From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Michael Shapiro <mshapiro51@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: select view definition from pg_views feature request
Date: Tue, 5 Nov 2019 07:01:37 -0800
Message-ID: <a484eebb-49a8-1ce4-99e0-179dc3e6b276@aklaver.com> (raw)
In-Reply-To: <CAGCvxeYArO8-tmFD1MzMP8nuAef25fhphPA6K38k6hV5jpoNEg@mail.gmail.com>
References: <CAGCvxebwiB+b5y_jAj_TLX+S6CoNbVFkmPqc9wTU5FLeNUa5jQ@mail.gmail.com>
<31367.1572815723@sss.pgh.pa.us>
<CAGCvxeYArO8-tmFD1MzMP8nuAef25fhphPA6K38k6hV5jpoNEg@mail.gmail.com>
On 11/5/19 6:43 AM, Michael Shapiro wrote:
> Can I set search_path='' (ie to a string that does not match any
> existing schema)? Would that be the proper way to guarantee that the
> definition for any view will always be fully-qualified?
test=# show search_path;
search_path
------------------------------------------------------------------
public,accounting,history,main,utility,timeclock,table_templates
test=# select * from pg_views where viewname = 'up_view';;
schemaname | viewname | viewowner | definition
------------+----------+-----------+-------------------------------
public | up_view | aklaver | SELECT up_test.id AS up_id, +
| | | up_test.col1 AS bool_col,+
| | | up_test.col_2 AS col2 +
| | | FROM up_test;
(1 row)
test=# set search_path = '';
SET
test=# show search_path;
search_path
-------------
""
(1 row)
test=# select * from pg_views where viewname = 'up_view';;
schemaname | viewname | viewowner | definition
------------+----------+-----------+-------------------------------
public | up_view | aklaver | SELECT up_test.id AS up_id, +
| | | up_test.col1 AS bool_col,+
| | | up_test.col_2 AS col2 +
| | | FROM public.up_test;
(1 row)
>
> On Sun, Nov 3, 2019 at 3:15 PM Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> wrote:
>
> Michael Shapiro <mshapiro51@gmail.com <mailto:mshapiro51@gmail.com>>
> writes:
> > It seems that the definition of a view from pg_catalog.pg_views
> does not
> > qualify the tables used in the view if the tables are in the
> current search
> > path.
>
> > Is it possible to either have the definition always qualify all
> tables
> > independent of the search_path (or else provide a new column that
> does
> > that)?
>
> Why don't you just change the search path to empty before selecting?
>
> regards, tom lane
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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, mshapiro51@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: select view definition from pg_views feature request
In-Reply-To: <a484eebb-49a8-1ce4-99e0-179dc3e6b276@aklaver.com>
References: <CAGCvxebwiB+b5y_jAj_TLX+S6CoNbVFkmPqc9wTU5FLeNUa5jQ@mail.gmail.com> <31367.1572815723@sss.pgh.pa.us> <CAGCvxeYArO8-tmFD1MzMP8nuAef25fhphPA6K38k6hV5jpoNEg@mail.gmail.com> <a484eebb-49a8-1ce4-99e0-179dc3e6b276@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