Skip to content

How to use Geography functions #1841

Answered by max-sixty
bkanuka asked this question in Q&A
Feb 14, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

For a one-off, it's easy to use an s-string for this:

from foo
select [my_lon, my_lat]  # assuming these columns exist
derive point = s"ST_GEOGPOINT({my_lon}, {my_lat})"

It's also possible to make a function (but at the moment it needs to be in every file, we don't have importing yet)

func geogpoint lon lat -> s"ST_GEOGPOINT({lon}, {lat})"

from foo
derive point = (geogpoint my_lon my_lat)

Both of these generate

SELECT
  my_lon,
  my_lat,
  ST_GEOGPOINT(my_lon, my_lat) AS point
FROM
  foo

For adding these to a standard library — very open to that, though maybe we want a separate namespace for them. Someone would have to think about which functions to add initially and how those would cor…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@bkanuka
Comment options

@max-sixty
Comment options

@bkanuka
Comment options

Answer selected by bkanuka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants