PostgreSQL syntax check without running the query

前端 未结 8 1815
时光取名叫无心
时光取名叫无心 2020-12-24 05:03

I want to verify the syntax of files containing sql queries before they can be committed in my CVS project.

In order to do that, I have a commitinfo script, but I h

相关标签:
8条回答
  • 2020-12-24 05:53

    A wonderful utility to verify SQL syntax: SQL Fiddle

    Supports MySQL, Oracle, PostgreSQL, SQLite, MS SQL.

    0 讨论(0)
  • 2020-12-24 05:54

    I recently wrote up a utility to statically check the syntax of SQL for PostgreSQL. It leverages ecpg, the embedded SQL C preproccessor for postgres, to check the SQL syntax, so it uses the exact same parser that is built in to Postgres itself.

    You can check it out on github: http://github.com/markdrago/pgsanity. You can give the README a skim to get a better idea of how it works and to get directions for how to install it. Here's a short example of how pgsanity can be used:

    $ pgsanity good1.sql good2.sql bad.sql
    bad.sql: line 1: ERROR: syntax error at or near "bogus_token"
    
    $ find -name '*.sql' | xargs pgsanity
    ./sql/bad1.sql: line 59: ERROR: syntax error at or near ";"
    ./sql/bad2.sql: line 41: ERROR: syntax error at or near "insert"
    ./sql/bad3.sql: line 57: ERROR: syntax error at or near "update"
    
    0 讨论(0)
提交回复
热议问题