3

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?

4
  • 1
    I've never seen this before, will be cool to see the answer here. Just upvote this question. Commented Apr 17, 2017 at 11:49
  • Are you sure this is SQL? Can you show more of the surrounding code? Commented Apr 17, 2017 at 11:51
  • 4
    This looks like it is intentionally trying to generate an error. Commented Apr 17, 2017 at 11:52
  • This fails on sqlfiddle sqlfiddle.com/#!15/5b08e1/1 Commented Apr 17, 2017 at 12:10

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.