在PostgreSQL中通过连接列进行更新

28

我需要按照以下方式通过将hotelcode与vendorcitycode(由下划线分隔)连接来设置hotelcode。

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

注意: hotelcodevendorcitycode是两个类型为character varying(100)的列。我使用的是PostgreSQL 8.0。


我不知道这是否是你被踩的原因,但答案在文档中很容易找到。http://www.postgresql.org/docs/8.0/interactive/functions-string.html#FUNCTIONS-STRING-SQL PostgreSQL 8.0版本已经停止支持;你应该尽快安排升级。http://www.postgresql.org/support/versioning/ - kgrittn
1个回答

55
UPDATE   table_name
SET      hotelcode = hotelcode || '_' || vendorcitycode
WHERE    (vendorid, vendorcitycode) = ('INV27', 'LON')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接