postgresql更新多列的查询

时间:2017-05-28 13:48:28

标签: sql postgresql

我有一个包含两列的表:build_desc和land_use

build_desc - column    land_use
Religious -row         Multiple-family residential'residential
Educational -row       Single-family 
                       Parks, Recreation, and Open Space

我在文本中添加了一个名为type_的新列,我想根据上面两列类型更新type_列。我正在接受更新查询语法

update final_parcels set type_ = case 
    when build_desc ='Religious' then 'Religious'
    when build_desc ='Educational' then 'School'
    when land_use in('Multiple-family residential','Single-family residential') then 'Residential'
    when land_use = 'Parks, Recreation, and Open Space'
    end

给我错误

ERROR:  syntax error at or near "end"
LINE 6:  end
         ^

********** Error **********

ERROR: syntax error at or near "end"
SQL state: 42601
Character: 288

1 个答案:

答案 0 :(得分:0)

我认为你真的很亲密。 。 。只是错过了最后一个then

update final_parcels
    set type_ = (case when build_desc = 'Religious' then 'Religious'
                      when build_desc = 'Educational' then 'School'
                      when land_use in ('Multiple-family residential','Single-family residential') then 'Residential'
                      when land_use = 'Parks, Recreation, and Open Space'
                      then ??
                 end);

您的示例表明??应为NULL''