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 1kztns-0002q7-Vl for pgsql-general@arkaria.postgresql.org; Thu, 14 Jan 2021 04:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kztnq-0004oR-4n for pgsql-general@arkaria.postgresql.org; Thu, 14 Jan 2021 04:00:06 +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 1kztnp-0004o9-PJ for pgsql-general@lists.postgresql.org; Thu, 14 Jan 2021 04:00:05 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kztni-0000wL-GH for pgsql-general@lists.postgresql.org; Thu, 14 Jan 2021 04:00:04 +0000 Received: by mail-ej1-x631.google.com with SMTP id ga15so6255841ejb.4 for ; Wed, 13 Jan 2021 19:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=CA4+A3LK4HxjjZkGXmAhOEZcsoWEyuRwDJlYuxS2A68=; b=o2Ua3hbe57VP6zmOnHq5z0mmm2bGQsVmglVvyjxn1hsApPrkQHCuL3IOic9EilTBaj 9JcP9N3NFb7pUD5XbXHZppuAhH721mbvDsmZieZUmvPZ4BDEFsXyJEWrc7F3Fgwzdofz 4YIMaB2F9E09D9DXZXceTMgAPq38x4r35G04IkmE0nBbZc1Od0gElRhM1OivBQryEtCT jRXebTTfxYPIdffFGdG8D8lJTLxskKWX7uyelf1bPcHRhz3Z1znsq6MbBoBxZQVxd4IA /xU+ybY21jU2rtpBCredyrLDAbRmWkQBvwwb5wwU1zWnfIHakJxXvuuhbOZmqpo0s+Ub LmJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=CA4+A3LK4HxjjZkGXmAhOEZcsoWEyuRwDJlYuxS2A68=; b=RB/8w1+O8Qw1xyKe9MDI1vSjM2PtOMvz0dgLPnr5ZxByX82t2SlAcrS+icYL7YZXYH g+PanLdrhFX/jvrfPhDKt2EluFUd83H6N3BbRWxbIM1lF2Kjj/dSt7O6alPih+VQXS9O RiaKvavimd9WJz5ht2y6TkpDZulzXompoEKl9dJ0eLou0Mrok1YKUPV9Ee4tTqCdrMZz D2iKoi0E4fyJ9Bj1clVcgPwLiTkGWx3+Pr4bYh+XnugLGWGlX0ceQx9wssvh3B6Y8siZ BCOo3oqOfQMaAlk4DB4gAE6mRbQDxPOUesbGPvv0T3qsF3tL4q5miB+LCRlOPmo0fM46 et6Q== X-Gm-Message-State: AOAM53096OwhLchWZevjcY6SkazgzwvW2XAP2QKyFtyBou4joYfuUpnV tyTyuUfrzzOJ11loe7UXW5wYRw== X-Google-Smtp-Source: ABdhPJz9GOiEXMXFYDvxuvcih8Udb4+xyfTCcj0pbeDPVP+3KIMC6Pb8T+qsvBS9pF7EZzeN9l7q+w== X-Received: by 2002:a17:906:cc9c:: with SMTP id oq28mr3832893ejb.224.1610596795443; Wed, 13 Jan 2021 19:59:55 -0800 (PST) Received: from localhost.localdomain (91-115-150-95.adsl.highway.telekom.at. [91.115.150.95]) by smtp.gmail.com with ESMTPSA id w17sm1465916ejk.124.2021.01.13.19.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 19:59:54 -0800 (PST) Message-ID: <05bbb83f4efe2eb860c701e77557c7cc6c9356fa.camel@cybertec.at> Subject: Re: How to keep format of views source code as entered? From: Laurenz Albe To: Adam Brusselback , "David G. Johnston" Cc: raf , "pgsql-generallists.postgresql.org" Date: Thu, 14 Jan 2021 04:59:53 +0100 In-Reply-To: References: <20210107233813.zjat7zmdfxqapjvv@raf.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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