X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 35F649DC9C7 for ; Thu, 16 Feb 2006 07:57:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70702-02 for ; Thu, 16 Feb 2006 07:57:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id D31B99DC813 for ; Thu, 16 Feb 2006 07:57:47 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 89B0C42F3AF; Thu, 16 Feb 2006 11:57:49 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 564D215EA4; Thu, 16 Feb 2006 11:57:49 +0000 (GMT) Message-ID: <43F468BC.2020207@archonet.com> Date: Thu, 16 Feb 2006 11:57:48 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Antal Attila Cc: pgsql-sql@postgresql.org Subject: Re: VIEWs and TEMP tables problem References: <43F4617E.9060708@ritek.hu> In-Reply-To: <43F4617E.9060708@ritek.hu> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.117 required=5 tests=[AWL=0.117] X-Spam-Score: 0.117 X-Spam-Level: X-Archive-Number: 200602/202 X-Sequence-Number: 24212 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 a LEFT 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 BY col_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