pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Is this a bug, or is it just me?
3+ messages / 3 participants
[nested] [flat]

* Is this a bug, or is it just me?
@ 2001-02-07 04:15 Josh Berkus <josh@agliodbs.com>
  2001-02-07 17:21 ` Re: Is this a bug, or is it just me? Stephan Szabo <sszabo@megazone23.bigpanda.com>
  2001-02-08 10:59 ` Re: Is this a bug, or is it just me? Jan Wieck <janwieck@Yahoo.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Josh Berkus @ 2001-02-07 04:15 UTC (permalink / raw)
  To: pgsql-sql

Tom et al.

Discovered this quirk in foriegn keys:

In the preliminary version of a database, I added foriegn
key constraints to a number of tables, linking them to a
column in a shared reference table (status.status) that was
only one-half of a composite primary key (and thus the
values were not unique).  When I tried to delete a row
containing a "2" in the status column from the status
relation, I received a Foreign Key violation error event
though there were other "2"'s in the table still present.

So ... is this a bug in forign key implementation, or just
my fault for keying off a non-unique value?

And, if the latter, is there a way I can construct a foreign
key constraint that keys onto a view or query?

Grazie!

-Josh Berkus


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Is this a bug, or is it just me?
  2001-02-07 04:15 Is this a bug, or is it just me? Josh Berkus <josh@agliodbs.com>
@ 2001-02-07 17:21 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2001-02-07 17:21 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-sql


Technically you are not allowed to make an FK to non-unique
values.  What you're closer to looking for is MATCH PARTIAL
which we don't support (because it's a real pain - although
with the new memory management stuff in 7.1 it may be less
of one - since the fundamental problem is storing values
from other iterations of the trigger for this last update/delete
for ref actions).

7.1 won't let you define such a constraint with the create 
table or alter table syntaxes (I guess theoretically it would
let you create constraint trigger and bring the broken 
constraint from an older version).  Right now we don't
support constraining views because we don't have a mechanism
in place to rewrite the constraint to actually work.

On Tue, 6 Feb 2001, Josh Berkus wrote:

> Tom et al.
> 
> Discovered this quirk in foriegn keys:
> 
> In the preliminary version of a database, I added foriegn
> key constraints to a number of tables, linking them to a
> column in a shared reference table (status.status) that was
> only one-half of a composite primary key (and thus the
> values were not unique).  When I tried to delete a row
> containing a "2" in the status column from the status
> relation, I received a Foreign Key violation error event
> though there were other "2"'s in the table still present.
> 
> So ... is this a bug in forign key implementation, or just
> my fault for keying off a non-unique value?
> 
> And, if the latter, is there a way I can construct a foreign
> key constraint that keys onto a view or query?




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Is this a bug, or is it just me?
  2001-02-07 04:15 Is this a bug, or is it just me? Josh Berkus <josh@agliodbs.com>
@ 2001-02-08 10:59 ` Jan Wieck <janwieck@Yahoo.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Jan Wieck @ 2001-02-08 10:59 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-sql

Josh Berkus wrote:
> Tom et al.
>
> Discovered this quirk in foriegn keys:
>
> In the preliminary version of a database, I added foriegn
> key constraints to a number of tables, linking them to a
> column in a shared reference table (status.status) that was
> only one-half of a composite primary key (and thus the
> values were not unique).  When I tried to delete a row
> containing a "2" in the status column from the status
> relation, I received a Foreign Key violation error event
> though there were other "2"'s in the table still present.
>
> So ... is this a bug in forign key implementation, or just
> my fault for keying off a non-unique value?
>
> And, if the latter, is there a way I can construct a foreign
> key constraint that keys onto a view or query?

    The referenced columns of a foreign key constraint shall have
    a unique constraint. That's how it is in the SQL  specs.   So
    it  is a bug that the system let's you specify the constraint
    at all. I think Stephan fixed it for 7.1.

    OTOH Postgres  doesn't  (and  shouldn't)  enforce  it  after,
    because  if  it  would,  you couldn't drop/create a corrupted
    index.

    And no, you can't actually reference to a  view  or  anything
    else  than a table. That is, because the system wouldn't know
    how to check for the DELETE/UPDATE cases on the  base  tables
    building  the  view  if  the  removal  of a key would violate
    existing references.

    For such custom setups,  we  have  procedural  languages  and
    triggers.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-02-08 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-02-07 04:15 Is this a bug, or is it just me? Josh Berkus <josh@agliodbs.com>
2001-02-07 17:21 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-02-08 10:59 ` Jan Wieck <janwieck@Yahoo.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