Re: simple? query - Mailing list pgsql-sql

From Relyea, Mike
Subject Re: simple? query
Date
Msg-id AF7D9319B29A0242A33C3BF843BD313308A20639@USA7061MS03.na.xerox.net
Whole thread Raw
In response to simple? query  (Jan Verheyden <jan.verheyden@uz.kuleuven.ac.be>)
List pgsql-sql
> From: Relyea, Mike [mailto:Mike.Relyea@xerox.com]
> Sent: Thursday, August 13, 2009 10:47 PM
>
> > From: pgsql-sql-owner@postgresql.org
> [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Jan Verheyden
> > Subject: [SQL] simple? query
> >
> > Hi,
> > I was trying to run following query but doesn't work:
> > if (uid='janvleuven10') then
> >   insert into test (registered) values ('1'); else
> >   insert into test (registered) values ('0'); end if;
>
> Perhaps UPDATE is what you're looking for?
> http://www.postgresql.org/docs/8.4/static/sql-update.html
>
> UPDATE test SET registered = '1' WHERE uid = 'janvleuven10';
> UPDATE test set registered = '0' WHERE uid <> 'janvleuven10';
>
>
>
>
> From: Jan Verheyden [mailto:jan.verheyden@uz.kuleuven.ac.be]
> Sent: Friday, August 14, 2009 3:11 AM
> To: Relyea, Mike
> Subject: RE: [SQL] simple? query
>
> Hi,
>
> Thanks for the reply. I was thinking of that, but the problem
> is that if it's not registered, the uid is not in the test database...
> I think in your example all the other rows will be signed as
> 'not registered, is this possible?'
>
> Regards,
>
> Jan

You're right, my suggestion will not insert new records.  It will only
update existing ones.  And yes, in my example all of the existing rows
where uid is not equal to janvleuven10 will have the registered value
set to 0.  That's how I interpreted the example you gave in your
original post.

Mike


pgsql-sql by date:

Previous
From: Hengky Lie
Date:
Subject: Field or record level encryption / decryption
Next
From: Joshua Tolley
Date:
Subject: Re: Field or record level encryption / decryption