pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Pete O'Such <posuch@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Unqualified relations in views
Date: Wed, 13 Sep 2023 08:11:03 +0200
Message-ID: <ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.camel@cybertec.at> (raw)
In-Reply-To: <CAEdngj_Z6mQa3qvcmUm6wwg1_dMvPtSt1Tr3PpxW2WNRzQ8haw@mail.gmail.com>
References: <CAEdngj_Z6mQa3qvcmUm6wwg1_dMvPtSt1Tr3PpxW2WNRzQ8haw@mail.gmail.com>

On Wed, 2023-09-13 at 01:58 -0400, Pete O'Such wrote:
> For a view, how does one show what schema was used to qualify a relation, when
> the query used to create the view originally left the relation unqualified?
> 
> The qualification of the view query seems static in all uses of the view.
> Using pg_get_viewdef() returns the unqualified relation, but Postgres always
> executes a qualified version of the view query, seemingly determined upon
> creation of the view.
> 
> That implies the final qualifier is stored by Postgres, but I don't know how
> to show it.

PostgreSQL resolves tables and other objects according to the setting of
"search_path" at CREATE VIEW time.  The query itself is stored in parsed form.

pg_get_viewdef() deparses the query and only prepends a schema name if the
schema is not on the "search_path".  So the solution is to set "search_path" empty:

  SET search_path = '';

  SELECT pg_get_viewdef('myschema.myview');

Yours,
Laurenz Albe





view thread (3+ messages)  latest in thread

Message-ID: <ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.camel@cybertec.at>
Permalink:  ../ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.camel@cybertec.at/
Also on:    postgresql.org/message-id/ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.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, posuch@gmail.com
  Subject: Re: Unqualified relations in views
  In-Reply-To: <ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.camel@cybertec.at>
  References: <CAEdngj_Z6mQa3qvcmUm6wwg1_dMvPtSt1Tr3PpxW2WNRzQ8haw@mail.gmail.com> <ff870b3f1993e0ed4ebff0a50ddbc7c717ee8676.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