Re: Returning Composite Types from C functions - Mailing list pgsql-hackers

From Michael Fuhr
Subject Re: Returning Composite Types from C functions
Date
Msg-id 20050618133111.GA91368@winnie.fuhr.org
Whole thread Raw
In response to Re: Returning Composite Types from C functions  ("John Hansen" <john@geeknet.com.au>)
Responses Re: Returning Composite Types from C functions
List pgsql-hackers
On Sat, Jun 18, 2005 at 10:03:38PM +1000, John Hansen wrote:
> 
> There is a workaround tho, so should be fixable:
> 
> SELECT (a.b).* FROM (SELECT ('1:2:3:4:5'::text::my_type) AS b) AS a;
> 
> Or am I missing something?

I don't know enough about PostgreSQL internals so I'll have to defer
to the developers.  But here's a case where the above workaround
doesn't work -- in my tests, the cast function is called once per
column per row, or ten times:

CREATE TABLE foo (t text);
INSERT INTO foo VALUES ('1:2:3:4:5');
INSERT INTO foo VALUES ('6:7:8:9:10');
SELECT (a.b).* FROM (SELECT t::my_type AS b FROM foo) AS a;

What do you get?  Can you think of a workaround for this case?
Maybe one of the developers can comment on why your example calls
the function only once and mine calls it multiple times per row,
even though they look similar.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: LGPL
Next
From: Tom Lane
Date:
Subject: Re: Returning Composite Types from C functions