Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function

From: rsmogura <rsmogura(at)softperience(dot)eu>
To: Lukas Eder <lukas(dot)eder(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Oliver Jowett <oliver(at)opencloud(dot)com>, <pgsql-jdbc(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function
Date: 2011-01-25 09:06:10
Message-ID: 528a0187e74bbc3a40a6659df8e67e67@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-jdbc

Hi,
I don't know if this is a bug, but at least I haven't found any clear
statement in documentation about; this should be wrote with big and bold
letters.

In any way I think this is bug or big inconsistency, because of, as was
stated in previous mail
test=# CREATE FUNCTION p_enhance_address3 (address OUT u_address_type,
i1 OUT
int)
AS $$
BEGIN
SELECT t_author.address
INTO address
FROM t_author
WHERE first_name = 'George';
i1 = 12;
END;
$$ LANGUAGE plpgsql;
test=# select *
from p_enhance_address3();
address | i1
----------------------------------------------------+----
("(""(""""Parliament Hill"""",77)"",NW31A9)",,,,,) | 12
(1 row),
but if you will create above function without last, i1 parameter
(SELECT * FROM p_enhance_address2();) then result will be
street | zip | city | country | since |
code
-------------------------------------+-----+------+---------+-------+------
("(""Parliament Hill"",77)",NW31A9) | | | | |
In last case, I think, result should be "packed" in one column, because
of it clearly "unpacked" record.

On Tue, 25 Jan 2011 14:39:51 +0700, Lukas Eder wrote:
>>> 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.
>>  
>> I think this is the old problem of PL/pgsql having two forms of
>> SELECT
>> INTO.  You can either say:
>>  
>> SELECT col1, col2, col3, ... INTO recordvar FROM ...
>>  
>> Or you can say:
>>  
>> SELECT col1, col2, col3, ... INTO nonrecordvar1, nonrecordvar2,
>> nonrecordvar3, ... FROM ...
>>  
>> In this case, since address is a recordvar, it's expecting the first
>>
>> form - thus the first select-list item gets matched to the first
>> column of the address, rather than to address as a whole.  It's not
>>
>> smart enough to consider the types of the items involved - only
>> whether they are records.  :-(
>
>  
> So what you're suggesting is that the plpgsql code is causing the
> issues? Are there any indications about how I could re-write this
> code? The important thing for me is to have the aforementioned
> signature of the plpgsql function with one UDT OUT parameter. Even
> if this is a bit awkward in general, in this case, I don't mind
> rewriting the plpgsql function content to create a workaround for
> this problem... 

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2011-01-25 09:07:39 Re: SSI patch version 14
Previous Message Dave Page 2011-01-25 08:42:21 Re: [HACKERS] Seeking Mentors for Funded Reviewers

Browse pgsql-jdbc by date

  From Date Subject
Next Message ml-tb 2011-01-27 10:41:23 Double quoted column name from DatabaseMetaData.getIndexInfo
Previous Message Lukas Eder 2011-01-25 07:39:51 Re: [HACKERS] Fwd: Weird issues when reading UDT from stored function