I am trying to create this SQL statement with Anorm in Scala. I am using a Postgres DB.
insert into my_table (coords) values (ST_GeomFromText('POINT(26.9484 24.03937)',4326)
I have tried this code:
val lat = 26.9484
val long = 24.03937
val coords = s"ST_GeomFromText('POINT($lat $long)',4326)"
SQL"insert into my_table (coords) values (${coords})".executeInsert()
But I get this error:
[PSQLException: ERROR: subfield "coords" is of type geometry but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Here was my solution:
Nice benefit is that if lat or long are None (null) then the coords field is set to NULL in the table.