postgresql 如何删除/创建具有大写字母的数据库名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23905515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:28:04  来源:igfitidea点击:

How to Drop/Create Database name that has upper-case letter?

postgresqlpsql

提问by Vivek S.

for example my Postgresqldatabase name is Ajp

例如我的Postgresql数据库名称是Ajp

i cannot drop/create the db with this name ie. Ajp

我无法删除/创建具有此名称的数据库,即。 Ajp

my scripts for drop is

我的 drop 脚本是

cd /D D:\Apps
cd RSTAR PGSQL DOTCONNECT
cd bin
cd Debug
cd PG
psql -U postgres  -d postgres -c "DROP DATABASE  Ajp "

while executing this i got this error

执行此操作时出现此错误

D:\Apps\RSTAR PGSQL DOTCONNECT\bin\Debug\PG>psql -U postgres -d postgres -c "DR OP DATABASE Ajp " ERROR: database "ajp" does not exist

D:\Apps\RSTAR PGSQL DOTCONNECT\bin\Debug\PG>psql -U postgres -d postgres -c“DR OP DATABASE Ajp”错误:数据库“ajp”不存在

i tried psql -U postgres -d postgres -c "DROP DATABASE 'Ajp' "(db name within quotes)

我试过psql -U postgres -d postgres -c "DROP DATABASE 'Ajp' "(引号内的数据库名称)

again got error

再次出错

ERROR: syntax error at or near "'Ajp'" LINE 1: DROP DATABASE 'Ajp'

错误:“'Ajp'”处或附近的语法错误第 1 行:DROP DATABASE 'Ajp'

how fix this problem ?? (please don't comment that change your dbname to lower-case)

这个问题怎么解决??(请不要评论change your dbname to lower-case

using : "PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 32-bit"

using : "PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 32-bit"

the solution for this problem is below

这个问题的解决方案如下

  • Sholud use escape character \
  • psql -U postgres -d postgres -c "DROP DATABASE \"Ajp\";"

    see the below comment

  • 应该使用转义字符 \
  • psql -U postgres -d postgres -c "DROP DATABASE \"Ajp\";"

    下面的评论

回答by a_horse_with_no_name

SQL identifiers that are case-sensitive need to be enclosed in double quotes:

区分大小写的 SQL 标识符需要用双引号括起来:

DROP DATABASE  "Ajp";

Not sure if they are properly preserved on Windows if you pass them through the commandline though.

如果您通过命令行传递它们,则不确定它们是否在 Windows 上正确保存。

You might need to put that into a SQL script and pass the script name to psql.

您可能需要将其放入 SQL 脚本并将脚本名称传递给 psql。

For details on valid identifiers please see the manual: http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

有关有效标识符的详细信息,请参阅手册:http: //www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS