我有一个sql块(file.sql):
DO $$
DECLARE
var1 varchar;
BEGIN
var1 := :key;
END $$;
当我用psql调用此.sql时,
psql -h localhost -v key="value" -U user -f file.sql postgredb
我收到错误:
错误:“:”
处或附近的语法错误
想知道为什么命令行arg没有得到解决
答案 0 :(得分:1)
我认为你不能那样做。 我创建了一个psql函数,它接受一个varchar参数(例如你的例子中的键),然后我将从终端调用它:
alex@mbpro:~/sdk/tools/bin$ ./sdkmanager --help
Usage:
sdkmanager [--uninstall] [<common args>] \
[--package_file <package-file>] [<packages>...]
sdkmanager --update [<common args>]
sdkmanager --list [<common args>]
In its first form, installs, or uninstalls, or updates packages.
<package> is a sdk-style path (e.g. "build-tools;23.0.0" or
"platforms;android-23").
<package-file> is a text file where each line is a sdk-style path
of a package to install or uninstall.
Multiple --package_file arguments may be specified in combination
with explicit paths.
In its second form (with --update), currently installed packages are
updated to the latest version.
In its third form, all installed and available packages are printed out.
Common Arguments:
--sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK containing this tool
--channel=<channelId>: Include packages in channels up to <channelId>.
Common channels are:
0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).
--include_obsolete: With --list, show obsolete packages in the
package listing. With --update, update obsolete
packages as well as non-obsolete.
--no_https: Force all connections to use http rather than https.
--proxy=<http | socks>: Connect via a proxy of the given type.
--proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.
--proxy_port=<port #>: Proxy port to connect to.
* If the env var REPO_OS_OVERRIDE is set to "windows",
"macosx", or "linux", packages will be downloaded for that OS.
然后你可以将所有这些包装在函数的某个bash脚本中,以便你可以更快地调用它。
希望有所帮助,欢呼。