Re: update problem

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Sudharshan(dot)Gundlapalle(at)mcs(dot)vuw(dot)ac(dot)nz
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: update problem
Date: 2002-09-09 14:29:12
Message-ID: 1031581752.25060.221.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, 2002-09-09 at 02:55, Sudharshan Reddy wrote:
> How can I update several columns in one UPDATE query ?
> The users's guide says:
> UPDATE table SET col = expression [, ...]
^^^^^^^^^^^^^^^^^^^^^^^^
> [ FROM fromlist ]
> [ WHERE condition ]
...
> UPDATE timed SET month='january' where month='1' and set month='feb' where month = '2';
> ERROR: parser: parse error at or near "month"

That isn't setting two different columns. You are trying to update the
same column with 2 different WHERE clauses. These must be two separate
queries.

UPDATE timed SET month='january' where month='1';
UPDATE timed SET month='feb' where month = '2';

Updating multiple columns works like this:

UPDATE timed SET month='january', year=2002 WHERE ...

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Submit yourselves therefore to God. Resist the devil,
and he will flee from you." James 4:7

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2002-09-09 17:21:54 Re: Unix domain sockets
Previous Message Sudharshan Reddy 2002-09-09 01:55:33 update problem