pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedconstraints for ensuring relationships
2+ messages / 2 participants
[nested] [flat]
* constraints for ensuring relationships
@ 2002-05-21 10:08 Markus Wagner <wagner@imsd.uni-mainz.de>
2002-05-21 14:43 ` Re: constraints for ensuring relationships Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 1 reply; 2+ messages in thread
From: Markus Wagner @ 2002-05-21 10:08 UTC (permalink / raw)
To: pgsql-sql
Hi,
I wonder if I can use constraints to ensure some special integrity.
Suppose there is a table "Type" of item types:
CREATE TABLE "Type"
(
"index" SERIAL PRIMARY KEY,
"name" TEXT,
"multiple" BOOL
);
Suppose there is a table "Item" like this:
CREATE TABLE "Item"
(
"index" SERIAL PRIMARY KEY,
"type" INT REFERENCES "Type",
"data" TEXT
);
Supose there is a table "SubItem" that contains special details about our
items:
CREATE TABLE "SubItem"
(
"index" SERIAL PRIMARY KEY,
"Item" INT REFERENCES "Item",
"Data" TEXT
);
And now the constraint:
Each Item should be allowed to have more than one subitem, if and only if its
type allows for multiple instances, i. e. the type the item is linked to must
have 't' in its field 'multiple'.
Can I attach constraints to some of the tables (e. g. "SubItem") that ensure
this?
Thanks a lot!
Markus
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: constraints for ensuring relationships
2002-05-21 10:08 constraints for ensuring relationships Markus Wagner <wagner@imsd.uni-mainz.de>
@ 2002-05-21 14:43 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2002-05-21 14:43 UTC (permalink / raw)
To: Markus Wagner <wagner@imsd.uni-mainz.de>; +Cc: pgsql-sql
On Tue, 21 May 2002, Markus Wagner wrote:
> I wonder if I can use constraints to ensure some special integrity.
>
> Suppose there is a table "Type" of item types:
>
> CREATE TABLE "Type"
> (
> "index" SERIAL PRIMARY KEY,
> "name" TEXT,
> "multiple" BOOL
> );
>
> Suppose there is a table "Item" like this:
>
> CREATE TABLE "Item"
> (
> "index" SERIAL PRIMARY KEY,
> "type" INT REFERENCES "Type",
> "data" TEXT
> );
>
> Supose there is a table "SubItem" that contains special details about our
> items:
>
> CREATE TABLE "SubItem"
> (
> "index" SERIAL PRIMARY KEY,
> "Item" INT REFERENCES "Item",
> "Data" TEXT
> );
>
> And now the constraint:
>
> Each Item should be allowed to have more than one subitem, if and only if its
> type allows for multiple instances, i. e. the type the item is linked to must
> have 't' in its field 'multiple'.
>
> Can I attach constraints to some of the tables (e. g. "SubItem") that ensure
> this?
Given your schema, you might be able to get away with triggers that do the
check or a bunch of check constraints that call a function that does the
check. You need to worry about updates on Type and Item and inserts and
updates on SubItem I think.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-05-21 14:43 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-21 10:08 constraints for ensuring relationships Markus Wagner <wagner@imsd.uni-mainz.de>
2002-05-21 14:43 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
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