Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
837 views
Welcome To Ask or Share your Answers For Others

1 Answer

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";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...