Re: [GENERAL] select for insert?

From: "omid omoomi" <oomoomi(at)hotmail(dot)com>
To: jose(at)sferacarta(dot)com, lylyeoh(at)mecomb(dot)com
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] select for insert?
Date: 2000-01-18 06:41:51
Message-ID: 20000118144151.48600.qmail@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi,
why not using "primary key (a , b) " clause at the end of your create table
statement?It would unsure you that "b" is unique for particular "a". I
suggest that you test the null value entries... if you are going to face
with.
regards,
omid.

>From: Jose Soares <jose(at)sferacarta(dot)com>
>To: Lincoln Yeoh <lylyeoh(at)mecomb(dot)com>
>CC: "pgsql-general(at)postgreSQL(dot)org" <pgsql-general(at)postgreSQL(dot)org>
>Subject: Re: [GENERAL] select for insert?
>Date: Tue, 18 Jan 2000 14:41:34 +0100
>
>
>
>Lincoln Yeoh wrote:
>
> > Hi everyone,
> >
> > say I have a table test
> > create table test (a int, b text);
> >
> > and I want to ensure that 'b' is unique for a particular 'a' ('a' not
>being
> > unique).
> >
> > Right now I can do something like
> > begin transaction
> > select count(*) from test where b =$value;
> > if count = 0 then insert into test (a,b) values ($a, $value);
> >
> > But there is still a chance of a duplicate being inserted.
>
>use unique constraint on column a as in:
>
>CREATE TABLE test (a char unique, b int);
>
>Jos
>
>
>
>************
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Browse pgsql-general by date

  From Date Subject
Next Message Robert 2000-01-18 07:33:37 Re: [GENERAL] Two serial fields question
Previous Message Micheal H. 2000-01-18 06:40:09 jdbc question