SQL PostgreSQL 中连字符 (-) 的转义序列是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3942759/
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
what's the escape sequence for hyphen (-) in PostgreSQL
提问by Shamal Karunarathne
I'm trying to rename a database to a name with a hyphen (-).
我正在尝试将数据库重命名为带有连字符 (-) 的名称。
ALTER DATABASE one RENAME TO one-two;
And psql returns an error:
并且 psql 返回错误:
ERROR: syntax error at or near "-"
What should I use as an escape sequence for "-" character or what's the way to do the above?
我应该使用什么作为“-”字符的转义序列或执行上述操作的方法是什么?
Note: I've tried the '\-' and didn't work as well.
注意:我试过 '\-' 并且效果不佳。
Thanks.
谢谢。
回答by Joe Stefanelli
Double quotes should do it. But you'll have to always use the quoted-identifier everywhere you reference the database.
双引号应该这样做。但是您必须始终在引用数据库的任何地方使用带引号的标识符。
ALTER DATABASE one RENAME TO "one-two";