pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: rsmogura <rsmogura@softperience.eu>
Cc: Lukas Eder <lukas.eder@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Cc: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function
Date: Mon, 17 Jan 2011 18:00:48 +1300
Message-ID: <4D33CD00.6000408@opencloud.com> (raw)
In-Reply-To: <AANLkTi=EAbWpOZhXUaG0OG7smtExwoE4M9dv2ykzPVcZ@mail.gmail.com>
References: <c63c0e3d-cd3b-4b82-b891-50f8ef43bfdb@j25g2000vbs.googlegroups.com>
	<AANLkTi=HC-C5gL29ovNqcqtfNQa6XM8oNA0a86YsYcVt@mail.gmail.com>
	<AANLkTi=pTFGV+vVFgKwB6+ZNWb+r9LrYpJXKEytL5P02@mail.gmail.com>
	<201101111946.33083.rsmogura@softperience.eu>
	<AANLkTi=UH_9qC8CmQBN7aEwsdUMYAzjRUCJmDiWFTQQH@mail.gmail.com>
	<4d7cc4033a655539995c240a6f282ab5@mail.softperience.eu>
	<AANLkTi=EAbWpOZhXUaG0OG7smtExwoE4M9dv2ykzPVcZ@mail.gmail.com>

On 17/01/11 17:27, Robert Haas wrote:
> On Wed, Jan 12, 2011 at 5:12 AM, rsmogura<rsmogura@softperience.eu>  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



view thread (48+ messages)  latest in thread

Message-ID: <4D33CD00.6000408@opencloud.com>
Permalink:  ../4D33CD00.6000408@opencloud.com/
Also on:    postgresql.org/message-id/4D33CD00.6000408@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, robertmhaas@gmail.com, rsmogura@softperience.eu, lukas.eder@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function
  In-Reply-To: <4D33CD00.6000408@opencloud.com>
  References: <c63c0e3d-cd3b-4b82-b891-50f8ef43bfdb@j25g2000vbs.googlegroups.com> <AANLkTi=HC-C5gL29ovNqcqtfNQa6XM8oNA0a86YsYcVt@mail.gmail.com> <AANLkTi=pTFGV+vVFgKwB6+ZNWb+r9LrYpJXKEytL5P02@mail.gmail.com> <201101111946.33083.rsmogura@softperience.eu> <AANLkTi=UH_9qC8CmQBN7aEwsdUMYAzjRUCJmDiWFTQQH@mail.gmail.com> <4d7cc4033a655539995c240a6f282ab5@mail.softperience.eu> <AANLkTi=EAbWpOZhXUaG0OG7smtExwoE4M9dv2ykzPVcZ@mail.gmail.com> <4D33CD00.6000408@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox