pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christophe Pettus <xof@thebuild.com>
To: Celia McInnis <celia.mcinnis@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Erik Wienhold <ewie@ewie.name>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Dropping a temporary view?
Date: Wed, 20 Mar 2024 09:57:11 -0700
Message-ID: <FF099452-FFAF-41D3-B014-77A81216668F@thebuild.com> (raw)
In-Reply-To: <CAGD6t7+vGjFj=VYWDsnwFg=7j13xEnceJ11aRBvHQis5QdHrpQ@mail.gmail.com>
References: <CAGD6t7JniiFU5_tu=1Dpa1-E_HjVdWyT8T7RaU6uTZ-7WF9TiQ@mail.gmail.com>
	<p3bniwsob54rr2y436hhjkl6c44k3refzzyjeqmh365fig726a@qq6ht7hzh4j6>
	<CAGD6t7+xR3YpP3QurENxL1p1FAv8zohd_8cg=tNRX10NZGHQZA@mail.gmail.com>
	<5b2ebf67-df3b-4b94-8a27-74d20d28f014@aklaver.com>
	<CAGD6t7+vGjFj=VYWDsnwFg=7j13xEnceJ11aRBvHQis5QdHrpQ@mail.gmail.com>



> On Mar 20, 2024, at 09:51, Celia McInnis <celia.mcinnis@gmail.com> wrote:
> 
> The view is being used in some web query software that multiple people will be accessing and the contents of the view depend on what the person is querying, so I think that temporary views or tables are a good idea.

There's nothing wrong with temporary views or tables, and the use-case you describe is a reasonable one.  The issue comes up when they have the same name as a permanent view or table.

It's deterministic which one a query will use.  All temporary objects are in the pseudo-schema `pg_temp` (it's a "pseudo-schema" because it's an alias to the current session's temporary schema, rather than a schema itself).  By default, pg_temp is absent from search_path, which is treated as if it were the first entry, so temporary tables and views "mask" the permanent ones.  However, if that temporary object doesn't happen to exist, or if pg_temp is explicitly moved to a different position in the search path, you could have some surprising behavior.




view thread (16+ messages)  latest in thread

Message-ID: <FF099452-FFAF-41D3-B014-77A81216668F@thebuild.com>
Permalink:  ../FF099452-FFAF-41D3-B014-77A81216668F@thebuild.com/
Also on:    postgresql.org/message-id/FF099452-FFAF-41D3-B014-77A81216668F@thebuild.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: xof@thebuild.com, celia.mcinnis@gmail.com, adrian.klaver@aklaver.com, ewie@ewie.name
  Subject: Re: Dropping a temporary view?
  In-Reply-To: <FF099452-FFAF-41D3-B014-77A81216668F@thebuild.com>
  References: <CAGD6t7JniiFU5_tu=1Dpa1-E_HjVdWyT8T7RaU6uTZ-7WF9TiQ@mail.gmail.com> <p3bniwsob54rr2y436hhjkl6c44k3refzzyjeqmh365fig726a@qq6ht7hzh4j6> <CAGD6t7+xR3YpP3QurENxL1p1FAv8zohd_8cg=tNRX10NZGHQZA@mail.gmail.com> <5b2ebf67-df3b-4b94-8a27-74d20d28f014@aklaver.com> <CAGD6t7+vGjFj=VYWDsnwFg=7j13xEnceJ11aRBvHQis5QdHrpQ@mail.gmail.com> <FF099452-FFAF-41D3-B014-77A81216668F@thebuild.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