初始化几何类型的空列的合适值是多少
What is the suitable value to initialize an empty column of type geometry
我想为几何列设置一个默认值,表示它为空或 empty.for 例如,字符串最初初始化为空或“”以表示为 void/empty。几何的 null/empty 等价于什么。
几何列的值是多少表示它是空的。我尝试了 0
和 ""
但不允许将它们插入到类型为 geometry
的列中
将 DEFAULT
添加到具有空几何的几何列,例如POINT
:
CREATE TABLE t (
id int,
geom geometry(point,4326) NOT NULL DEFAULT 'POINT EMPTY'
);
它也适用于其他几何类型(以及它们的 Z
和 M
扩展),例如:
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
演示:db<>fiddle
我想为几何列设置一个默认值,表示它为空或 empty.for 例如,字符串最初初始化为空或“”以表示为 void/empty。几何的 null/empty 等价于什么。
几何列的值是多少表示它是空的。我尝试了 0
和 ""
但不允许将它们插入到类型为 geometry
将 DEFAULT
添加到具有空几何的几何列,例如POINT
:
CREATE TABLE t (
id int,
geom geometry(point,4326) NOT NULL DEFAULT 'POINT EMPTY'
);
它也适用于其他几何类型(以及它们的 Z
和 M
扩展),例如:
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
演示:db<>fiddle