在postgresql中连接两列并用结果替换其中一列
我有一个表格,在在postgresql中连接两列并用结果替换其中一列,postgresql,sql-update,subquery,concatenation,Postgresql,Sql Update,Subquery,Concatenation,我有一个表格,在位置列中有文件的文件夹,例如'/home/ubuntu/test',在名称列中有文件名,例如'test1.png' 我想用完整路径替换位置列,例如'/home/ubuntu/test/test.png' 我试过这个: UPDATE experiment_11.microscope_image_files SET location=(SELECT concat_ws('/', location::text, name::text) FROM experiment_11.micro
位置
列中有文件的文件夹,例如'/home/ubuntu/test'
,在名称
列中有文件名,例如'test1.png'
我想用完整路径替换位置
列,例如'/home/ubuntu/test/test.png'
我试过这个:
UPDATE experiment_11.microscope_image_files
SET location=(SELECT concat_ws('/', location::text, name::text)
FROM experiment_11.microscope_image_files);
但我得到了以下错误:
错误:用作表达式的子查询返回多行
您不需要子查询。相反,只需使用:
UPDATE experiment_11.microscope_image_files SET
location = location || '/' || name
该错误是由子查询返回的行数超过1行(实际上它返回的是所有行)引起的,但当用作表达式(如您所做)时,它必须返回0行或1行。尝试
更新实验\u 11.microscope\u image\u files SET location=concat\ws('/',location::text,name::text)