当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to test an SQL statement without executing it

问题描述:

I have a SQL statement in a string, and I want to try it but without being executed.

In other words, I want to ensure that when executed later in my database return something, even a null.

SQL statements to try are queries (select). I'm using PHP with postgresql.

网友答案:

explain is used to show the execution plan. When issued without the analyze option it will not be executed:

=> explain select 1;
                QUERY PLAN                
------------------------------------------
 Result  (cost=0.00..0.01 rows=1 width=0)
(1 row)

=> explain select x;
ERROR:  column "x" does not exist
LINE 1: explain select x;

http://www.postgresql.org/docs/current/static/sql-explain.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: