我希望能够编写将数据库更改为当前我已登录的sql查询。
示例:
$ psql my_db
psql(9.1.1)
my_db=> ALTER DATABASE my_db SET some_variable = '0';
^^^^^
是否有办法避免在此查询中指定数据库名称?
如果您使用的是9.1,则可以使用:
DO $$
BEGIN
execute 'alter database '||current_database()||' set some_var = ''0''';
END
$$;
如果在psql
中执行脚本,则可以使用psql
的替换机制:
alter database :DBNAME SET ...
文档在这里:http://www.postgresql.org/docs/current/interactive/app-psql.html#APP-PSQL-VARIABLES