Re: Inspection of row types in pl/pgsql and pl/sql

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Postgresql-Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inspection of row types in pl/pgsql and pl/sql
Date: 2009-11-14 16:31:01
Message-ID: 4AFEDB45.5000000@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> "Florian G. Pflug" <fgp(at)phlo(dot)org> writes:
>> Tom Lane wrote:
>>> Trying to do this in plpgsql is doomed to failure and heartache,
>
>> Well, the proposed functions at least allow for some more
>> flexibility in working with row types, given that you know in
>> advance which types you will be dealing with (but not necessarily
>> the precise ordering and number of the record's fields). They might
>> feel a bit kludgy because of the "anyelement" dummy argument that
>> bridges the gap between the statically typed nature of SQL and the
>> rather dynamic RECORDs, but the kludgy-ness factor is still within
>> reasonable limits I think.
>
> It sounds pretty d*mn klugy to me, and I stand by my comment that it
> isn't going to work anyway. When you try it you are going to run
> into "parameter type doesn't match that while preparing the plan"
> errors.

Ok, I must be missing something. I currently fail to see how
my proposed
record_value(record, name, anyelement) returns anyelement
function differs (from the type system's point of view) from
value_from_string(text, anyelement) returns anyelement
which simply casts the text value to the given type and can easily be
implemented in plpgsq.

create or replace function
value_from_string(v_value text, v_type_dummy anyelement)
returns anyelement as
$body$
declare
v_result v_type_dummy%type;
begin
if v_value is null then
return null;
end if;

v_result := v_value;
return v_result;
end;
$body$ language plpgsql immutable;

-- Returns 124
select value_from_string('123', NULL::int) + 1;
-- returns {1,2,3,4}
select value_from_string('{1,2,3}', NULL::int[]) || array[4];

best regards,
Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-11-14 16:40:18 Re: Inspection of row types in pl/pgsql and pl/sql
Previous Message Tom Lane 2009-11-14 16:26:50 Re: Re: BUG #5065: pg_ctl start fails as administrator, with "could not locate matching postgres executable"