checking SQL statement/subexpression validity - Mailing list pgsql-general

From David Garamond
Subject checking SQL statement/subexpression validity
Date
Msg-id 42097BB3.2080907@zara.6.isreserved.com
Whole thread Raw
Responses Re: checking SQL statement/subexpression validity  (Mike Nolan <nolan@gw.tssi.com>)
List pgsql-general
I need to check whether a SQL subexpression (to be used in WHERE
clause), e.g.:

  colname > 200

or an entire SELECT statement, e.g.:

  SELECT * FROM t1, t2 WHERE colname > 200

is syntactically valid. Is there a quick (and also safe) way to do this?
I'm thinking of doing "SELECT ... FROM ... WHERE <SQLexpr> LIMIT 0" for
#1, but I'm not sure if it's 100% safe; and I don't know what to do with
#2. AFAIK, in, say, Perl's DBI, $dbh->prepare() doesn't check SQL syntax
and $sth->execute() actually executes the statement.

--
dave

pgsql-general by date:

Previous
From: Art Fore
Date:
Subject: Database permissions
Next
From: "Rick Schumeyer"
Date:
Subject: how to delete from a view