gpt4 book ai didi

PostgreSQL - 删除名称中带有正斜杠的数据库

转载 作者:行者123 更新时间:2023-11-29 12:06:15 24 4
gpt4 key购买 nike

在我的 Ruby-on-Rails database.yml 文件中,我不小心创建了一个名称中带有正斜杠 (/) 的 PostgreSQL 数据库。

我一直无法通过 psql 命令删除这个数据库,尝试了各种转义序列。

最佳答案

用引号将您的数据库名称引起来:

DROP DATABASE "database/withslash";

来自Identifiers and Keywords文档:

There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named "select", whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected. The example can be written with quoted identifiers like this:

UPDATE "my_table" SET "a" = 5;

Quoted identifiers can contain any character, except the character with code zero.

请注意,引用的标识符区分大小写。

虽然连接 数据库时您不能删除该数据库,所以也许您想使用命令行 dropdb command .您的 shell 将解析引号,因此您想转义引号:

dropdb \"database/withslash\"

关于PostgreSQL - 删除名称中带有正斜杠的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12442625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com