Re: How to keep format of views source code as entered? - Mailing list pgsql-general

From Laurenz Albe
Subject Re: How to keep format of views source code as entered?
Date
Msg-id 05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at
Whole thread Raw
In response to Re: How to keep format of views source code as entered?  (Adam Brusselback <adambrusselback@gmail.com>)
Responses Re: How to keep format of views source code as entered?
List pgsql-general
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




pgsql-general by date:

Previous
From: Adam Brusselback
Date:
Subject: Re: How to keep format of views source code as entered?
Next
From: "David G. Johnston"
Date:
Subject: Re: How to keep format of views source code as entered?