Re: VIEWs and TEMP tables problem

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: Antal Attila <atesz(at)ritek(dot)hu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: VIEWs and TEMP tables problem
Date: 2006-02-16 12:13:18
Message-ID: 43F46C5E.8090806@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 OFFSET 10;

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Caune 2006-02-16 13:57:20 Re: How to force PostgreSQL using an index
Previous Message Richard Huxton 2006-02-16 11:57:48 Re: VIEWs and TEMP tables problem