Skip to content

Insert into table with postgis geometry type #395

Answered by houten11
Napam asked this question in Q&A
Discussion options

You must be logged in to vote

You are trying to send part of the sql query as an argument, which is not possible without some form of eval function.

Jet way would be to define two missing functions first:

func ST_MakePoint(lon, lat float64) Expression {
	return Func("ST_MakePoint", Float(lon), Float(lat))
}

func ST_SetSRID(point Expression, srid int64) Expression {
	return Func("ST_SetSRID", point, Int(srid))
}

Which then can be used like any query expression:

ST_SetSRID(ST_MakePoint(11.22, 33.44), 4326).EQ(Table.Point)

Also, note that now you'll have to use VALUES instead MODEL method for insert:

insertStatement := Listings.INSERT(
    Listings.AllColumns,
).VALUES(
    ...,
    ST_SetSRID(ST_MakePoint(1.2345, 6.7890)…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Napam
Comment options

Answer selected by Napam
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