Postgres使用format() [英] Postgres usage of format()
本文介绍了Postgres使用format()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这种情况下,format()的用法通常可以互换吗?
Is the usage of format() in cases like this generally interchangeable?
exec_str := format('UPDATE ' || TG_ARGV[0] ||
' SET username = current_user,
time = current_timestamp::timestamp(0);'
);
EXECUTE exec_str;
vs.
exec_str := 'UPDATE ' || TG_ARGV[0] ||
' SET username = current_user,
time = current_timestamp::timestamp(0);'
;
EXECUTE format(exec_str);
推荐答案
函数format()
的主要优点是可以使用参数:
The primary benefit of the function format()
is that you can use parameters:
execute format('
UPDATE %I
SET username = current_user,
time = current_timestamp::timestamp(0);',
TG_ARGV[0]);
在文档中了解更多信息.
Read more in the documentation.
这篇关于Postgres使用format()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文