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

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Adam Brusselback <adambrusselback(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: raf <raf(at)raf(dot)org>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to keep format of views source code as entered?
Date: 2021-01-14 03:59:53
Message-ID: 05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-01-14 05:22:58 Re: How to keep format of views source code as entered?
Previous Message Adam Brusselback 2021-01-14 01:39:46 Re: How to keep format of views source code as entered?