ST_SetSRID
What is ST_SetSRID?
ST_SetSRID assigns an SRID to a geometry's metadata. It does not reproject coordinates — callers must be certain the coordinates already correspond to the target CRS.
ST_SetSRID(geometry geom, integer srid) → geometryThis is the opposite of ST_Transform, which changes coordinate values. Use ST_SetSRID to tag untagged geometry or correct mislabelled SRIDs.
When would you use ST_SetSRID?
Use ST_SetSRID after constructing geometry from raw WKT that lacks an SRID (e.g. ST_GeomFromText('POINT(-73 40)')), to tag the result as EPSG:4326. It is also the fix for data imported via shapefile or CSV loaders that defaulted the SRID to 0.
In migrations between PostGIS versions or systems, ST_SetSRID is used to re-tag data after column type changes or after restoring from dumps that lost the SRID metadata.
FAQs
Does ST_SetSRID reproject coordinates?
No. Only the SRID tag changes. Use ST_Transform to actually convert coordinates to a different CRS.
What SRID is assigned to geometry constructed by ST_GeomFromText without an SRID?
Zero (0), meaning "undefined". Geometries with SRID 0 cannot participate in indexed spatial queries that require matching SRIDs. Tag them with ST_SetSRID.
Can I use any integer as an SRID?
Technically yes, but stick to values defined in the spatial_ref_sys table to ensure ST_Transform works. Common values: 4326 (WGS84), 3857 (Web Mercator), 4269 (NAD83).
What if the coordinates are actually in a different CRS than I'm tagging?
You'll get incorrect spatial results — ST_Distance, ST_Transform, and every measurement will be wrong. Always confirm the CRS of incoming data before tagging.