pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: ADD FOREIGN KEY fails, but the records exist
Date: Mon, 15 Feb 2021 11:37:21 -0500
Message-ID: <2254788.1613407041@sss.pgh.pa.us> (raw)
In-Reply-To: <e8a458ad-2f92-6f8d-c485-8f72e3d4f72a@gmail.com>
References: <e8a458ad-2f92-6f8d-c485-8f72e3d4f72a@gmail.com>

Ron <ronljohnsonjr@gmail.com> writes:
> Postgresql 12.5
> It's a self-referential FK on a single (but partitioned) table.  The ALTER 
> TABLE command fails, but I queried it, and the record that it fails on 
> exists.  I modified the original INITIALLY IMMEDIATE clause to INITIALLY 
> DEFERRED but that did not help.

> What am I doing wrong?

As Adrian noted, the queries you showed don't actually prove that the
required employer_response_id exists in the table.  However, if the
identical data worked in Oracle then it should work in PG too, so for
the moment I'll assume that that was a thinko and the FK should be
valid.  In that case I'd go looking for "invisible" reasons for the
keys not to match.  You did not show the column data types, but if the
response ids are strings not numbers then I'd be wondering about extra
spaces and such.  Perhaps Oracle is more forgiving of such things than
PG is.

			regards, tom lane





view thread (10+ messages)  latest in thread

Message-ID: <2254788.1613407041@sss.pgh.pa.us>
Permalink:  ../2254788.1613407041@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2254788.1613407041@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ronljohnsonjr@gmail.com
  Subject: Re: ADD FOREIGN KEY fails, but the records exist
  In-Reply-To: <2254788.1613407041@sss.pgh.pa.us>
  References: <e8a458ad-2f92-6f8d-c485-8f72e3d4f72a@gmail.com> <2254788.1613407041@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox