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.

asked 23 Feb '15, 05:24

tzup's gravatar image

tzup
360121526
accept rate: 0%

3

Also consider SQLDIALECT(), WATCOMSQL(), TRANSACTSQL(), REWRITE() and SQLFLAGGER().

(23 Feb '15, 06:22) Breck Carter
Replies hidden
2

"DBISQL -x" might also help...

(23 Feb '15, 06:45) Volker Barth
3

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:

GRANT SELECTX ON products for MyUser;

whereas they will not check whether "products" or "MyUser" actually do exist.

(24 Feb '15, 03:49) Volker Barth
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×29

question asked: 23 Feb '15, 05:24

question was seen: 2,690 times

last updated: 24 Feb '15, 03:53