2

I've set the SRID 4326 for a table having geometry column, but when i insert a geometry without SRID, i get an error because no SRID specified is interpreted as -1 or 0, so how i can set a default SRID to insert geometries without specifying SRID each time.

  • I don't think you can directly, as it is possible, but not advisable to mix geometries with different SRIDs in same column. You could possibly do it via a trigger, though personally I have never found wrapping geometries in ST_SETSRID to be very arduous. – John Powell Apr 26 '15 at 18:54
  • i'm not looking to mix geometries with different SRID, in my case i'm using hibernate spatial, i find it little bad to set SRID for each geometry creation. – geogeek Apr 26 '15 at 18:59
  • 1
    That is fair enough, I know you hibernate guys are purists :D. I have used GeoDjango a bit, and it seems to be quite normal there to have to explicitly set the SRID in your models. A before insert trigger is what you are looking for, I think. – John Powell Apr 26 '15 at 20:12
  • anybody know an answer for this? I've got the same case - I don't want to mix SRIDs, but some software tries to insert geometries that don't specify an SRID. I want those inserts to succeed (in other words it is safe to assume the geometries are in the SRID of the table) – MC5 Apr 20 '16 at 22:00
  • i think a insert trigger would do the task – geogeek Apr 21 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.