在执行插入语句中转义引号 [英] escaping quotes in execute insert statment
本文介绍了在执行插入语句中转义引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在循环内插入一个函数。参见下面的函数。
I have a function that has an insert inside within loop. See the function below.
create temp table temp2 (id serial, other_value uuid);
CREATE OR REPLACE function verify_uuid() returns varchar AS $$
declare uu RECORD;
BEGIN
FOR uu IN select * from temp1
loop
execute 'INSERT INTO temp2 values ''' || uu ||''':uuid';
END LOOP;
END
$$
LANGUAGE 'plpgsql' ;
select verify_uuid();
我遇到的问题是价值观部分。使用当前的设置,我得到了错误:
The problem that I am having is the values part. With its present setup, I am getting the error:
查询:将INSERT插入temp2值
'(1,6f32e71c-9aad -48a9-a72c-bdec2f4548a2)':uuid
QUERY: INSERT INTO temp2 values '(1,6f32e71c-9aad-48a9-a72c-bdec2f4548a2)':uuid
引号放在错误的位置,我不确定如何获得它们在正确的地方。
The quotes are in the wrong place, and I am not sure how to get them in the right place.
推荐答案
所以最后,我讲了以下内容。这使我明白了这一点:
So in the end, I went with the following. It got me to this point:
EXECUTE'INSERT INTO temp2 values('|| uu.id ||','''|| uu.some_value ||''')';
这篇关于在执行插入语句中转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文