Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the suitable value to initialize an empty column of type geometry

i want to set a default value to a geometry column indicates that it is null or empty.for example, a string initially is initialized to null or "" to indicate being void/empty. what is the equivalent to null/empty for geometries.
what is the value to be set to a geometry column inidicates that it is empty. i tried 0 and ""
but they are not allowed to be inserted in a column of type geometry

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could add a DEFAULT in the geometry column with an empty geometry, e.g. for POINT:

CREATE TABLE t (
  id int,
  geom geometry(point,4326) NOT NULL DEFAULT 'POINT EMPTY'
);

It applies also to other geometry types, e.g.:

SELECT 
  'POINT EMPTY'::geometry,
  'POLYGON EMPTY'::geometry,
  'LINESTRING EMPTY'::geometry,
  'MULTILINESTRING EMPTY'::geometry,
  'MULTIPOLYGON EMPTY'::geometry,
  'MULTIPOINT EMPTY'::geometry;

-[ RECORD 1 ]----------------------------------------
geometry | 0101000000000000000000F87F000000000000F87F
geometry | 010300000000000000
geometry | 010200000000000000
geometry | 010500000000000000
geometry | 010600000000000000
geometry | 010400000000000000

Demo: db<>fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading