The forum is currently being migrated to a new host. While the migration happens, the old server is still available. Once the new machine is ready, I will copy the database to the new machine. Feel free to ask and answer questions in the meantime.

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

accept rate: 0%



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

"DBISQL -x" might also help...

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

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 23 Feb '15, 05:24

question was seen: 2,390 times

last updated: 24 Feb '15, 03:53