Re: UPDATE Syntax - solved

Поиск
Список
Период
Сортировка
От Ulrich Goebel
Тема Re: UPDATE Syntax - solved
Дата
Msg-id 03338ea2-b389-f5f2-cdf5-0d17a8c34e41@fam-goebel.de
обсуждение исходный текст
Ответ на UPDATE Syntax  (Ulrich Goebel <ml@fam-goebel.de>)
Список 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



В списке pgsql-general по дате отправления:

Предыдущее
От: Ulrich Goebel
Дата:
Сообщение: UPDATE Syntax
Следующее
От: Niels Jespersen
Дата:
Сообщение: table returning function for each row in other resultset