pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@kick.com>
To: Niall Smart <niall.smart@ebeon.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with subquery in CHECK constraint.
Date: Thu, 8 Jun 2000 11:15:08 -0700
Message-ID: <004d01bfd175$7d9af7b0$0c64010a@kick.com> (raw)
References: <000901bfd0df$f57c1f20$2801007e@tpf.co.jp>
	<393F8A00.1D2D4AB5@ebeon.com>

> CONSTRAINT TYPE_CD_OK CHECK (
> EXISTS (SELECT 1 FROM XREF WHERE
> XREF_GROUP = 'CUST_TYPE' AND
> XREF_CD = TYPE_CD)
> )
>
>
> > There seems to be more serious problems.
> > 1) The constraint is not only for the defined table but also for
referenced
> >     tables in the subquery.
>
> I don't understand what you mean -- the constraint only
> constrains 1 column in one table...

Think of this sequence:

insert into xref (xref_group, xref_cd) values ('CUST_TYPE', '1');
insert into xref (xref_group, xref_cd) values ('CUST_TYPE', '2');
insert into xref (xref_group, xref_cd) values ('CUST_TYPE', '3');
insert into cust (cust_id, name, type_cd) values (1, 'a', '1');
insert into cust (cust_id, name, type_cd) values (2, 'b', '2');
delete from xref where xref_cd='1';

I believe that technically the delete should fail because it breaks the
type_cd_ok constraint, but right now, we wouldn't be even checking
that constraint to notice that we're breaking it.






view thread (7+ messages)  latest in thread

Message-ID: <004d01bfd175$7d9af7b0$0c64010a@kick.com>
Permalink:  ../004d01bfd175$7d9af7b0$0c64010a@kick.com/
Also on:    postgresql.org/message-id/004d01bfd175$7d9af7b0$0c64010a@kick.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 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-sql@postgresql.org
  Cc: sszabo@kick.com, niall.smart@ebeon.com
  Subject: Re: Problem with subquery in CHECK constraint.
  In-Reply-To: <004d01bfd175$7d9af7b0$0c64010a@kick.com>
  References: <000901bfd0df$f57c1f20$2801007e@tpf.co.jp> <393F8A00.1D2D4AB5@ebeon.com> <004d01bfd175$7d9af7b0$0c64010a@kick.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