Skip to content

Instantly share code, notes, and snippets.

@tuesd4y
Last active March 11, 2019 10:04
Show Gist options
  • Save tuesd4y/21afb418405d31bb0dc2f1800806e932 to your computer and use it in GitHub Desktop.
Save tuesd4y/21afb418405d31bb0dc2f1800806e932 to your computer and use it in GitHub Desktop.
export distance summaries with points from postgres (+postgis) db to csv file. Includes coordinates of customers and stops, as well as spherical distance
\copy (select cd.name, pv.id as variation_id,
st_distance_sphere(cd.location, pv.location) as distance,
cd.city,
cd.address,
li.name as product,
pv.stop as bus_stop,
ST_X(pv.location) as stopX,
ST_Y(pv.location) as stopY,
ST_X(cd.location) as customerX,
ST_Y(cd.location) as customerY
from triply_order o, triply_order_line_items oli, simple_line_item li, product_variant pv, customer_details cd
where oli.line_items_id = li.id
and li.variation_id = pv.id
and oli.triply_order_id = o.id
and o.customer_details_id = cd.id
and cd.location is not null) to '/Users/dev/Documents/file.csv' with csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment