1

I want to permissions to a user named foo-bar in PostgreSQL (the key is that the username has a minus '-' in it). However, when I use GRANT ALL PRIVILEGES ON DATABASE baz TO foo-bar, postgres complains about the minus character being invalid syntax. I figured that made sense, I just needed to use a string literal or escape the minus. However, trying the double dollar sign literal syntax here and prepending an E as suggested here didn't work (presumably because the username isn't considered a string here).

So that begs the question, how does one refer to a user in postgres if the user has a minus in their name?

1 Answer 1

5
GRANT ALL PRIVILEGES ON DATABASE baz TO "foo-bar"

should work

Sign up to request clarification or add additional context in comments.

2 Comments

Well, now I feel silly. I tried single quotes and it complained about that, but apparently forgot double quotes.
@codeCogs don't feel silly. 7 years later and I did the same thing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.