Postgres usage of format()

 ̄綄美尐妖づ 提交于 2020-01-07 02:52:07

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/39204461/postgres-usage-of-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!