query to get the list of key (reserverd) words?

Started by Bill Moranover 14 years ago5 messagesgeneral
Jump to latest
#1Bill Moran
wmoran@potentialtech.com

I'm in the unenviable position of needing to check various input to
ensure that it doesn't contain any PostgreSQL/SQL key words/reserved
words.

The initial implementation simply made a copy of this table:
http://www.postgresql.org/docs/8.3/static/sql-keywords-appendix.html#KEYWORDS-TABLE
into a static array in the code. Obviously, this is non-optimal
because it becomes a manual chore to ensure the list is up to date
any time new PG releases are made.

Is there a pg_* or other table in the database that I can query for this
list? Or some other automated method that can be employed?

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

In reply to: Bill Moran (#1)
Re: query to get the list of key (reserverd) words?

On 4 August 2011 13:53, Bill Moran <wmoran@potentialtech.com> wrote:

Is there a pg_* or other table in the database that I can query for this
list?  Or some other automated method that can be employed?

All keywords are listed in src/backend/parser/gram.y:

/* ordinary key words in alphabetical order */
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION

BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BY

*** SNIP ***

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bill Moran (#1)
Re: query to get the list of key (reserverd) words?

Bill Moran <wmoran@potentialtech.com> writes:

Is there a pg_* or other table in the database that I can query for this
list? Or some other automated method that can be employed?

In recent versions, "select * from pg_get_keywords()"

regards, tom lane

#4Bill Moran
wmoran@potentialtech.com
In reply to: Tom Lane (#3)
Re: query to get the list of key (reserverd) words?

In response to Tom Lane <tgl@sss.pgh.pa.us>:

Bill Moran <wmoran@potentialtech.com> writes:

Is there a pg_* or other table in the database that I can query for this
list? Or some other automated method that can be employed?

In recent versions, "select * from pg_get_keywords()"

That's fantastic ... exactly what I needed to make this easy! Thanks.

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

#5Igor Neyman
ineyman@perceptron.com
In reply to: Bill Moran (#1)
Re: query to get the list of key (reserverd) words?

-----Original Message-----
From: Bill Moran [mailto:wmoran@potentialtech.com]
Sent: Thursday, August 04, 2011 8:53 AM
To: pgsql-general@postgresql.org
Subject: query to get the list of key (reserverd) words?

I'm in the unenviable position of needing to check various input to
ensure that it doesn't contain any PostgreSQL/SQL key words/reserved
words.

The initial implementation simply made a copy of this table:
http://www.postgresql.org/docs/8.3/static/sql-keywords-
appendix.html#KEYWORDS-TABLE
into a static array in the code. Obviously, this is non-optimal
because it becomes a manual chore to ensure the list is up to date
any time new PG releases are made.

Is there a pg_* or other table in the database that I can query for
this
list? Or some other automated method that can be employed?

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

Use pg_get_keywords(OUT word text, OUT catcode "char", OUT catdesc text)

Regards,
Igor Neyman