Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Postgres:在由\prompt显示的文本中使用连接_String_Postgresql_Concatenation_Psql_Prompt - Fatal编程技术网

String Postgres:在由\prompt显示的文本中使用连接

String Postgres:在由\prompt显示的文本中使用连接,string,postgresql,concatenation,psql,prompt,String,Postgresql,Concatenation,Psql,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 ta

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
myuser=# \i /home/myuser/test.sql
table_customers
The table
psql:/home/myuser/test.sql:3: invalid variable name: "||"
: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
CONCAT(The table ,
psql:/home/myuser/test.sql:3: invalid variable name: "table_customers,"
: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