vitaly-t
vitaly-t

Reputation: 25840

Min length for SQL Name/Identifier in PostgreSQL?

I need to parse an SQL name for PostgreSQL, and to be sure it is always compliant.

I know that, for example, an SQL name/identifier can even consist of a single white space.

What I'm trying to find out is - is there a single use case within the entire PostgreSQL syntax where it is possible to pass in an empty "" SQL name/identifier and still to be considered valid?

I want to know whether I should parse "" as always invalid in PostgreSQL or not.

Upvotes: 0

Views: 374

Answers (1)

fl0cke
fl0cke

Reputation: 2884

An empty quoted identifier is not valid as per the SQL standard. You get the following error message when you try to create a table with "":

ERROR: zero-length delimited identifier at or near """"

And what would it identify anyways? There is no such thing like an identifier that identifies the empty identifier.


You can find out more about the syntax here: http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html

Quoted identifiers can contain any character, except the character with code zero. (To include a double quote, write two double quotes.) This allows constructing table or column names that would otherwise not be possible, such as ones containing spaces or ampersands. The length limitation still applies.

Upvotes: 1

Related Questions