1

How to check if provided string is a valid name in postgres ? I know that it is possible to use any string as name when it is quoted, but I want to know is string can be used without quotes i.e. as role name. I have idea to do it like this: BEGIN; CREATE ROLE ; ROLLBACK; Is is good idea ?

1 Answer 1

5

You can use the function quote_ident() which will quote a string only if necessary.

So if the "quoted" value is the same as the input, it's a legal identifier:

select quote_ident('foobar') = 'foobar'

returns true, however

select quote_ident('foo bar') = 'foo bar'

returns false.

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

Comments

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.