Re: VIEWs and TEMP tables problem - Mailing list pgsql-sql

From Richard Huxton
Subject Re: VIEWs and TEMP tables problem
Date
Msg-id 43F468BC.2020207@archonet.com
Whole thread Raw
In response to VIEWs and TEMP tables problem  (Antal Attila <atesz@ritek.hu>)
List pgsql-sql
Antal Attila wrote:
> Hi!
> 
> I found a problem with the views in PostgreSQL if I want to use 
> temporary tables in it.  See the next case!
[snip]
> The problem is that the view use the original permanent table, but the 
> 1) query use the temporary actual_code table.
> I read the temporally table definition in the documentation 
> (http://www.postgresql.org/docs/8.1/interactive/sql-createtable.html) 
> and I concluded it should be working.
> 
> Is it BUG, or FEATURE? Has anybody got good ideas for solve this problem?

Feature, I'd guess.

When the view was built there was no TEMP TABLE. If you do \d a_view 
you'll see it actually will link to something like "public.a". If it 
didn't, your view could change depending on your search_path settings 
and even break.

You'll see a similar problem with plpgsql functions.

> This construction came to my mind, because I tried to solve my another 
> question: 
> http://groups.google.co.hu/group/pgsql.performance/browse_thread/thread/c7aec005f4a1f3eb/83fa0053cad33dea 

I think you need to explain why you're trying to do this:   CREATE VIEW ab_view AS        SELECT a.id AS id,
          a.userid AS userid_a, b.userid AS userid_b,                       a.col AS col_a, b.col AS col_b        FROM
aLEFT JOIN b ON (a.id = b.a_id);
 
    EXPLAIN ANALYSE SELECT * FROM ab_view        WHERE userid_a = 23 AND userid_b = 23 AND col_a LIKE 's%'        ORDER
BYcol_b        LIMIT 10 OFFSET 10;
 

If you want userid_a=userid_b ALWAYS to be the same, just put it in the 
view. If you sometimes want them different, then you'll have to provide 
two parameters anyway. It's not clear how you intend to use this.

--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: Antal Attila
Date:
Subject: VIEWs and TEMP tables problem
Next
From: Markus Schaber
Date:
Subject: Re: VIEWs and TEMP tables problem