Re: simple? query

From: "Relyea, Mike" <Mike(dot)Relyea(at)xerox(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Cc: "Jan Verheyden" <jan(dot)verheyden(at)uz(dot)kuleuven(dot)ac(dot)be>
Subject: Re: simple? query
Date: 2009-08-14 12:58:35
Message-ID: AF7D9319B29A0242A33C3BF843BD313308A20639@USA7061MS03.na.xerox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> From: Relyea, Mike [mailto:Mike(dot)Relyea(at)xerox(dot)com]
> Sent: Thursday, August 13, 2009 10:47 PM
>
> > From: pgsql-sql-owner(at)postgresql(dot)org
> [mailto:pgsql-sql-owner(at)postgresql(dot)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(dot)verheyden(at)uz(dot)kuleuven(dot)ac(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Joshua Tolley 2009-08-14 13:24:16 Re: Field or record level encryption / decryption
Previous Message Hengky Lie 2009-08-14 09:20:58 Field or record level encryption / decryption