Postgresql 从存储过程更新
我需要创建一个存储过程,它可以接受模式名和表名作为参数,并对同一个表进行更新Postgresql 从存储过程更新,postgresql,sql-injection,plpgsql,dynamic-sql,Postgresql,Sql Injection,Plpgsql,Dynamic Sql,我需要创建一个存储过程,它可以接受模式名和表名作为参数,并对同一个表进行更新 CREATE OR REPLACE FUNCTION garscratch.update_table(schema_name text, table_name text ) RETURNS void as $$ DECLARE table TEXT; BEGIN execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for
CREATE OR REPLACE FUNCTION garscratch.update_table(schema_name text, table_name text ) RETURNS void as $$
DECLARE
table TEXT;
BEGIN
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
END;
$$ LANGUAGE plpgsql;
当我执行上述程序时,如下所示:
select update_table(my,my_table);
我得到一个错误:
“我的”列不存在
它不将“my”作为架构名称。执行以下过程:
select update_table('my','my_table');
还要换行吗
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
到
执行以下程序:
select update_table('my','my_table');
还要换行吗
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
到
执行以下程序:
select update_table('my','my_table');
还要换行吗
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
到
执行以下程序:
select update_table('my','my_table');
还要换行吗
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
到
在我看来,您可能对
表_name | |'set id=
部分有问题-具体地说,我认为您应该在'
和set
之间添加一个空格。尝试打印您正在执行的内容,您可能会发现问题所在。在我看来,您可能对表_name | |'set id=
部分有问题-具体地说,我认为您应该在'
和set
之间添加一个空格。尝试打印您正在执行的内容,您可能会发现问题所在。在我看来,您可能对表_name | |'set id=
部分有问题-具体地说,我认为您应该在'
和set
之间添加一个空格。尝试打印您正在执行的内容,您可能会发现问题所在。在我看来,您可能对表_name | |'set id=
部分有问题-具体地说,我认为您应该在'
和set
之间添加一个空格。尝试打印您正在执行的操作,您可能会发现问题所在。- 在
和tablename
之间需要一个空格set
- 您需要在值
周围加上单引号“test”
或者,如果它应该是一个列名,则根本不需要引号 - 您需要清理标识符以避免SQL注入
- 在
和tablename
之间需要一个空格set
- 您需要在值
周围加上单引号“test”
或者,如果它应该是一个列名,则根本不需要引号 - 您需要清理标识符以避免SQL注入
- 在
和tablename
之间需要一个空格set
- 您需要在值
周围加上单引号“test”
或者,如果它应该是一个列名,则根本不需要引号 - 您需要清理标识符以避免SQL注入
- 在
和tablename
之间需要一个空格set
- 您需要在值
周围加上单引号“test”
或者,如果它应该是一个列名,则根本不需要引号 - 您需要清理标识符以避免SQL注入
@Your:这显然与SQL注入有关。标识符必须被视为用户输入,并针对动态SQL进行清理。这实际上是这里最重要的问题。缺少的空白很容易解决。@ErwinBrandstetter好的,公平point@Your:这显然与SQL注入有关。标识符必须被视为用户输入,并针对动态SQL进行清理。这实际上是这里最重要的问题。缺少的空白很容易解决。@ErwinBrandstetter好的,公平point@Your:这显然与SQL注入有关。标识符必须被视为用户输入,并针对动态SQL进行清理。这实际上是这里最重要的问题。缺少的空白很容易解决。@ErwinBrandstetter好的,公平point@Your:这显然与SQL注入有关。标识符必须被视为用户输入,并针对动态SQL进行清理。这实际上是这里最重要的问题。缺少的空白很容易解决。@ErwinBrandstetter好的,公平点