Forge
Forge

Reputation: 1677

Postgres create view as not a view

Maintaining code from a former employee found a piece of SQL i cannot understand:

CREATE OR REPLACE VIEW my_view AS Not a view

There's no info on official documentation and I've beenseeking for information on this query but to no avail.

any hint?

Upvotes: 3

Views: 2208

Answers (1)

klin
klin

Reputation: 121604

The view was deleted.

Your script was generated by an application which uses pg_get_viewdef(view_oid). When there is no a view with a given oid then the function returns the string not a view. Simple test:

create view my_view as select 1;

select oid 
from pg_class 
where relname = 'my_view';

  oid   
--------
 151388
(1 row)

select pg_get_viewdef(151388);

 pg_get_viewdef 
----------------
  SELECT 1;
(1 row)

drop view my_view;

select pg_get_viewdef(151388);

 pg_get_viewdef 
----------------
 Not a view
(1 row) 

Note that it does not mean that my_view does not exist. If you recreate the view it'll have another oid. The only certain conclusion is that your script is not up-to-date (It's inconsistent with the current content of the database). As a remedy you should dump the schema in SQL format, e.g.

pg_dump --schema-only --format=plain my_database > my_database.dump

Upvotes: 3

Related Questions