I have this parameterized query in an Npgsqlcommand:
UPDATE raw.geocoding
SET the_geom = ST_Transform(ST_GeomFromText('POINT(:longitude :latitude)', 4326),3081)
WHERE id=:id
:longutide and :latitude are double, and id is int.
The query that is actually run against the DB looks like this:
UPDATE raw.geocoding
SET the_geom = ST_Transform(ST_GeomFromText('POINT(((E'-96.6864379495382')::float8) ((E'32.792527154088')::float8))', 4326),3081)
WHERE id=((10793455)::int4)
Thanks to help from Erwin Brandstetter here, it’s apparent that the query needs to be simplified to work with PostGIS. He suggested this:
UPDATE raw.geocoding
SET the_geom = ST_Transform(ST_GeomFromText(
$$POINT(:longitude :latitude)$$::geometry, 4326), 3081)
WHERE id = :id
I guess I could create this with a dynamic query, where I manually update the query every time I run it, but is there a way to make this work with a Npgsql parameterized query?
I am not an expert with
npgsql, but I think your parameterized query could work like this:And
mygeomwould hold this string:.. pre-assembled from your other variables. Would result in a query like this:
Which should work.
If you have trouble assembling the string (like your comment demonstrates), there is a more elegant way. As per hint from @Paul on my previous answer – PostGIS provides a dedicated function for the purpose:
Details in the manual. With this, we finally arrive at:
Note the comma. Will it finally work now?
If not, just beat it with a sledgehammer. Grml.
It does – with
ST_SetSRID()now instead ofST_GeomFromText(). See comment.