Re: Returning Composite Types from C functions

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: John Hansen <john(at)geeknet(dot)com(dot)au>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Returning Composite Types from C functions
Date: 2005-06-18 13:31:11
Message-ID: 20050618133111.GA91368@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-06-18 13:35:30 Re: Returning Composite Types from C functions
Previous Message Robert Treat 2005-06-18 13:27:49 Re: default database creation with initdb