I was thinking that I could use: SELECT PLAN('statement goes here'); If the result is some text, then I know the syntax of the sql statement is valid. Is there a better way of doing such validations? I'm interested solely in validating the syntax correctness of an sql script. |
Also consider SQLDIALECT(), WATCOMSQL(), TRANSACTSQL(), REWRITE() and SQLFLAGGER().
"DBISQL -x" might also help...
It might be added that "select plan()" will only work for SQL statements that generate a plan, i.e. for single queries and DML statements, not for procedure calls or DDL statements. However, it seems to check whether the schema is valid for the statement, so it will notify about misspelled identifiers or non-existing tables/columns. That makes it only partially useful for "syntax-only" validation.
REWRITE() and DBISQL -x in contrast can parse all statements, however, they will only check for syntax errors (as you have asked for). E.g. the following will raise a syntax error:
whereas they will not check whether "products" or "MyUser" actually do exist.