2023年8月3日发(作者:)

postgresSQL在update语句中使⽤别名和关联表(⼦查询)update apt_taxiway m

set code = , name = om (select name as code, name, uuid, version, airport_code from am_taxiway_area where name like '%-%' and version ='2020_14'union allselect as code, , , n, t_code

from am_taxiway_area a right join (select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name havingcount(name) = 1

) b on = ere n = '2020_14'union allselect as code, || '_' || 1 as name, , n, t_code

from am_taxiway_area a right join (select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name havingcount(name) > 1

) b on = ere n = '2020_14') nwhere = and n = '2020_14';同mysql和oracle不同,pgsql的update语法中关联表不使⽤join ,⽽是使⽤from,关联条件不⽤on,⽽是写在where中,和条件写在⼀起。使⽤别名更新时,被更新表的字段不能⽤别名,如 = 是不⾏的。

2023年8月3日发(作者:)

postgresSQL在update语句中使⽤别名和关联表(⼦查询)update apt_taxiway m

set code = , name = om (select name as code, name, uuid, version, airport_code from am_taxiway_area where name like '%-%' and version ='2020_14'union allselect as code, , , n, t_code

from am_taxiway_area a right join (select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name havingcount(name) = 1

) b on = ere n = '2020_14'union allselect as code, || '_' || 1 as name, , n, t_code

from am_taxiway_area a right join (select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name havingcount(name) > 1

) b on = ere n = '2020_14') nwhere = and n = '2020_14';同mysql和oracle不同,pgsql的update语法中关联表不使⽤join ,⽽是使⽤from,关联条件不⽤on,⽽是写在where中,和条件写在⼀起。使⽤别名更新时,被更新表的字段不能⽤别名,如 = 是不⾏的。