-
-
Save tearf001/038fc36481863f3b732641c01c6d5ed9 to your computer and use it in GitHub Desktop.
动态查询引用三级
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXECUTE 'UPDATE tbl SET ' | |
|| quote_ident(colname) -- | |
|| ' = ' | |
|| quote_nullable(newvalue) | |
|| ' WHERE key = ' | |
|| quote_literal(keyvalue); | |
EXECUTE format('UPDATE tbl SET %I = %L ' | |
'WHERE key = %L', colname, newvalue, keyvalue); | |
%I is equivalent to quote_ident, and %L is equivalent to quote_nullable. | |
The format function can be used in conjunction with the USING clause: | |
EXECUTE format('UPDATE tbl SET %I = $1 WHERE key = $2', colname) | |
USING newvalue, keyvalue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment