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

From Markus Schaber
Subject Re: VIEWs and TEMP tables problem
Date
Msg-id 43F46C5E.8090806@logix-tt.com
Whole thread Raw
In response to VIEWs and TEMP tables problem  (Antal Attila <atesz@ritek.hu>)
Responses Re: VIEWs and TEMP tables problem  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi, Antal,

Antal Attila wrote:

> CREATE VIEW a_view AS SELECT * FROM a JOIN actual_code AC ON (a.code =
> AC.code);

Here, you bind the View to the permanent table.

> CREATE TEMP TABLE actual_code AS SELECT 23::INT4 AS code;

And here you create the temp table that will hide the permanent 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.

I would not think so, as it states "unless they are referenced with
schema-qualified names". So the permanent table is not removed, only
hidden in the default (non-qualified) name space.

Views don't look up the tables by name. Views bind to the table via
internal ids, and this binding is strong enough to survive even a table
rename, still referencing the same table.

> Is it BUG, or FEATURE? Has anybody got good ideas for solve this problem?

It is a feature.

> 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

Maybe you try:
CREATE VIEW ab_view AS       SELECT a.id AS id,                      a.userid AS userid,                      a.col AS
col_a,b.col AS col_b       FROM a LEFT JOIN b ON (a.id = b.a_id AND a.userid=b.userid);
 

EXPLAIN ANALYSE SELECT * FROM ab_view       WHERE userid = 23 AND col_a LIKE 's%'       ORDER BY col_b       LIMIT 10
OFFSET10;
 

HTH,
Markus
-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: VIEWs and TEMP tables problem
Next
From: "Daniel Caune"
Date:
Subject: Re: How to force PostgreSQL using an index