pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Katona Gabor <katonag@dragon.klte.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to union tables and have a field with UNIQUE constraint?
Date: Thu, 3 Jan 2002 10:02:07 -0800 (PST)
Message-ID: <20020103095733.C12608-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <Pine.GSO.4.10.10112281351460.8286-100000@dragon>

On Fri, 28 Dec 2001, Katona Gabor wrote:

>
>   I have the followinig SQL code (of course the tables contain more useful
> data). When I load it into PostgreSQL via \i foo.txt it produces the
> folloving error massage:
> UNIQUE constraint matching given keys for referenced table "t" not found
>   The task I want to do with this code: Making a table t from t1 and t2 using
> the id and the foo column. Table t shoud have one id and one foo column,
> holding all the rows from t1 and t2, this is why I use UNION. As you can see,
> the id column of t1 and t2 is PRIMARY KEY, therefore UNIQUE and the prepared
> sequences provide that no rows can share the same id even after UNION.
>
>   How can I correct the code to work? Is there any working way of doing such
> things?

I assume you want to reference id, so you'd need to do something like:

CREATE UNIQUE INDEX t_id_key ON t(id);
and in the uniont definition, something like:
tid INTEGER REFERENCES t(id),

This is a hacky sort of way to do it (we allow you to make the internal
form that a unique constraint has via create index even on views which
I don't believe would ever be used :( ) and may not continue working
forever.





view thread (7+ messages)  latest in thread

Message-ID: <20020103095733.C12608-100000@megazone23.bigpanda.com>
Permalink:  ../20020103095733.C12608-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020103095733.C12608-100000@megazone23.bigpanda.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, katonag@dragon.klte.hu
  Subject: Re: How to union tables and have a field with UNIQUE constraint?
  In-Reply-To: <20020103095733.C12608-100000@megazone23.bigpanda.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