Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL DROP VIEW IF EXISTS

In PostgreSQL when I run the command

DROP VIEW IF EXISTS view_name;

I get the response:

View IF dropped.

Can anyone explain what this means? why the word 'IF' instead of a response like: View view_name dropped ?

like image 522
russellelbert Avatar asked Jul 23 '26 07:07

russellelbert


1 Answers

That's not what PostgreSQL does. Demo:

postgres=# create view view_name as select 1;
CREATE VIEW

postgres=# drop view if exists view_name;
DROP VIEW

postgres=# \echo :SERVER_VERSION_NUM
110002

postgres=# drop view if exists view_name;
NOTICE:  view "view_name" does not exist, skipping
DROP VIEW

Possibly you're not using PostgreSQL proper, but rather a fork that has a different syntax for this operation. Check out the result of SELECT version();.

like image 197
Daniel Vérité Avatar answered Jul 24 '26 23:07

Daniel Vérité



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!