Skip site navigation (1) Skip section navigation (2)

Re: Update function

From: C(dot)Raymond Church <crchurch(at)worldnet(dot)att(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Update function
Date: 2002-04-12 11:05:01
Message-ID: 02041207050101.07881@linux01 (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

On Friday 12 April 2002 11:42 am, you wrote:
> Hi all,
> I have a table with products in and each products has 13 a digit barcode
> as its primary key.  There

I'm not sure what you mean, "has 13 a digit barcode...".   Is that a style of 

> I'm really stuck.  Any suggestions would be welcome.  What would really be
> useful is an example on how to move through a result set one record at a
> time, check if that changing the barcode on that current record does not
> result in an alreadly existing barcode.  If it doesn't, then then record
> is updated through an update, if it does, the record is deleted.
> Thanks

I would suggest that you put barcode data in a separate table "barcodes" with 
primary key the same as your "products" primary key (foreign key in barcodes 
table) and change your products table to use a serial data type for primary 
key (rather than the current "barcodes" field).  Doing those two things 
should make it possible to query for barcodes that point to the same product; 
therefore, duplicate barcodes for the same product wouldn't matter.  As I 
understand it, barcodes may be assigned to the same product for miriad 
reasons; e.g., special pricing, etc.

Also, if you don't want duplicate barcodes ("barcode" table), set a 
constraint for the "barcode" column to UNIQUE.


pgsql-novice by date

Next:From: Helge BahmannDate: 2002-04-12 11:38:33
Subject: Re: Update function
Previous:From: Rasmus MohrDate: 2002-04-12 10:48:14
Subject: Re: Matching a large number of user chosen

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group