Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在postgresql中连接两列并用结果替换其中一列_Postgresql_Sql Update_Subquery_Concatenation - Fatal编程技术网

在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)