Postgres:在 \prompt 显示的文本中使用连接
Postgres: using concatenation in the text displaed by \prompt
在psql
中,有没有办法让\prompt
文本成为字符串和变量的串联?例如,假设在文件 test.sql
中我们有:
\set name table_customers
\echo :name
\prompt CONCAT('The table ', table_customers, ' was created') answer
\echo :answer
上面的不行:
myuser=# \i /home/myuser/test.sql
table_customers
CONCAT(The table ,
psql:/home/myuser/test.sql:3: invalid variable name: "table_customers,"
:answer
我也试过:
\set name table_customers
\echo :name
\prompt 'The table ' || table_customers || ' was created' answer
\echo :answer
但是还是不行:
myuser=# \i /home/myuser/test.sql
table_customers
The table
psql:/home/myuser/test.sql:3: invalid variable name: "||"
:answer
替换“||”用“+”给出完全相同的结果。
正确的做法是什么?
我实际上刚刚找到了一个可行的解决方案:只需先连接到另一个变量(使用简单的空格),然后将该新变量作为 \prompt
文本传递:
\set name table_customers
\echo :name
\set input 'The table ' :name ' was created.'
\prompt :input answer
\echo :answer
在psql
中,有没有办法让\prompt
文本成为字符串和变量的串联?例如,假设在文件 test.sql
中我们有:
\set name table_customers
\echo :name
\prompt CONCAT('The table ', table_customers, ' was created') answer
\echo :answer
上面的不行:
myuser=# \i /home/myuser/test.sql
table_customers
CONCAT(The table ,
psql:/home/myuser/test.sql:3: invalid variable name: "table_customers,"
:answer
我也试过:
\set name table_customers
\echo :name
\prompt 'The table ' || table_customers || ' was created' answer
\echo :answer
但是还是不行:
myuser=# \i /home/myuser/test.sql
table_customers
The table
psql:/home/myuser/test.sql:3: invalid variable name: "||"
:answer
替换“||”用“+”给出完全相同的结果。
正确的做法是什么?
我实际上刚刚找到了一个可行的解决方案:只需先连接到另一个变量(使用简单的空格),然后将该新变量作为 \prompt
文本传递:
\set name table_customers
\echo :name
\set input 'The table ' :name ' was created.'
\prompt :input answer
\echo :answer