Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating by concatenating columns in PostgreSQL

Tags:

I need to set the hotelcode by concatenating it with the vendorcitycode (separated by an underscore) as follows.

update schema.table_name set
       hotelcode = hotelcode+"_"+vendorcitycode)
 where vendorid = 'INV27' and vendorcitycode = 'LON'

Note : hotelcode and vendorcitycode are two columns of type character varying(100). I use PostgreSQL 8.0.

like image 817
namalfernandolk Avatar asked May 18 '12 13:05

namalfernandolk


People also ask

How do you update columns in PostgreSQL?

First, specify the name of the table that you want to update data after the UPDATE keyword. Second, specify columns and their new values after SET keyword. The columns that do not appear in the SET clause retain their original values. Third, determine which rows to update in the condition of the WHERE clause.


1 Answers

UPDATE   table_name
SET      hotelcode = hotelcode || '_' || vendorcitycode
WHERE    (vendorid, vendorcitycode) = ('INV27', 'LON')
like image 146
Quassnoi Avatar answered Sep 22 '22 18:09

Quassnoi