0

In Oracle we have

select dbms_assert.simple_sql_name(TEST) from dual

what will be the equivalent in postgresql ? I can't seem to find anywhere the answer.

If column is wrong in Oracle we get:

 ORA-44003: invalid SQL name ORA-06512: at "SYS.DBMS_ASSERT", line 160
 44003. 0000 -  "invalid SQL name"
 *Document: Yes
 *Cause:    The input parameter string was not a valid simple SQL name.
 *Action:   Check with the DBMS_ASSERT spec to verify that the parameter
            string is a valid simple SQL name.
1
  • You can easily write such a function yourself using the specification from the documentation. Commented Dec 13, 2017 at 15:31

1 Answer 1

3

Not exactly the same thing, but an "illegal" identifier has to be quoted in Postgres (and SQL). The function format() has a special place holder for identifiers and will return a quoted identifier if anything is non-standard:

So select format('%I', 'foo') returns foo.

But select format('%I', 'foo bar') returns "foo bar"

So if you check that the return value is quoted (starts with a ") then it's not a valid identifier.

This also checks for reserved keywords, so select format('%I', 'order') returns "order"

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.