I'm trying to use SELECT ST_GeomFromText() with a value catched from another query:

SELECT ST_GeomFromText(
  FROM table-name
  LIMIT 1)

The value that I'm trying to use is compatible with the SELECT ST_GeomFromText() and I'm using PostgreSQL/PostGIS.

Other solution that would help would be a INSERT INTO with SELECT ST_GeomFromText() as a value.

closed as off-topic by JGH, Mark Ireland, Andre Silva, LaughU, Erik Feb 11 at 8:19

  • This question does not appear to be about geographic information systems (GIS) within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.


Try this :

SELECT ST_GeomFromText(
           CAST(ST_GeomFromGeoJSON(t1."column-name") AS TEXT)
         ), 4326
FROM (SELECT "column-name"
      FROM table-name
      ORDER BY id DESC
      LIMIT 1) AS t1
  • Hi, i tried your suggestion and the following error happened: ERROR: function st_geomfromgeojson(json) does not exist LINE 3: ST_GeomFromGeoJSON(t1.geometria) ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 56 – lucazpinheiro Feb 8 at 15:48
  • In postgreSQL, what is the return type of the geometria field ? The entry data must be in text, json or jsonb type. – J. Monticolo Feb 8 at 16:04
  • I'm using a JSON {"type":"Polygon","coordinates":[[[-48.544464,-27.579818],[-48.548584,-27.60994],[-48.45005,-27.622717],[-48.439064,-27.584991],[-48.544464,-27.579818]]]} and when i tried to use this json direct with the SELECT ST_GeomFromText( ST_AsText( ST_GeomFromGeoJSON(function it worked perfectly. – lucazpinheiro Feb 8 at 16:16
  • I think it's working now, I've cast the JSON as TEXT. I've corrected my post. – J. Monticolo Feb 8 at 16:45
  • Same error: ERROR: function st_geomfromgeojson(json) does not exist LINE 3: CAST(ST_GeomFromGeoJSON(t1.geometria) AS TEXT) – lucazpinheiro Feb 8 at 16:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.