From: | Ulrich Goebel <ml(at)fam-goebel(dot)de> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | UPDATE Syntax |
Date: | 2021-02-03 10:31:41 |
Message-ID: | 811db0e2-1ae3-9908-a421-4a4ba74fcc96@fam-goebel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
in a Python Script I build an UPDATE using the syntax:
update tbl set (col1, col2, ...) = (val1, val2, ...) where id = xx
That works as long in the two lists are more then one column and values.
If I have just one column and value, I get an error message:
==========================================================================
cg=# select id, name, vorname, status from tbl_person;
id | name | vorname | status
----+--------+---------+--------
3 | Goebel | Ulrich | a
(1 row)
cg=#
cg=#
cg=#
cg=# update tbl_person set status = 'a' where id=3;
UPDATE 1
cg=#
cg=#
cg=#
cg=# update tbl_person set (status) = ('a') where id=3;
ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or
ROW() expression
LINE 1: update tbl_person set (status) = ('a') where id=3;
^
cg=#
cg=#
cg=#
cg=# update tbl_person set (status, name) = ('a', 'Goebel') where id=3;
UPDATE 1
cg=#
==========================================================================
In fact in the script I have both cases: one ore more columns.
Is there another way but to code a case differentiation to avoid this
error message? Well, I could use the other syntax:
update tbl set col1=val1, col2=val2, ... where id=xx
but I just like the former...
Thank's
Ulrich
--
Ulrich Goebel
Am Büchel 57, 53173 Bonn
From | Date | Subject | |
---|---|---|---|
Next Message | Ulrich Goebel | 2021-02-03 10:38:35 | Re: UPDATE Syntax - solved |
Previous Message | Laurenz Albe | 2021-02-03 10:30:45 | Re: count(*) vs count(id) |