472,122 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

table functions + user defined types

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';

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). Howto do this?

Thanks for your advice in advance

Zoltan Bartko
Nov 12 '05 #1
1 1748
On 27/10/03 3:20 pm, "BARTKO, Zoltan" <ba***********@pobox.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.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

61 posts views Thread by Toby Austin | last post: by
2 posts views Thread by Bryan Olson | last post: by
44 posts views Thread by bahadir.balban | last post: by
8 posts views Thread by Edward Diener | last post: by
31 posts views Thread by Michael | last post: by
6 posts views Thread by LSW | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.