pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Adam Brusselback <adambrusselback@gmail.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: raf <raf@raf.org>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to keep format of views source code as entered?
Date: Thu, 14 Jan 2021 04:59:53 +0100
Message-ID: <05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at> (raw)
In-Reply-To: <CAMjNa7dOD93jbf-zBohFUu=R6s=Qez-KrEMnH8tqmgL4ZA+Z7Q@mail.gmail.com>
References: <d082c7257ff647e9aba17790938e92de@MS-FRA-E13EX02.intl.ad.vzwcorp.com>
	<b91237db66a5419cac100fd2100f7cb0@MS-FRA-E13EX02.intl.ad.vzwcorp.com>
	<20210107233813.zjat7zmdfxqapjvv@raf.org>
	<CAKFQuwasSDMoW1A5uWVu9jm3YgG6FHuNCfvgR2OGn=BPjY=_+Q@mail.gmail.com>
	<CAMjNa7dOD93jbf-zBohFUu=R6s=Qez-KrEMnH8tqmgL4ZA+Z7Q@mail.gmail.com>

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






view thread (31+ messages)  latest in thread

Message-ID: <05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at>
Permalink:  ../05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at/
Also on:    postgresql.org/message-id/05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, adambrusselback@gmail.com, david.g.johnston@gmail.com, raf@raf.org
  Subject: Re: How to keep format of views source code as entered?
  In-Reply-To: <05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at>
  References: <d082c7257ff647e9aba17790938e92de@MS-FRA-E13EX02.intl.ad.vzwcorp.com> <b91237db66a5419cac100fd2100f7cb0@MS-FRA-E13EX02.intl.ad.vzwcorp.com> <20210107233813.zjat7zmdfxqapjvv@raf.org> <CAKFQuwasSDMoW1A5uWVu9jm3YgG6FHuNCfvgR2OGn=BPjY=_+Q@mail.gmail.com> <CAMjNa7dOD93jbf-zBohFUu=R6s=Qez-KrEMnH8tqmgL4ZA+Z7Q@mail.gmail.com> <05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox