pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Julius de Bruijn <bruijn@prisma.io>
To: pgsql-general@lists.postgresql.org
Subject: Re: How are the SELECT queries reconstructed in pg_views
Date: Tue, 28 Mar 2023 13:26:17 -0700
Message-ID: <abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com> (raw)
In-Reply-To: <73b0f3b2-819d-4cb3-6101-cd02c033da5e@aklaver.com>
References: <25b7f08f-1a5d-669a-1678-9def044df0bf@prisma.io>
	<73b0f3b2-819d-4cb3-6101-cd02c033da5e@aklaver.com>

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






view thread (3+ messages)

Message-ID: <abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com>
Permalink:  ../abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com/
Also on:    postgresql.org/message-id/abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com

 · 

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: adrian.klaver@aklaver.com, bruijn@prisma.io
  Subject: Re: How are the SELECT queries reconstructed in pg_views
  In-Reply-To: <abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com>
  References: <25b7f08f-1a5d-669a-1678-9def044df0bf@prisma.io> <73b0f3b2-819d-4cb3-6101-cd02c033da5e@aklaver.com> <abf8a3e5-570c-84a1-dda6-491bd288e3d6@aklaver.com>

* 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