From: | Ulrich Goebel <ml(at)fam-goebel(dot)de> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: UPDATE Syntax - solved |
Date: | 2021-02-03 10:38:35 |
Message-ID: | 03338ea2-b389-f5f2-cdf5-0d17a8c34e41@fam-goebel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Solved. Use
update tbl set (col1, col2, ...) = ROW(val1, val2, ...) where id=xx
Thank's to Laurenz Albe in the german mailinglist.
Am 03.02.21 um 11:31 schrieb Ulrich Goebel:
> 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 | Niels Jespersen | 2021-02-03 15:01:07 | table returning function for each row in other resultset |
Previous Message | Ulrich Goebel | 2021-02-03 10:31:41 | UPDATE Syntax |