Thread: 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/
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
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
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/
> -----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