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 1phFtj-0005LY-P0 for pgsql-general@arkaria.postgresql.org; Tue, 28 Mar 2023 20:26:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phFti-0006pn-JW for pgsql-general@arkaria.postgresql.org; Tue, 28 Mar 2023 20:26:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phFti-0006pd-8A for pgsql-general@lists.postgresql.org; Tue, 28 Mar 2023 20:26:26 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phFtg-0002gL-As for pgsql-general@lists.postgresql.org; Tue, 28 Mar 2023 20:26:25 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3A9AC5C0067; Tue, 28 Mar 2023 16:26:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 28 Mar 2023 16:26:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1680035183; x=1680121583; bh=lGgvGJXVtu25aZeLRhtYnNDpJ+E1pcWFS99 hqQg5DnM=; b=ZmRUnNZA1Kzmj2GqdOyezN6/+vwY/Y/kn2mMqJH3L2ONwjRDIXT uNHGxWerw9rrblSUfRWUgyFPMbQshjRr9NJNsj1zlpuBK+3yfgkAnrEWnnSdX6Bi iCgnP0Krqq9ipBf/TuktIgp3CoZGw8BbBny+8GZ+BW8EQ2jnGoIc7zfM/2GTgNYh 4d+NkDnXYxY8LD3Q3NkqbNSaHlLrOpYFYshIc9nTX/WQRhsC9Xtq38+BqhXLET/g BI+GL09Huw3Ar2xuw/4+fm15DFxMqwERJ/rOBwuNm7RSFdT4ulS57Hxa0pcQtXPe ZETFbnTWI9mzllVYm9OoUfYIn7ucOleEXjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1680035183; x= 1680121583; bh=lGgvGJXVtu25aZeLRhtYnNDpJ+E1pcWFS99hqQg5DnM=; b=o 9nHjV1f0d9SJL5jMq9seYxdkI66OXFV5KQvongzA9DZOIUqld5XmK8NMvfuLHxqC SVi+TfdsKpDMLvc2+Se+94Bfq7Pwgju0LYjzpQI5eFTYz+Y9E/y/jnRrPzLDM7bh JNmAPhoXN+GZEj+4GZrIYqXvxjgmAaVtWczAVgdXSBVtu2xPO1G4CVI/ubqibp9T 9arw/czwSTmjw+aEu6klEx8dZk3ByHPQtqjrnB5/tHV8/se8Po2OZVBaS07744zK xOmc6u4umCIxCzAuZnPydr/vzMC0vLoRG6MRwmTYwI8CA1PD5RCF/l2eT131kzE6 duifqUHHY/WZQpbQUu9AA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehgedgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuhffvfhgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepleejvdelgfelgeejgeejiefhtdejhfehgeeghedv jeejffefvefhffdtgefhffejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Mar 2023 16:26:20 -0400 (EDT) Message-ID: Date: Tue, 28 Mar 2023 13:26:17 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: How are the SELECT queries reconstructed in pg_views Content-Language: en-US From: Adrian Klaver To: Julius de Bruijn , pgsql-general@lists.postgresql.org References: <25b7f08f-1a5d-669a-1678-9def044df0bf@prisma.io> <73b0f3b2-819d-4cb3-6101-cd02c033da5e@aklaver.com> In-Reply-To: <73b0f3b2-819d-4cb3-6101-cd02c033da5e@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/28/23 13:23, Adrian Klaver wrote: > On 3/28/23 06:43, Julius de Bruijn wrote: >> Hi, >> I haven't been able to find exactly what changes PostgreSQL does when >> reconstructing the query, but I've successfully been able to create >> views where the resulting query differs from what I wrote. Is there >> any documentation for this feature where I can learn more about what >> happens before the query is stringified to the information schema? Or, >> even better, is there a way for me to send a query to the database and >> as a result get back a reconstructed query? > > I should have added I got pg_get_viewdef() from the below : \d+ information_schema.views ... CASE WHEN pg_has_role(c.relowner, 'USAGE'::text) THEN pg_get_viewdef(c.oid) ELSE NULL::text END::information_schema.character_data AS view_definition, ... > SELECT pg_catalog.pg_get_viewdef('61822'::pg_catalog.oid, true); >          pg_get_viewdef > -------------------------------- >   SELECT up_test.id AS up_id,  + >      up_test.col_1 AS bool_col,+ >      up_test.col_2 AS col2     + >     FROM up_test; > -- Adrian Klaver adrian.klaver@aklaver.com