初始化类型为GEOMETRY的空列的合适值是多少

2022-04-09 00:00:00 python postgresql postgis sql

问题描述

我想将指示它为空或空的几何列设置为缺省值。例如,一个字符串最初被初始化为空或&q;以指示为空/空。几何图形的Null/Empty等效项是什么? 要为几何图形列设置的值是多少,表示该几何图形列为空。我尝试了0"" 但不允许将它们插入类型为GEOMETRY的列


解决方案

DEFAULT添加到几何图形为空的几何图形列,例如POINT

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

它也适用于其他几何类型(及其ZM扩展),例如:

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

相关文章