Both keywords and identifier names in PostgreSQL have a maximum length limit of 31 characters. Parsed keywords or identifiers over that length limit are automatically truncated. Identifiers may begin with any letter (a through z), and may then be followed by letters, numbers (0 through 9), or underscores. While keywords are not permitted to start or end with an underscore, identifier names are . Neither keywords nor identifiers should ever begin with a number.

the section called When quotes are required described how quoted identifiers could be used to "over-rule" the case insensitivity of identifiers by placing quotes around them. The same rule-bending can apply to the assertion that an identifier cannot begin with a number. While PostgreSQL will not allow you to create a table called 1st_bent_rule , it will allow you to quote this identifier in order to create it.

Example 3-3 first fails in trying to create an illegaly named table. It then proceeds to bend the rules with quotes.

Example 3-3. Bending Rules

booktown=# CREATE TABLE 1st_bent_rule (rule_name text);
ERROR:  parser: parse error at or near "1"
booktown=# CREATE TABLE "1st_bent_rule" (rule_name text);
CREATE

Furthermore, while quotes themselves are of course not allowed within the set of quotes to refer to a table name, other normally illegal characters are allowed, such as spaces (" ") and ampersands ("&"). Take note that while the ANSI/ISO SQL standard forbids using identifiers with the same names as SQL keywords, PostgreSQL (like many other SQL implementations) has a similarly relaxed view on this, allowing you to force certain conditions with quoted identifiers.

Remember that while these can be useful tricks to know for unusual circumstances, if you wish to design portable, standard SQL statements and relations, it is best to adhere to the standards put forth whenever possible.