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
Asked
Active
Viewed 933 times
1
-
3That's what `null` is for – Nov 12 '21 at 09:17
-
@a_horse_with_no_name i am using python , and none is eqivalent to null, however, it is not allowed – Amrmsmb Nov 12 '21 at 09:19
-
See this https://stackoverflow.com/questions/4231491/how-to-insert-null-values-into-postgresql-database-using-python – yoonghm Nov 12 '21 at 09:25
-
2If `null`/`None` is not allowed then probably your column is defined as `NOT NULL`. – Tupteq Nov 12 '21 at 09:29
1 Answers
4
Add a DEFAULT
to 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 (and their Z
and M
extensions as well), e.g.:
SELECT
'POINT EMPTY'::geometry,
'POLYGON EMPTY'::geometry,
'LINESTRING EMPTY'::geometry,
'MULTILINESTRING EMPTY'::geometry,
'MULTIPOLYGON EMPTY'::geometry,
'MULTIPOINT EMPTY'::geometry,
'POLYHEDRALSURFACE EMPTY'::geometry,
'TRIANGLE EMPTY'::geometry,
'TIN EMPTY'::geometry,
'GEOMETRYCOLLECTION EMPTY'::geometry;
-[ RECORD 1 ]----------------------------------------
geometry | 0101000000000000000000F87F000000000000F87F
geometry | 010300000000000000
geometry | 010200000000000000
geometry | 010500000000000000
geometry | 010600000000000000
geometry | 010400000000000000
geometry | 010F00000000000000
geometry | 011100000000000000
geometry | 011000000000000000
geometry | 010700000000000000
Demo: db<>fiddle

Jim Jones
- 18,404
- 3
- 35
- 44
-
you mean that, for polygon, 010300000000000000 is the equivalent to null or empty? – Amrmsmb Nov 12 '21 at 09:36