我正在使用地理处理软件中的数据库并遇到了一些问题。有必要在这个数据库中创建一个额外的层,我也决定尝试创建它。
使用pgAdmin 4软件,PostgreSQL 10.1和postgis 10.我在下面提交了我在数据库中创建此图层的行。
我设法创建了图层,一切正常,字段显示,每列的选项都出现了,但问题是:我需要administracao
和classeativecon
列来接受多个元素,而不仅仅是一个。例如,在admin层中,我想放置代码2和3,但只接受一个。
我认为这很简单,但由于我的知识几乎为零,我无法做到。我希望你能帮助我。
CREATE TABLE ge.edf_edificacao_pavimento_a (
id integer NOT NULL DEFAULT nextval('ge.edf_edificacao_pavimento_a_id_seq'::regclass),
geometriaaproximada smallint NOT NULL DEFAULT 0,
nome smallint NOT NULL,
numero smallint NOT NULL,
bloco smallint NOT NULL,
operacional smallint NOT NULL,
situacaofisica smallint NOT NULL DEFAULT 95,
matconstr smallint NOT NULL,
numeropavimentos smallint NOT NULL,
alturaaproximada smallint NOT NULL,
turistica smallint NOT NULL,
cultura smallint NOT NULL,
administracao smallint NOT NULL,
classeativecon smallint NOT NULL,
divisaoativecon smallint NOT NULL,
grupoativecon smallint NOT NULL,
proprioadm smallint NOT NULL,
numerosequencial smallint NOT NULL,
numerometrico smallint NOT NULL,
cep smallint NOT NULL,
pais smallint NOT NULL,
unidadefederacao smallint NOT NULL,
municipio smallint NOT NULL,
bairro smallint NOT NULL,
logradoura smallint NOT NULL,
id_assentamento_precario smallint NOT NULL,
id_complexo_habitacional smallint NOT NULL,
geom geometry(MultiPolygon,31984) NOT NULL,
CONSTRAINT edf_edificacao_pavimento_a_pk PRIMARY KEY (id)
WITH (FILLFACTOR=10),
CONSTRAINT edf_edificacao_pavimento_a_turistica_fk FOREIGN KEY (turistica)
REFERENCES dominios.booleano_estendido (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_situacaofisica_fk FOREIGN KEY (situacaofisica)
REFERENCES dominios.situacao_fisica (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_proprioadm_fk FOREIGN KEY (proprioadm)
REFERENCES dominios.booleano (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_operacional_fk FOREIGN KEY (operacional)
REFERENCES dominios.booleano_estendido (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_matconstr_fk FOREIGN KEY (matconstr)
REFERENCES dominios.mat_constr (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_grupoativecon_fk FOREIGN KEY (grupoativecon)
REFERENCES dominios.grupo_ativ_econ (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_geometriaaproximada_fk FOREIGN KEY (geometriaaproximada)
REFERENCES dominios.booleano (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_divisaoativecon_fk FOREIGN KEY (divisaoativecon)
REFERENCES dominios.divisao_ativ_econ (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_cultura_fk FOREIGN KEY (cultura)
REFERENCES dominios.booleano_estendido (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_classeativecon_fk FOREIGN KEY (classeativecon)
REFERENCES dominios.classe_ativ_econ (code) MATCH FULL,
CONSTRAINT edf_edificacao_pavimento_a_administracao_fk FOREIGN KEY (administracao)
REFERENCES dominios.administracao (code) MATCH FULL,
CONSTRAINT edf_edificacao_a_administracao_check CHECK (administracao = ANY (ARRAY[(2)::smallint, (3)::smallint, (4)::smallint, (5)::smallint, (6)::smallint, (95)::smallint, (97)::smallint])),
CONSTRAINT edf_edificacao_a_classeativecon_check CHECK (classeativecon = ANY (ARRAY[(10)::smallint, (11)::smallint, (12)::smallint, (13)::smallint, (14)::smallint, (15)::smallint, (16)::smallint, (17)::smallint, (18)::smallint, (19)::smallint, (2)::smallint, (20)::smallint, (21)::smallint, (22)::smallint, (23)::smallint, (24)::smallint, (25)::smallint, (26)::smallint, (27)::smallint, (28)::smallint, (29)::smallint, (3)::smallint, (30)::smallint, (31)::smallint, (32)::smallint, (33)::smallint, (34)::smallint, (35)::smallint, (36)::smallint, (4)::smallint, (5)::smallint, (6)::smallint, (7)::smallint, (8)::smallint, (9)::smallint, (95)::smallint, (98)::smallint, (99)::smallint])),
CONSTRAINT edf_edificacao_a_cultura_check CHECK (cultura = ANY (ARRAY[(0)::smallint, (1)::smallint, (95)::smallint])),
CONSTRAINT edf_edificacao_a_divisaoativecon_check CHECK (divisaoativecon = ANY (ARRAY[(1)::smallint, (10)::smallint, (11)::smallint, (13)::smallint, (14)::smallint, (15)::smallint, (16)::smallint, (17)::smallint, (18)::smallint, (19)::smallint, (2)::smallint, (20)::smallint, (21)::smallint, (22)::smallint, (23)::smallint, (24)::smallint, (25)::smallint, (27)::smallint, (28)::smallint, (29)::smallint, (30)::smallint, (31)::smallint, (32)::smallint, (33)::smallint, (34)::smallint, (35)::smallint, (36)::smallint, (37)::smallint, (45)::smallint, (5)::smallint, (50)::smallint, (51)::smallint, (52)::smallint, (55)::smallint, (74)::smallint, (92)::smallint, (95)::smallint, (99)::smallint])),
CONSTRAINT edf_edificacao_a_geometriaaproximada_check CHECK (geometriaaproximada = ANY (ARRAY[(0)::smallint, (1)::smallint])),
CONSTRAINT edf_edificacao_a_grupoativecon_check CHECK (grupoativecon = ANY (ARRAY[(15)::smallint, (16)::smallint, (19)::smallint, (20)::smallint, (23)::smallint, (30)::smallint, (31)::smallint, (32)::smallint, (6)::smallint, (8)::smallint, (95)::smallint, (98)::smallint, (99)::smallint])),
CONSTRAINT edf_edificacao_a_matconstr_check CHECK (matconstr = ANY (ARRAY[(1)::smallint, (2)::smallint, (3)::smallint, (5)::smallint, (8)::smallint, (95)::smallint, (97)::smallint, (99)::smallint])),
CONSTRAINT edf_edificacao_a_operacional_check CHECK (operacional = ANY (ARRAY[(0)::smallint, (1)::smallint, (95)::smallint])),
CONSTRAINT edf_edificacao_a_proprioadm_check CHECK (proprioadm = ANY (ARRAY[(0)::smallint, (1)::smallint])),
CONSTRAINT edf_edificacao_a_situacaofisica_check CHECK (situacaofisica = ANY (ARRAY[(1)::smallint, (2)::smallint, (3)::smallint, (4)::smallint, (5)::smallint, (7)::smallint, (95)::smallint, (97)::smallint])),
CONSTRAINT edf_edificacao_a_turistica_check CHECK (turistica = ANY (ARRAY[(0)::smallint, (1)::smallint, (95)::smallint]))
);
CREATE INDEX edf_edificacao_pavimento_a_gist
ON ge.edf_edificacao_pavimento_a USING gist (geom);
答案 0 :(得分:0)
阵列而不是标量类型将是一个简单,肮脏的解决方案。但由于你有FK限制,这不是一个选择。
如果您始终要求完全两个值administracao
值,则只需添加两列administracao1
和administracao2
。对于不同的数量,创建1-n表。像:
CREATE TABLE ge.edf_edificacao_pavimento_administracao (
edf_id int NOT NULL REFERENCES ge.edf_edificacao_pavimento_a (id) ON UPDATE CASCADE ON DELETE CASCADE
, administracao smallint NOT NULL REFERENCES dominios.administracao (code)
, PRIMARY KEY (edf_id, administracao)
, CONSTRAINT edf_edificacao_a_administracao_check CHECK (administracao = ANY ('{2,3,4,5,6,95,97}'::int2[]))
);
允许任意数量的元素。但是,执行至少一个值更难。你还不清楚确切的要求。
旁白:
MATCH FULL
只是NOT NULL
列上单列FK的噪音