Re: display table contents using a stored proc

From: "Obe, Regina DND\\MIS" <robe(dot)dnd(at)cityofboston(dot)gov>
To: 'Manish Raj Sharma' <manishrs(at)aol(dot)net>, "'pgsql-novice(at)postgresql(dot)org'" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: display table contents using a stored proc
Date: 2005-10-05 13:08:52
Message-ID: 35F9812087218F47B050D41D1B58298B086F70@dnd5.dnd.boston.cob
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

You don't want it to return void. Also for something this simple, you really
don't need to use plpgsql. You can just use sql language

Try something like

create or replace function show_table (
cidr -- ip_block
) returns setof ip_table
language sql as '
select * from ip_table
where ip_block = $1;
';

If you are using it to return a table structure then you'll probably want to
do something like

select * from show_table('62.51.0.0/16');

-----Original Message-----
From: Manish Raj Sharma [mailto:manishrs(at)aol(dot)net]
Sent: Wednesday, October 05, 2005 8:16 AM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] display table contents using a stored proc

Hi,

I am new to stored procedures and have been trying to display the
contents of a table using a stored proc as follows:

create or replace function show_table (
cidr -- ip_block
) returns void
language plpgsql as '
declare
block alias for $1;
begin
select * from ip_table
where ip_block = block
return;
end;
';

When I call the function, I get the following:

mydb=# SELECT show_table('62.51.0.0/16');
ERROR: SELECT query has no destination for result data
HINT: If you want to discard the results, use PERFORM instead.
CONTEXT: PL/pgSQL function "show_table" line 4 at SQL statement

Any help?

Thanks,
-manish

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel T. Staal 2005-10-05 13:51:31 Re: Missing file LIBC06P1
Previous Message Manish Raj Sharma 2005-10-05 12:15:58 display table contents using a stored proc