-1

I have the following SQL code but it's not working, it says syntax error:

EXPLAIN
DROP TABLE cool_table

Does anyone know why?

I wrote this question because I was taught to always use EXPLAIN before running a query on the database to avoid running a task that's too much for the database processing, no one told me about don't use EXPLAIN before DROP. Then I had this question about why is EXPLAIN not working with the DROP.

halfer
  • 19,824
  • 17
  • 99
  • 186
Kevin Zhao
  • 2,113
  • 2
  • 14
  • 18

2 Answers2

2

It should not work - DDL statements has no plan - so EXPLAIN has nothing to show.

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94
  • that's not exactly true. A `create table .. as select ...` is DDL as well and _does_ have an execution plan. –  May 31 '15 at 12:35
  • But what is CREATE TABLE AS SELECT ? DDL or SELECT? – Pavel Stehule May 31 '15 at 14:38
  • Clearly DDL as it creates a new table. –  May 31 '15 at 14:56
  • ok, I this is exception due strange nature of this statement. For me CREATE AS SELECT is two statements in one box - CREATE TABLE and INSERT INTO SELECT - but this topis is not too much important – Pavel Stehule May 31 '15 at 15:04
0

As it turns out, you can't put EXPLAIN before a DROP statement in Postgresql...

Use EXPLAIN not with DROP but other statements

Kevin Zhao
  • 2,113
  • 2
  • 14
  • 18