Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 58A9D1337B43 for ; Mon, 17 Jan 2011 01:01:14 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 89590-05; Mon, 17 Jan 2011 05:01:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 4950C13364DE; Mon, 17 Jan 2011 01:01:00 -0400 (AST) Received: from deluge.opencloud.co.nz ([192.168.0.16]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PehCy-0003PA-Pv; Mon, 17 Jan 2011 18:00:48 +1300 Message-ID: <4D33CD00.6000408@opencloud.com> Date: Mon, 17 Jan 2011 18:00:48 +1300 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: Robert Haas CC: rsmogura , Lukas Eder , pgsql-jdbc@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function References: <201101111946.33083.rsmogura@softperience.eu> <4d7cc4033a655539995c240a6f282ab5@mail.softperience.eu> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.89 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_FILL_THIS_FORM_SHORT=0.01 X-Spam-Level: X-Archive-Number: 201101/37 X-Sequence-Number: 21369 On 17/01/11 17:27, Robert Haas wrote: > On Wed, Jan 12, 2011 at 5:12 AM, rsmogura wrote: >> Dear hackers :) Could you look at this thread from General. >> --- >> I say the backend if you have one "row type" output result treats it as the >> full output result, it's really bad if you use STRUCT types (in your example >> you see few columns, but this should be one column!). I think backend should >> return ROWDESC(1), then per row data describe this row type data. In other >> words result should be as in my example but without last column. Because >> this funny behaviour is visible in psql in JDBC I think it's backend problem >> or some far inconsistency. I don't see this described in select statement. > > I've read this report over a few times now, and I'm still not > understanding exactly what is happening that you're unhappy about. If I understand it correctly, the problem is this: Given the schema and data from the OP (summary: t_author is a TABLE t_author.address is of type u_address_type u_address_type is a TYPE with fields: street, zip, city, country, since, code u_address_type.street is of type u_street_type u_street_type is a TYPE with fields: street, no) A bare SELECT works as expected: > test_udt=# SELECT t_author.address FROM t_author WHERE first_name = 'George'; > address > ------------------------------------------------------------------- > ("(""Parliament Hill"",77)",NW31A9,Hampstead,England,1980-01-01,) > (1 row) However, doing the same via a plpgsql function with an OUT parameter produces something completely mangled: > test_udt=# CREATE FUNCTION p_enhance_address2 (address OUT u_address_type) AS $$ BEGIN SELECT t_author.address INTO address FROM t_author WHERE first_name = 'George'; END; $$ LANGUAGE plpgsql; > CREATE FUNCTION > test_udt=# SELECT * FROM p_enhance_address2(); > street | zip | city | country | since | code > -------------------------------------+-----+------+---------+-------+------ > ("(""Parliament Hill"",77)",NW31A9) | | | | | > (1 row) Here, we've somehow got the first two fields of u_address_type - street and zip - squashed together into one column named 'street', and all the other columns nulled out. Unsurprisingly the JDBC driver produces confusing results when faced with this, so it was originally reported as a JDBC problem, but the underlying problem can be seen via psql too. Oliver