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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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
String postgresql函数声明中的字符串形成失败_String_Postgresql_Casting_Sql Function - Fatal编程技术网

String postgresql函数声明中的字符串形成失败

String postgresql函数声明中的字符串形成失败,string,postgresql,casting,sql-function,String,Postgresql,Casting,Sql Function,我已经在sql中创建了一个函数,我调用了一个非常大的表的各个块 我添加了一个值为0到4的列chunk(inttyped column),并希望将函数逐块应用于表chunk 以下是我试图参数化的sql: update some_t t set col_2 = (select t2.col_2 from some_t t2 where t2.col_1 = t. col_1 and t2.col_2 is not null

我已经在sql中创建了一个函数,我调用了一个非常大的表的各个块

我添加了一个值为0到4的列
chunk
int
typed column),并希望将函数逐块应用于表chunk

以下是我试图参数化的sql:

update some_t t
    set col_2 = (select t2.col_2 from some_t t2
                 where t2.col_1 = t. col_1 
                 and t2.col_2 is not null
                 limit 1)
where t.col_2 is null;

这是一个函数,带有额外的参数
chunk
,它允许我在表的块上对函数进行分区

CREATE FUNCTION impute_place(table_ text, impute_from_col text, impute_to_col text, chunk text)
RETURNS VOID
AS $func$

BEGIN
    EXECUTE 'UPDATE ' || table_ || ' t1
             SET ' || impute_to_col || ' = (select t2.' || impute_to_col ||
                                            ' from ' || table_ || ' t2
                                             where t2.' || impute_from_col || ' = t1.' || impute_from_col ||
                                            ' and t2.' || impute_to_col || ' is not null
                                             limit 1)
             WHERE t1.' || impute_to_col || ' is null
             AND chunk = ' || chunk ||;
END;
$func$
LANGUAGE plpgsql VOLATILE;
当我随后尝试在所有分区上运行它时,我得到一个错误,我试图修复,但无法修复

另外,没有
和chunk='| | chunk | |该函数工作正常,因此erro必须在此行中

select impute_place('some_t', 'col_1', 'col_2', '0');
select impute_place('some_t', 'col_1', 'col_2', '1');
select impute_place('some_t', 'col_1', 'col_2', '2');
select impute_place('some_t', 'col_1', 'col_2', '3');
select impute_place('some_t', 'col_1', 'col_2', '4');

我得到以下错误:

[42883] ERROR: operator does not exist: 
text || Hint: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
Where: PL/pgSQL function impute_place(text,text,text,text) line 4 at EXECUTE

删除
之后的无效连接,即
。||块| |应为
。|124;块。作为旁注:
chunk
似乎是数字。因此,它的类型应该是数字类型,而不是
text
。对于其他变量,
name
更适合。谢谢。成功了。如果你把它作为答案发布,我会接受它,这样你就能得到分数了!:)