0

我正在研究地理处理软件中的数据库并遇到了一些问题。有必要在这个数据库中创建一个额外的层,我也决定尝试创建它。

使用 pgAdmin 4 软件、PostgreSQL 10.1 和 postgis 10。我在我为在数据库中创建这一层而编写的行下方提交。

我设法创建了图层,一切正常,出现字段,出现每列的选项,但问题是:我需要administracaoandclasseativecon列接受多个元素,而不仅仅是一个。例如,在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);
4

1 回答 1

0

数组而不是标量类型将是一个简单而肮脏的解决方案。但是由于您有 FK 约束,所以这不是一个选择。

如果您总是需要两个administracao,只需添加两列administracao1administracao2. 对于不同的数字,创建 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[]))
);

允许任意数量的元素。但是,很难强制执行至少一个值。您还不清楚确切的要求。

旁白:

于 2018-01-10T01:42:35.750 回答