问题描述:

I am using Postgres Version 9.1 and am having some trouble reviewing past VIEWS that I have created.

Once I create a VIEW, Postgres jumbles up the CREATE VIEW text so it is very unreadable.

For instance, I might create a simple VIEW as:

create view some_view as

select *

from some_table

where some_column = 'some_value';

This then turns into something way more complicated as:

select [all columns...]

from some_table

where (((some_column = 'some_value')));

Now, this is a simple example - however when you get into multiple JOINS and WHERE clauses or SUBQUERIES it gets nearly impossible to read so as to edit the VIEW at a later date.

(The exact location the VIEWS are stored is in information_schema.pg_views if anybody cares to look.)

For that reason I save my CREATE VIEW scripts as a separate .sql file, however this can get taxing and is obviously has the liability of not being sync'd with the current VIEW in the Postgres Database (if you update the VIEW but don't update the .sql file for instance).

It would be MUCH more simple if the plain text of the CREATE VIEW was saved.

When I create a FUNCTION, it saves the script entirely as is with all white-space, etc.

This makes it very simple, at a later date, to review it and see if it needs to be fixed up or spot possible errors.

So my question is if there is some place in the Postgres database where the actual plain-text is saved of the CREATE VIEW statement for later review/editing.

Thank you.

网友答案:

As found, the correct answer is to:

a) Maintain your SQL Scripts in separate files
b) Have a proper versioning system (Git, etc.)
c) Deploy from the versioning system

Done Deal.

相关阅读:
Top