小编Blo*_*mex的帖子

从 shell 运行参数化查询时,“:”处或附近出现语法错误

我正在尝试从 shell 运行参数化查询。

但是当我跑步时:

p='some stuff'
psql -d "dbname" -v v1="$p" -c "SELECT * FROM table WHERE name=:'v1'"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ERROR:  syntax error at or near ":"
Run Code Online (Sandbox Code Playgroud)

同时:

psql -d "dbname" -v v1="$p" -c "\echo :'v1'"
Run Code Online (Sandbox Code Playgroud)

工作正常。(按预期返回'some stuff':)

postgresql shell psql

2
推荐指数
1
解决办法
719
查看次数

标签 统计

postgresql ×1

psql ×1

shell ×1