Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 8C3DF62698E for ; Mon, 16 Apr 2012 18:43:16 -0300 (ADT) Received: from mail.dhs-club.com ([208.69.229.2]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SJthZ-0004C3-9d for pgsql-bugs@postgresql.org; Mon, 16 Apr 2012 21:43:15 +0000 Received: from [192.168.0.11] (hq.clubshop.com [208.78.129.189]) (authenticated bits=0) by mail.dhs-club.com (8.14.4/8.14.4) with ESMTP id q3GLgx7p009027 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Mon, 16 Apr 2012 21:43:00 GMT Message-ID: <4F8C9262.4030204@dhs-club.com> Date: Mon, 16 Apr 2012 17:42:58 -0400 From: Bill MacArthur User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: TYPE of TEMP table does not seem to get set References: <4F8C771A.2040509@dhs-club.com> <4379.1334607089@sss.pgh.pa.us> <4F8C810C.6000408@dhs-club.com> In-Reply-To: <4F8C810C.6000408@dhs-club.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.70 on 208.69.229.2 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/106 X-Sequence-Number: 32857 On 4/16/2012 4:29 PM, Bill MacArthur wrote: > On 4/16/2012 4:11 PM, Tom Lane wrote: >> Bill MacArthur writes: >>> I have a view "configurations.tp_transactions" which is a blend of many tables using INNER and LEFT JOINs. I want to populate a temp table from which I can obtain the data and programmatically write queries to operate on that data using certain PLPGSQL functions in a uniform fashion. I have several functions which all expect a single argument of the type "configurations.tp_transactions". >> >> I think you would need to create the temp table as a child of the main >> table for this to work. As you're doing it, the rowtype of the temp >> table is independent of the main (and the fact that they happen to have >> the same columns is NOT good enough to make it acceptable to a function >> declared to take the main table's rowtype). >> >> regards, tom lane >> > > I have tried this but no go: > network=# create temp table chl() inherits (configurations.tp_transactions); > ERROR: inherited relation "tp_transactions" is not a table > > This does not work either: > network=> CREATE TEMP TABLE myt OF configurations.tp_transactions; > CREATE TABLE > network=> \d myt > Table "pg_temp_11.myt" > Column | Type | Modifiers > ---------------+----------------------+----------- > id | integer | > > amount | numeric | > pp_value | numeric | > Typed table of type: configurations.tp_transactions > > network=> insert into myt select * from configurations.tp_transactions where trans_id=920787; > INSERT 0 1 > > network=> select configurations.myself(myt.*) from myt; > ERROR: function configurations.myself(myt) does not exist > LINE 1: select configurations.myself(myt.*) from myt; > ^ > HINT: No function matches the given name and argument types. You might need to add explicit type casts. > > network=> select configurations.myself(myt.*) from configurations.tp_transactions myt where trans_id=920787; > myself > -------- > 12 > (1 row) > I also tried creating an explicit TYPE and changing a function to expect that as an argument type. Then after creating the temp table using "OF , I got the same result. Apparently there is no way to attach a type to a temp table except to make it inherit from a real table. I have created a skeleton table from which I can create my temp table using INHERITS. Then I changed the argument data type on my function and it will now accept a row of data from my temp table recognizing the type. I am hoping to avoid any unneeded overhead related to the use of a real table as the parent, including replication, but there does not seem to be any way to avoid that possibility. Still not sure if this is a bug or not... don't know if it really should work the way I was expecting it to. The final working solution... for now: network=# create table work.tp_transactions network-# (id integer , INSERT INTO work.tp_transactions SELECT * FROM configurations.tp_transactions WHERE configurations.tp_transactions.trans_id IN (920787); network=# CREATE OR REPLACE FUNCTION configurations.myself(work.tp_transactions) network=# create temp table myt () inherits (work.tp_transactions); CREATE TABLE network=# select configurations.myself(myt.*) from myt; myself -------- 12 (1 row)