ERROR: column specified more than once in Postgres

ERROR: column specified more than once in Postgres

我是 Postgres 新手,我有以下 table 可以通过 c# 代码创建:

string create = "CREATE TABLE " + articles
                    + "("
                       + " SEQU_NK SERIAL PRIMARY KEY,"
                       + " ARTICLE_NK bigint   NOT NULL,"
                       + " DEPOT_NK  bigint  NOT NULL  ,"
                       + " EXPED_NK  bigint NOT NULL,"
                       + " CLIENT_NK  bigint  NOT NULL,"
                       + " SIGNE_TRANSP character varying(2) NOT NULL,"
                       + " NB_PLIS_TOTAL bigint DEFAULT 0  ,"
                       + " DH_PREM_ETIQUETTE timestamp  DEFAULT '0001-01-01 00:00:00',"
                       + " DATE_DEPOT_ARTICLE character varying(10) DEFAULT NULL,"                    
                       + " ARTICLE_NK character varying(10)  references articles(ARTICLE_NK),"
                       + " DEPOT_NK character varying(10)  references depots(DEPOT_NK),"
                       + " EXPED_NK character varying(10)  references expeds(EXPED_NK),"
                       + " CLIENT_NK character varying(10)  references clients(CLIENT_NK),"
                    + ") ";

也尝试在 PGAdmin3 上编写查询:

CREATE TABLE articles( SEQU_NK SERIAL PRIMARY KEY,
                       ARTICLE_NK bigint   NOT NULL,
                        DEPOT_NK  bigint  NOT NULL  ,
                        EXPED_NK  bigint NOT NULL,
                       CLIENT_NK  bigint  NOT NULL,
                        SIGNE_TRANSP character varying(2) NOT NULL,
                        NB_PLIS_TOTAL bigint DEFAULT 0  , 
                        DH_PREM_ETIQUETTE timestamp  DEFAULT '0001-01-01 00:00:00',                      
                        ARTICLE_NK character varying(10)  references articles(ARTICLE_NK),
                        DEPOT_NK character varying(10)  references depots(DEPOT_NK),
                        EXPED_NK character varying(10)  references expeds(EXPED_NK),
                       CLIENT_NK character varying(10)  references clients(CLIENT_NK)) ;

得到的错误是:

ERROR:  column "article_nk" specified more than once
********** Error **********

ERROR: column "article_nk" specified more than once
SQL state: 42701

如何解决这个错误,因为它是一个外键?当我将查询从 Mysql 更改为 Postgres 时?

等价的 Mysql 查询是(我正在翻译成 Postgres 的是):

CREATE TABLE IF NOT EXISTS `articles` (
  `SEQU_NK` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Auto: Numero sequence',
  `ARTICLE_NK` int(11) NOT NULL,
  `DEPOT_NK` int(11) NOT NULL DEFAULT '0',
  `EXPED_NK` int(11) NOT NULL,
  `CLIENT_NK` int(11) NOT NULL,
  `SIGNE_TRANSP` varchar(2) NOT NULL DEFAULT '',
  `NB_PLIS_TOTAL` int(11) DEFAULT '0',
  `DH_PREM_ETIQUETTE` datetime DEFAULT '0001-01-01 00:00:00',
  PRIMARY KEY (`SEQU_NK`),
  KEY `ARTICLE_NK` (`ARTICLE_NK`),
  KEY `DEPOT_NK` (`DEPOT_NK`),
  KEY `EXPED_NK` (`EXPED_NK`),
  KEY `CLIENT_NK` (`CLIENT_NK`),

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;

您有列:

ARTICLE_NK bigint NOT NULL,

ARTICLE_NK character varying(10) references articles(ARTICLE_NK)

postgres 将秒解释为一列。不是钥匙...

您应该改用此语法:

CONSTRAINT ARTICLE_NK_FK FOREIGN KEY (ARTICLE_NK) REFERENCES articles (ARTICLE_NK)

CREATE TABLE manual with some examples