X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 778E75293E for ; Sun, 26 Jun 2005 11:59:11 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69070-02 for ; Sun, 26 Jun 2005 14:58:55 +0000 (GMT) Received: from mailout02.albacom.net (mailout02.albacom.net [217.220.34.14]) by svr1.postgresql.org (Postfix) with SMTP id C45085295C for ; Sun, 26 Jun 2005 11:58:53 -0300 (ADT) Received: (qmail 28641 invoked by uid 507); 26 Jun 2005 14:58:51 -0000 Received: from site.webmaster@email.it by mailout02.albacom.net with qmail-scanner (rbl: ???. spamassassin: ???. Clear:RC:1(217.221.167.198):RBL:0:SA:0(0.0/1000.0):. Processed in 0.40928 secs); 26 Jun 2005 14:58:51 -0000 Received: from unknown (HELO ?127.0.0.1?) (davide@attutta.albaweb.it@217.221.167.198) by mailout02.albacom.net with SMTP; 26 Jun 2005 14:58:50 -0000 Message-ID: <42BEC2AA.9030404@email.it> Date: Sun, 26 Jun 2005 16:58:50 +0200 From: davide User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: multiple PK with a non UNIQUE field Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.376 tagged_above=0 required=5 tests=DNS_FROM_RFC_POST X-Spam-Level: * X-Archive-Number: 200506/303 X-Sequence-Number: 21904 Sorry, I 'm a beginner of postgres and I found a problem when I was passed from MySQL: I have to create a referential constraint table APPALTO from a table OPERE that as a composed PK(cod_op,cod_com) where cod_op ISN'T unique. in MySQL: CREATE TABLE opere ( cod_op int NOT NULL , cod_com int NOT NULL , costo int , data_inizio date , data_fine date , tipo char(6) NOT NULL , PRIMARY KEY (cod_op,cod_com) ) ; CREATE TABLE committenti ( cod_com int NOT NULL , nome char(30) NOT NULL, indirizzo char(60) NOT NULL, CF char(16) unique, P_IVA char(11) unique, tipo char(8) NOT NULL , PRIMARY KEY (cod_com) ); CREATE TABLE appalto ( cod_op int not null references Opere, cod_com int not null references Opere, scadenza date not null, importo int not null, PRIMARY KEY (cod_op,cod_com) ); But when I try to insert it: ERROR: number of referencing and referenced columns for foreign key disagree another table connected at OPERE give instead another error: CREATE TABLE direzione ( CF char(16) not null references Salariati(CF), cod_op int not null references Opere (cod_op), cod_com int not null references Opere (cod_com), -- opere_pkey int references Opere, -- PRIMARY KEY (opere_pkey) PRIMARY KEY (CF,cod_op,cod_com) ) ; ERROR: there is no unique constraint matching given keys for referenced table "opere" If I try to use the index "opere_pkey" (automatic created) NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "opere_pkey" for table "opere" Why MySQL let me do these and PostgreSQL no? There's another way?