pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Rudolph <mrudolph@zetec.com>
To: pgsql-sql@postgresql.org
Subject: INDEX and NULL values
Date: Thu, 18 Dec 2003 16:23:21 -0800
Message-ID: <A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.com> (raw)

Here are the sample tables for my question.

CREATE TABLE bar (
    id        int2 PRIMARY KEY UNIQUE DEFAULT nextval('bar_id_seq'),
    ...
);

CREATE TABLE foo (
    id        int2 PRIMARY KEY UNIQUE DEFAULT nextval('foo_id_seq'),
    number    int2 NOT NULL,
    bar_id    int2 REFERENCES bar ON UPDATE CASCADE ON DELETE CASCADE,
    ...
);
CREATE UNIQUE INDEX foo_number_id_index ON foo(number, bar_id);

I am a novice for sure. I am trying to prevent multiple combinations
of the number and bar_id fields. However, since the bar_id can be NULL
I am actually getting multiple combinations with NULL. 

For example, 
foo:
id     number    bar_id .....
-------------------------------
1    |    1    | 
2    |    2    |   3
3    |    1    |   
....

Row 1 and 3 are duplicates that I wish to disallow. I am however seeing
just this behavior with 7.3.2. I am seeing the duplicates. I am not able
to add another row with number = 2 and bar_id = 3. 

What am I doing wrong? What sort of NULLism is biting me?

I have searched around the lists and the documentation, I am sure it is
explained but I am not able to see the solution. I link that helps out
would be appreciated.

Thanks for your help.

Matthew

-----------------------------------------------------------------------
DISCLAIMER:  Information contained in this message and/or
attachment(s) may contain confidential information of Zetec, Inc.
If you have received this transmission in error, please notify
the sender by return email.
-----------------------------------------------------------------------



Message-ID: <A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.com>
Permalink:  ../A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.com/
Also on:    postgresql.org/message-id/A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.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: mrudolph@zetec.com
  Subject: Re: INDEX and NULL values
  In-Reply-To: <A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.com>
  References: <A0823E3FBDD5694493D6C61793F044BC22D1CA@exchange02.zetec.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