PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 21st, 2003, 05:12 AM
jaja jaja is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 jaja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Stored procedures

Hello.
I'm trying to translate sql code from a asp application to stored procedures in PostgreSQL.
The main problem is when the result of the sql code is a set (recordset) from some joins between two o more tables.
How can I define the function in PostgreSQL for this case? What type I have to select for the result?
Thank you.

Reply With Quote
  #2  
Old March 23rd, 2003, 11:37 PM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 13 m 55 sec
Reputation Power: 27
have you looked into using views at all?

http://www.phpfreaks.com/postgresql...rial-views.html
__________________
- Andreas Koepke

Koepke Photography


Reply With Quote
  #3  
Old March 24th, 2003, 12:27 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
If you are trying to return a "setof record" but there isn't a table with the same definition, you can create a composite type instead.

See
this for more detail.
__________________
FSBO (For Sale By Owner) Realty

Reply With Quote
  #4  
Old March 28th, 2003, 02:14 AM
smauroz smauroz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 smauroz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy i have the sama problem + or -

I start with the only sql and after i used plpgsql:

CREATE FUNCTION fct_selezione_user_area(text) RETURNS SETOF RECORD AS'
declare
objRs_selezione RECORD;
codice_area ALIAS FOR $1;
begin
SELECT INTO objRs_selezione.id_area,objRs_selezione.area * from
tbl_area where area = codice_area;
RETURN objRs_selezione;
End;
' LANGUAGE 'plpgsql';

I select the function to see results:
select * from fct_selezione_user_area('B');

error:
A column definition list is required for functions returning RECORD

I start with 2 tables and after i reduce to 1...but the problem is the same...definition of columns....
some idea?
tnx

Reply With Quote
  #5  
Old March 28th, 2003, 06:02 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
smauroz,

There's so many things wrong with your function that I don't know where to begin, but I'll try.

First, you cannot return a set of record without defining the record first. As I mentioned previously you either have to have a table that already has the same definition as the record being returned and use it, or define a composite type.

For example, if you have a table:

define table ex1(
id int not null primary key,
foo text not null);

You could use it as the type for the returned set if you were returning an int and text. e.g.

create or replace function bar() returns set of ex1 as '....

if you didn't have a table with that definition but needed to return a set like that you could do this:

create type my_return_type as (id int, foo text);

create or replace function bar() returns set of my_return_type as '...

Second,
Your query inside the function is wrong. You are trying to use a variable (codice_area) inside the select which is problematic. Also, since it is text it would need to be quoted. The proper way to do this is with an EXECUTE.

Third,
Your select into is wrong. For what you are trying it would be:

select into objRs_selezione id_area,area from tbl_area.

I can't give you an example that would work because I'm not even sure what you are trying to return since you threw the * in there.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Stored procedures


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT