Liquid Fire Posted September 18, 2008 Share Posted September 18, 2008 Is there a program that can tell me that when i pass it a string that if the SQL syntax is correct as if all the database, tables, and fields in the queries existed for PostgreSQL? Quote Link to comment https://forums.phpfreaks.com/topic/124738-syntax-checker/ Share on other sites More sharing options...
btherl Posted September 18, 2008 Share Posted September 18, 2008 You can execute "EXPLAIN query" in postgresql. If it succeeds then your query is valid. For example: EXPLAIN SELECT * FROM table Quote Link to comment https://forums.phpfreaks.com/topic/124738-syntax-checker/#findComment-644330 Share on other sites More sharing options...
Liquid Fire Posted September 18, 2008 Author Share Posted September 18, 2008 will it run even if the tables, databases, and fields don't exist? I just want something to test syntax. Quote Link to comment https://forums.phpfreaks.com/topic/124738-syntax-checker/#findComment-644334 Share on other sites More sharing options...
btherl Posted September 18, 2008 Share Posted September 18, 2008 No it will only run if the query is a valid query. What it does is asks postgres to plan the query, but not to execute it. If there's a problem with the query then postgres can't plan it, and it'll give an error (pg_query() will return false). If the query is valid then you'll get a result back with some text describing how postgres would execute that query. Quote Link to comment https://forums.phpfreaks.com/topic/124738-syntax-checker/#findComment-644370 Share on other sites More sharing options...
Zane Posted September 18, 2008 Share Posted September 18, 2008 Also, next time don't double/triple post a question in multiple forums please. Quote Link to comment https://forums.phpfreaks.com/topic/124738-syntax-checker/#findComment-644384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.