Thread: update problem

update problem

From
Sudharshan Reddy
Date:
How can I update several columns in one UPDATE query ?
The users's guide says:
UPDATE table SET col = expression [, ...]
    [ FROM fromlist ]
    [ WHERE condition ]

CREATE TABLE time(
orderdate date,
day char(10),
month char(10),
year integer
);

UPDATE timed SET month='january' where month='1' and set month='feb' where month = '2';
ERROR:  parser: parse error at or near "month"

thanks
sudharshan

--
Sudharshan Reddy G
Masters of Computer Science,
Victoria University Of Willington,
Willington-6004
NewZealand

Re: update problem

From
Oliver Elphick
Date:
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.Elphick@lfix.co.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