Re: table functions + user defined types

From: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
To: "BARTKO, Zoltan" <bartko(dot)zoltan(at)pobox(dot)sk>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: table functions + user defined types
Date: 2003-10-27 15:53:36
Message-ID: BBC2F000.27133%awitney@sghms.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 27/10/03 3:20 pm, "BARTKO, Zoltan" <bartko(dot)zoltan(at)pobox(dot)sk> wrote:

> Ladies and Gentlemen,
>
> Please, enlighten me, if you can, in the following matter:
>
> I made a type:
>
> create type my_type as (
> a integer,
> b integer
> );
>
> since I have a table:
>
> create table my_table (
> a integer;
> );
>
> and I have now a function too:
>
> create or replace function my_func (
> integer, -- a
> integer, -- b
> ) returns setof my_type as
> '
> declare
> pa alias for $1;
> pb alias for $2;
> -- declarations
> my_value my_type;
> begin
> my_value.a := pa;
> my_value.b := pb;
> return my_value;
> end;
> ' language 'plpgsql';

Try this....

create or replace function my_func (
integer, -- a
integer -- b
) returns my_type as
'
declare
pa alias for $1;
pb alias for $2;
-- declarations
my_value record;
begin
select into my_value pa, pb;
return my_value;
end;
' language 'plpgsql';

> when I run this darling function I get a parse error pointing to the line
> after "begin".
>
> What am I doing wrong? I have skimmed through all the manuals, had a look at
> the postgresql cookbook, no info on this. I just would like to have a
> function that returns more fields at the same time - add a column to table
> my_table, where I could occasionally return some value (e.g. error code). How
> to do this?
>
> Thanks for your advice in advance
>
> Zoltan Bartko
>

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-10-27 16:05:14 Re: function with tablename parameter
Previous Message Manfred Koizar 2003-10-27 15:44:55 Re: Nullable 'Foreign Key-like' Constraint