PostgreSQL,区分大小写 EXECUTE

问题描述 投票:0回答:1

EXECUTE 语句无法识别数据库名称中的大写字母。

在名为“ABcdeFG”的数据库上运行以下查询

DO
$c$
BEGIN
EXECUTE 'ALTER DATABASE ' || current_database() || ' SET client_encoding = $$LATIN1$$';
END;
$c$;

返回以下错误:

"ERROR:  database "abcdefg" does not exist
CONTEXT:  SQL statement "ALTER DATABASE ABcdeFG SET client_encoding = $$LATIN1$$"
PL/pgSQL function inline_code_block line 3 at EXECUTE

********** Error **********

ERROR: database "abcdefg" does not exist
SQL state: 3D000
Context: SQL statement "ALTER DATABASE ABcdeFG SET client_encoding = $$LATIN1$$"
PL/pgSQL function inline_code_block line 3 at EXECUTE"

有没有办法根据数据库名称中的大小写字母来执行此命令?

sql postgresql command execute case-sensitive
1个回答
0
投票

它的工作原理是将数据库名称放在引号中:

DO
$c$
BEGIN
EXECUTE 'ALTER DATABASE "' || current_database() || '" SET client_encoding = $$LATIN1$$';
END;
$c$;
© www.soinside.com 2019 - 2024. All rights reserved.