列上的PostgreSQL复杂更新操作(PostgreSQL complex update operation on column)

我正在尝试更新具有place_id(fk)的每一行,但db表示select的结果有多于一行。 当然它确实有多行,因为我正在尝试更新列,而不仅仅是一条记录。

update Event set placeListingName = (select substr(coalesce(epc.shortTitle, epc.title),1,100) from Event e join e.place p join p.publicContent epc where e.place is not null) where place is not null

括号中的表达式(选择...其中e.place不为null)运行良好并返回字符串列表

I'm trying to update every row which has place_id (fk) but db says the result of select is has more then one row. Of course it does has more then one row, because I'm trying to update column, not only one record.

update Event set placeListingName = (select substr(coalesce(epc.shortTitle, epc.title),1,100) from Event e join e.place p join p.publicContent epc where e.place is not null) where place is not null

the expression in brackets (select ... where e.place is not null) works well and returns a list of Strings

最满意答案

如果有兴趣:

update Event e set e.placeListingName = (select substr(coalesce(epc.shortTitle, epc.title),1,100) from Event ev join ev.place p join p.publicContent epc where ev.id = e.id) where e.place is not null

If anyone interested:

update Event e set e.placeListingName = (select substr(coalesce(epc.shortTitle, epc.title),1,100) from Event ev join ev.place p join p.publicContent epc where ev.id = e.id) where e.place is not null

更多推荐