Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A8648632B76 for ; Sun, 13 Sep 2009 15:38:13 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 19558-09 for ; Sun, 13 Sep 2009 18:38:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA04.emeryville.ca.mail.comcast.net (qmta04.emeryville.ca.mail.comcast.net [76.96.30.40]) by mail.postgresql.org (Postfix) with ESMTP id 5683663315A for ; Sun, 13 Sep 2009 15:38:02 -0300 (ADT) Received: from OMTA18.emeryville.ca.mail.comcast.net ([76.96.30.74]) by QMTA04.emeryville.ca.mail.comcast.net with comcast id gJcP1c0051bwxycA4Je19k; Sun, 13 Sep 2009 18:38:01 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA18.emeryville.ca.mail.comcast.net with comcast id gJim1c0051Ak4z48eJimFX; Sun, 13 Sep 2009 18:42:46 +0000 From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: Serious problems with non-primary foreign keys Date: Sun, 13 Sep 2009 11:37:59 -0700 User-Agent: KMail/1.9.10 Cc: Janne References: <793249.77906.qm@web39808.mail.mud.yahoo.com> In-Reply-To: <793249.77906.qm@web39808.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200909131137.59745.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.475 tagged_above=-10 required=5 tests=AWL=0.124, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/55 X-Sequence-Number: 33120 On Friday 11 September 2009 6:26:13 am Janne wrote: > I'm having some serious problems using PostgreSQL with symfony and > Doctrine. Here is the error that I've been fighting with for the last > couple of days: SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: > current transaction is aborted, commands ignored until end of transaction > block. Failing Query: CREATE INDEX company_id ON sf_guard_user_profile > (company_id) It seems to affect every single non-primary foreign key. > Turning the key to primary foreign fixes the problem but I don't want it to > be primary. I can't think of any logical reason why this error would > happen. Generally there's nothing wrong with using a non-primary (not null) > foreign key. But Postgre seems to think there is. I know PostgreSQL creates > an index for every primary key. Since turning the key also into primary > seems to fix it, should I just define an index for it? I've tried it but > nothing changes. Here's the relevant SQL: CREATE TABLE > sf_guard_user_profile (id BIGINT, company_id BIGINT NOT NULL, PRIMARY > KEY(id)); CREATE TABLE company (company_id INT, PRIMARY KEY(company_id)); > Any ideas on how to fix this? Thank you, > janneaa I think more information is required. First the complete transaction. Second the complete error message, especially the part that explains what is causing the CREATE INDEX command to fail. Third I do not see a FOREIGN KEY reference in the SQL you posted. -- Adrian Klaver aklaver@comcast.net