Skip site navigation (1) Skip section navigation (2)

Re: Reserved words and delimited identifiers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Joe Abbate <jma(at)freedomcircle(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reserved words and delimited identifiers
Date: 2011-11-30 04:41:30
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Tue, Nov 29, 2011 at 7:29 PM, Joe Abbate <jma(at)freedomcircle(dot)com> wrote:
>> It seems to me that since a TYPE in a column definition or function
>> argument can be a non-native TYPE, it could be a reserved word and
>> therefore it should always be allowable to quote the TYPE.  Can someone
>> please explain why that is not the case?

> Type names as they appear in pg_type.typname can always be quoted.
> But some types, like int4, have alternate names - e.g. int4 can be
> specified as integer or int, and foat8 can be specified using the
> two-word phrase double precision.  These alternate names are keywords
> when unquoted, but identifiers (with a different meaning) when quoted.

Another way to say that is that the type int4 can be specified in two

	int4		(an identifier)
	INTEGER		(a keyword)

Quoting "int4" is no problem, because it's still an identifier, but
quoting "integer" takes away its keyword nature, so it doesn't get

The fact that INTEGER is a keyword, and not an identifier, is per SQL
specification.  We could perhaps hack things so that "integer" as an
identifier would also work, but I doubt that we'd go so far as to make
"INTEGER" (a different identifier) also work, and we'd certainly not
be able to do much about the spec's more exciting deviations from
identifier-looking type names, such as CHARACTER VARYING or DOUBLE

Or to put it more pithily: the SQL committee's ideas of good syntax
seem to have been frozen around the time COBOL was invented.

			regards, tom lane

In response to


pgsql-hackers by date

Next:From: Robert HaasDate: 2011-11-30 04:42:10
Subject: Re: ALTER TABLE lock strength reduction patch is unsafe
Previous:From: Joe AbbateDate: 2011-11-30 04:21:59
Subject: Re: Reserved words and delimited identifiers

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group