如何在psql的命令行查询中转义单引号?

exp*_*ert 7 postgresql quoting psql

我google了很多,但..

如何在psql的命令行查询中转义单引号?

psql -t -A -F $'\t' postgresql://zzzz:5432/casedb -U qqqq -c 'select id,ext_ids ->> 'qwe' as qwe from data ORDER BY qwe' > /jdata/qwe.tab
Run Code Online (Sandbox Code Playgroud)

导致错误

ERROR:  column "qwe" does not exist
LINE 1: select id,ext_ids ->> qwe as qwe from data...
Run Code Online (Sandbox Code Playgroud)

kli*_*lin 6

在Postgres中,您可以使用美元引用的字符串:

select id,ext_ids ->> $$qwe$$ as qwe from data ORDER BY qwe;
-- or
select id,ext_ids ->> $anything$qwe$anything$ as qwe from data ORDER BY qwe;
Run Code Online (Sandbox Code Playgroud)