Search Postgresql Archives

Re: How to keep format of views source code as entered?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2021-01-13 at 20:39 -0500, Adam Brusselback wrote:
> > Admittedly, the system probably should be made to save the text, should someone wish to write such a patch. 
> 
> It has been a major annoyance for views with complex subqueries or where clauses, the PG representation is absolutely unreadable.

This is not going to happen, and I dare say that such a patch would be rejected.

Since PostgreSQL stores view definitions in their parsed form, the query does
not contain the name of the used objects, but only their object ID.

This allows you for example to rename the underlying objects, because that
does not change the object ID:

CREATE TABLE t (id integer);

CREATE VIEW v AS SELECT * FROM t;

\d+ v
[...]
View definition:
 SELECT t.id
   FROM t;

ALTER TABLE t RENAME TO quaxi;

\d+ v
[...]
View definition:
 SELECT quaxi.id
   FROM quaxi;

If PostgreSQL were to store the original text, either that text would become
wrong, or you would have to forbid renaming of anything that is referenced
by a view.

A database is no source versioning system.  The next thing someone will request
is that the original CREATE TABLE or CREATE INDEX statements should be preserved.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux