From: Shatamjeev Dewan <sdewan@nbsps.com>
To: Michael Lewis <mlewis@entrata.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: RE: ERROR: there is no unique constraint matching given keys for referenced table "audit_p"
Date: Mon, 18 Nov 2019 18:58:24 +0000
Message-ID: <F2F23E564EB92A4C80228EB86713BA130BF9B0@TO1RODC.nbspaymentsolutions.com> (raw)
In-Reply-To: <CAHOFxGrK-TgSF8u=TuDu8ntJOEZDFx01iu92WKtMAC7Ji=1GZw@mail.gmail.com>
References: <F2F23E564EB92A4C80228EB86713BA130BF984@TO1RODC.nbspaymentsolutions.com>
<CAHOFxGrK-TgSF8u=TuDu8ntJOEZDFx01iu92WKtMAC7Ji=1GZw@mail.gmail.com>
Thanks a lot Michael. Get well soon.
From: Michael Lewis <mlewis@entrata.com>
Sent: November-18-19 12:57 PM
To: Shatamjeev Dewan <sdewan@nbsps.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: ERROR: there is no unique constraint matching given keys for referenced table "audit_p"
On Mon, Nov 18, 2019 at 10:10 AM Shatamjeev Dewan <sdewan@nbsps.com<mailto:sdewan@nbsps.com>> wrote:
I am trying to create a foreign key constraint on a table : audit_param in postgres 12 which references partitioned table audit_p. is there anyway to get rid of this error.
ERROR: there is no unique constraint matching given keys for referenced table "audit_p"
As far as I understand, what you want is not possible. You cannot partition on a timestamp and then foreign key to an object_id natively. You can get around this with triggers- https://www.depesz.com/2018/10/31/foreign-key-to-partitioned-table-part-2/ - but that would not be recommended.
Admittedly, I have a pretty nasty head cold so it may be that someone chimes in with much better insight on your design.
By the way, there are strong recommendations for using timestamp WITH TIMEZONE in nearly all cases. I just wanted to mention since timestamp without timezone is rarely the best choice.
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: sdewan@nbsps.com, mlewis@entrata.com
Subject: Re: ERROR: there is no unique constraint matching given keys for referenced table "audit_p"
In-Reply-To: <F2F23E564EB92A4C80228EB86713BA130BF9B0@TO1RODC.nbspaymentsolutions.com>
References: <F2F23E564EB92A4C80228EB86713BA130BF984@TO1RODC.nbspaymentsolutions.com> <CAHOFxGrK-TgSF8u=TuDu8ntJOEZDFx01iu92WKtMAC7Ji=1GZw@mail.gmail.com> <F2F23E564EB92A4C80228EB86713BA130BF9B0@TO1RODC.nbspaymentsolutions.com>
* 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