简体   繁体   中英

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?

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, eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM