From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Katona Gabor <katonag(at)dragon(dot)klte(dot)hu> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How to union tables and have a field with UNIQUE constraint? |
Date: | 2002-01-03 18:02:07 |
Message-ID: | 20020103095733.C12608-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-01-03 20:51:37 | Re: How to union tables and have a field with UNIQUE constraint? |
Previous Message | Bruce Momjian | 2002-01-03 17:06:09 | Re: Retrieving information from System Tables |