pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Barwick <barwick@gmx.net>
To: Phill Kenoyer <pgsql@c0de.net>
To: pgsql-admin@postgresql.org
Subject: Re: Primary Key Problems
Date: Sat, 8 Dec 2001 02:52:55 +0100
Message-ID: <200112080246.DAA20030@post.webmailer.de> (raw)
In-Reply-To: <20011208014433.GA2913@c0de.net>
References: <20011208014433.GA2913@c0de.net>

On Saturday 08 December 2001 02:44, Phill Kenoyer wrote:
> Here is a good one.  I have three fields set for my primary key.  Now I
> thought that a primary key was unique, and dups can not be inserted.

That's the theory ;-)

> CREATE TABLE "inventory" (
>         "stock" character varying(50) NOT NULL,
>         "inventory_type" character varying(20) DEFAULT 'unknown' NOT NULL,
>         "client_id" integer NOT NULL,
> [...]
>         Constraint "inventory_pkey"
> 		Primary Key ("stock", "inventory_type", "client_id")
> );
>
> and I insert into the db and get dups.
>
>  client_id | stock | inventory_type
> -----------+-------+----------------
>         81 | 2001  | new
>         81 | 2001  | new
>         81 | 2003  | new
>         81 | 2005  | new
>         81 | 2006  | new
>         81 | 2006  | new
>         81 | 2008  | new
>         81 | 2008  | new
>
> Why did I get dups in my data?

Are the duplicated values in "stock" and "inventory_type"
genuinely identical? As they are both VARCHARs they could
contain differing amounts of trailing spaces or other 
'invisible' characters which would not be obvious from the
console, but would represent valid and unique values
to the constraint checker. These could result from
unfiltered input, such as from an HTML form.

Also, does the primary key still exist?

SELECT relname, relowner FROM pg_class WHERE relname='inventory_pkey'

Ian Barwick




view thread (8+ messages)  latest in thread

Message-ID: <200112080246.DAA20030@post.webmailer.de>
Permalink:  ../200112080246.DAA20030@post.webmailer.de/
Also on:    postgresql.org/message-id/200112080246.DAA20030@post.webmailer.de

 · 

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-admin@postgresql.org
  Cc: barwick@gmx.net, pgsql@c0de.net
  Subject: Re: Primary Key Problems
  In-Reply-To: <200112080246.DAA20030@post.webmailer.de>
  References: <20011208014433.GA2913@c0de.net> <200112080246.DAA20030@post.webmailer.de>

* 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