Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxofT-0000Or-Ai for pgsql-general@arkaria.postgresql.org; Fri, 08 Jan 2021 10:06:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kxofS-00023o-9J for pgsql-general@arkaria.postgresql.org; Fri, 08 Jan 2021 10:06:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxofR-00023h-O8 for pgsql-general@lists.postgresql.org; Fri, 08 Jan 2021 10:06:49 +0000 Received: from loire.is.ed.ac.uk ([129.215.16.10]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kxofJ-0003VO-Q2 for pgsql-general@lists.postgresql.org; Fri, 08 Jan 2021 10:06:48 +0000 Received: from beeknow.inf.ed.ac.uk (beeknow.inf.ed.ac.uk [129.215.202.44]) by loire.is.ed.ac.uk (8.14.7/8.14.7) with ESMTP id 108A6bXk002635 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 8 Jan 2021 10:06:37 GMT Received: from corona.lan (tcolles.plus.com [84.92.122.245]) (authenticated bits=0) by beeknow.inf.ed.ac.uk (8.14.7/8.14.7) with ESMTP id 108A6Y8W019089 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 8 Jan 2021 10:06:36 GMT Date: Fri, 8 Jan 2021 10:06:32 +0000 (GMT) From: Tim.Colles@ed.ac.uk Sender: timc@corona To: Karsten Hilbert cc: pgsql-general@lists.postgresql.org Subject: Re: How to keep format of views source code as entered? In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed X-Edinburgh-Scanned: at loire.is.ed.ac.uk Content-Transfer-Encoding: 8BIT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 8 Jan 2021, Karsten Hilbert wrote: > Am Fri, Jan 08, 2021 at 08:38:29AM +0000 schrieb Markhof, Ingolf: > >> I am really surprised that PostgreSQL is unable to keep the >> source text of a view. Honestly, for me the looks like an >> implementation gap. Consider software development. You are >> writing code in C++ maybe on a UNIX host. And whenever you >> feed you source code into the compiler, it will delete it, >> keeping the resulting executable, only. > > You expect the compiler to keep your source code for you ? > > Most certainly, PostgreSQL does not delete your view source > code, just as the compiler does. > > I am not so sure that analogy holds up. > The SQL-92 standard requires the source text of a view to be held in order to provide the "information_schema" "view definition" column which "contains a representation of the view descriptors” - to me though it is open to interpretation what that actually means. MariaDB, like PostgreSQL, does not not store an exact copy of the view source either. The SQL-92 standard is completely explicit about column expansion: “NOTE 13: Any implicit column references that were contained in the associated with the are replaced by explicit column references in VIEW_DEFINITION.” - so any view definition that is stored, solely for the purposes of standard compliance, will at a minimum have to differ from the original source if the source had any implicit column references (and by association table references as well I assume). Arguably if PostgreSQL held an exact copy of the view definition (except for alterations under Note 13 above) then it should also store exact copies of other pre-parsed objects, such as DEFAULT on table columns and WITH on trigger clauses, in order to be useful under the OP's context. See also: http://www.postgresql-archive.org/idea-storing-view-source-in-system-catalogs-td1987401.html http://www.postgresql-archive.org/Preserving-the-source-code-of-views-td5775163.html -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.