I have a table with "coordinate" column in it of data_type POINT (native postrgresql point). I want to convert it into Geometry(Point,4326)
I am using psycopg2 to connect to my database.
I ran this command:
cur.execute(f"ALTER TABLE {table} ALTER COLUMN {column} TYPE geometry(Point, 4326) USING ST_SetSRID(ST_MakePoint({column}[0],{column}[1]), 4326);")
But it gives this error:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request
and if I use
cur.execute(f"ALTER TABLE {table} ALTER COLUMN {column} TYPE geometry(Point, 4326) USING {column}::ST_SetSRID(ST_MakePoint({column}[0],{column}[1]), 4326);")
it says st_setsrid does not exist.
If I cannot solve this issue, is there any other way to convert dataType of column from native point to geometry(point,4326)?
select postgis_version();
.select ST_SetSRID(ST_MakePoint(1,2), 4326)
work? If is works then perhaps{column}[0],{column}[1]
are not of correct datatype for ST_MakePoint.CAST
toST_SetSRID
- you need to wrap the actualCAST
into those functions, i.e.USING ST_SetSRID(<column>::GEOMETRY(POINT), 4326)