为什么会出现此错误?
set session my.vars.id = SELECT "Name" FROM "Client" WHERE "ID" = 1;
SELECT * FROM "Client" WHERE "Name" = current_setting('my.vars.id');
...
ERROR: syntax error at or near "SELECT"
LINE 1: set session my.vars.id = SELECT "Name" FROM "Client" WHERE "...
^
答案 0 :(得分:1)
因为只能在SET
命令中使用常量。
尝试一下:
SELECT set_config('my.vars.id', "Name", FALSE)
FROM "Client" WHERE "ID" = 1;