pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedpl/pgsql and returning rows
7+ messages / 4 participants
[nested] [flat]
* pl/pgsql and returning rows
@ 2001-03-05 19:51 wade <wade@wavefire.com>
0 siblings, 0 replies; 7+ messages in thread
From: wade @ 2001-03-05 19:51 UTC (permalink / raw)
To: pgsql-sql
Here is the senario...
I have a table defined as
create table details (
field1 <type>
field2 <type>
.
.
.
);
and a function:
create function get_details(int4) returns details as '
declare
ret details%ROWTYPE;
site_rec record;
cntct contacts%ROWTYPE;
begin
select into site_rec * sites_table where id = $1 limit 1;
select into cntct * from contacts where id = site_rec.contact;
-- and then i populate rows of ret.
ret.name := cntct.name;
ret.ip := site_rec.ip;
.
.
.
return ret;
end;
' language 'plpgsql';
now the problem is when is when I do a:
SELECT get_details(55);
all i get is a single oid-looking return value:
get_details
-------------
136295592
(1 row)
How do i get at the actual information in the row?
Is this type of function even possible?
If not, is there a different manner in which i should approach this task?
Thanx in advance.
-Wade
^ permalink raw reply [nested|flat] 7+ messages in thread
* pl/pgsql and returning rows
@ 2001-03-26 19:59 wade <wade@wavefire.com>
2001-03-27 08:26 ` Re: pl/pgsql and returning rows Richard Huxton <dev@archonet.com>
0 siblings, 1 reply; 7+ messages in thread
From: wade @ 2001-03-26 19:59 UTC (permalink / raw)
To: pgsql-sql
Here is the senario...
I have a table defined as
create table details (
field1 <type>
field2 <type>
.
.
.
);
and a function:
create function get_details(int4) returns details as '
declare
ret details%ROWTYPE;
site_rec record;
cntct contacts%ROWTYPE;
begin
select into site_rec * sites_table where id = $1 limit 1;
select into cntct * from contacts where id = site_rec.contact;
-- and then i populate rows of ret.
ret.name := cntct.name;
ret.ip := site_rec.ip;
.
.
.
return ret;
end;
' language 'plpgsql';
now the problem is when is when I do a:
SELECT get_details(55);
all i get is a single oid-looking return value:
get_details
-------------
136295592
(1 row)
How do i get at the actual information in the row?
Is this type of function even possible?
If not, is there a different manner in which i should approach this task?
Thanx in advance.
-Wade
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pl/pgsql and returning rows
2001-03-26 19:59 pl/pgsql and returning rows wade <wade@wavefire.com>
@ 2001-03-27 08:26 ` Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 7+ messages in thread
From: Richard Huxton @ 2001-03-27 08:26 UTC (permalink / raw)
To: pgsql-sql; wade <wade@wavefire.com>
From: "wade" <wade@wavefire.com>
> create function get_details(int4) returns details as '
> declare
> ret details%ROWTYPE;
> site_rec record;
> cntct contacts%ROWTYPE;
> begin
> select into site_rec * sites_table where id = $1 limit 1;
> select into cntct * from contacts where id = site_rec.contact;
>
> -- and then i populate rows of ret.
> ret.name := cntct.name;
> ret.ip := site_rec.ip;
> .
> .
> .
> return ret;
> end;
> ' language 'plpgsql';
>
> now the problem is when is when I do a:
> SELECT get_details(55);
> all i get is a single oid-looking return value:
> get_details
> -------------
> 136295592
> (1 row)
Sorry - you can't return a row from a function at the present time (except
for trigger functions which are special) although I believe this is on the
todo list for a later 7.x release.
Just from the top of my head, you might try a view with a select rule,
although I'm not completely clear what your objectives are.
- Richard Huxton
^ permalink raw reply [nested|flat] 7+ messages in thread
* RE: pl/pgsql and returning rows
@ 2001-03-27 21:43 Jeff Eckermann <jeckermann@verio.net>
2001-03-27 21:51 ` Re: RE: pl/pgsql and returning rows Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Eckermann @ 2001-03-27 21:43 UTC (permalink / raw)
To: pgsql-sql@postgresql.org, wade <wade@wavefire.com>
As a workaround, you can insert your row into an existing table, then
retrieve it from there later. I think you need to enumerate all of the
fields, as in 'INSERT INTO table VALUES (ret.field1,
ret.field2,...ret.fieldn);'. At least, I haven't succeeded any other way.
Messy, but the best method available right now.
> -----Original Message-----
> From: Richard Huxton [SMTP:dev@archonet.com]
> Sent: Tuesday, March 27, 2001 2:27 AM
> To: pgsql-sql@postgresql.org; wade
> Subject: Re: pl/pgsql and returning rows
>
> From: "wade" <wade@wavefire.com>
>
> > create function get_details(int4) returns details as '
> > declare
> > ret details%ROWTYPE;
> > site_rec record;
> > cntct contacts%ROWTYPE;
> > begin
> > select into site_rec * sites_table where id = $1 limit 1;
> > select into cntct * from contacts where id = site_rec.contact;
> >
> > -- and then i populate rows of ret.
> > ret.name := cntct.name;
> > ret.ip := site_rec.ip;
> > .
> > .
> > .
> > return ret;
> > end;
> > ' language 'plpgsql';
> >
> > now the problem is when is when I do a:
> > SELECT get_details(55);
> > all i get is a single oid-looking return value:
> > get_details
> > -------------
> > 136295592
> > (1 row)
>
> Sorry - you can't return a row from a function at the present time (except
> for trigger functions which are special) although I believe this is on the
> todo list for a later 7.x release.
>
> Just from the top of my head, you might try a view with a select rule,
> although I'm not completely clear what your objectives are.
>
> - Richard Huxton
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: RE: pl/pgsql and returning rows
2001-03-27 21:43 RE: pl/pgsql and returning rows Jeff Eckermann <jeckermann@verio.net>
@ 2001-03-27 21:51 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-03-28 10:23 ` Re: RE: pl/pgsql and returning rows Richard Huxton <dev@archonet.com>
0 siblings, 1 reply; 7+ messages in thread
From: Bruce Momjian @ 2001-03-27 21:51 UTC (permalink / raw)
To: Jeff Eckermann <jeckermann@verio.net>; +Cc: pgsql-sql@postgresql.org, wade <wade@wavefire.com>
MY book in chapter 18 has a Pl/PgSQL function called change_statename
that does insert/update automatically.
http://www.postgresql.org/docs/awbook.html
> As a workaround, you can insert your row into an existing table, then
> retrieve it from there later. I think you need to enumerate all of the
> fields, as in 'INSERT INTO table VALUES (ret.field1,
> ret.field2,...ret.fieldn);'. At least, I haven't succeeded any other way.
> Messy, but the best method available right now.
>
> > -----Original Message-----
> > From: Richard Huxton [SMTP:dev@archonet.com]
> > Sent: Tuesday, March 27, 2001 2:27 AM
> > To: pgsql-sql@postgresql.org; wade
> > Subject: Re: pl/pgsql and returning rows
> >
> > From: "wade" <wade@wavefire.com>
> >
> > > create function get_details(int4) returns details as '
> > > declare
> > > ret details%ROWTYPE;
> > > site_rec record;
> > > cntct contacts%ROWTYPE;
> > > begin
> > > select into site_rec * sites_table where id = $1 limit 1;
> > > select into cntct * from contacts where id = site_rec.contact;
> > >
> > > -- and then i populate rows of ret.
> > > ret.name := cntct.name;
> > > ret.ip := site_rec.ip;
> > > .
> > > .
> > > .
> > > return ret;
> > > end;
> > > ' language 'plpgsql';
> > >
> > > now the problem is when is when I do a:
> > > SELECT get_details(55);
> > > all i get is a single oid-looking return value:
> > > get_details
> > > -------------
> > > 136295592
> > > (1 row)
> >
> > Sorry - you can't return a row from a function at the present time (except
> > for trigger functions which are special) although I believe this is on the
> > todo list for a later 7.x release.
> >
> > Just from the top of my head, you might try a view with a select rule,
> > although I'm not completely clear what your objectives are.
> >
> > - Richard Huxton
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: RE: pl/pgsql and returning rows
2001-03-27 21:43 RE: pl/pgsql and returning rows Jeff Eckermann <jeckermann@verio.net>
2001-03-27 21:51 ` Re: RE: pl/pgsql and returning rows Bruce Momjian <pgman@candle.pha.pa.us>
@ 2001-03-28 10:23 ` Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 7+ messages in thread
From: Richard Huxton @ 2001-03-28 10:23 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; Jeff Eckermann <jeckermann@verio.net>; +Cc: pgsql-sql; wade <wade@wavefire.com>
From: "Bruce Momjian" <pgman@candle.pha.pa.us>
> MY book in chapter 18 has a Pl/PgSQL function called change_statename
> that does insert/update automatically.
>
> http://www.postgresql.org/docs/awbook.html
The functions called get_details though, so I assumed it's supposed to be
shorthand for a join.
- Richard
> > As a workaround, you can insert your row into an existing table, then
> > retrieve it from there later. I think you need to enumerate all of the
> > fields, as in 'INSERT INTO table VALUES (ret.field1,
> > ret.field2,...ret.fieldn);'. At least, I haven't succeeded any other
way.
> > Messy, but the best method available right now.
> >
> > > -----Original Message-----
> > > From: Richard Huxton [SMTP:dev@archonet.com]
> > > Sent: Tuesday, March 27, 2001 2:27 AM
> > > To: pgsql-sql@postgresql.org; wade
> > > Subject: Re: pl/pgsql and returning rows
> > >
> > > From: "wade" <wade@wavefire.com>
> > >
> > > > create function get_details(int4) returns details as '
> > > > declare
> > > > ret details%ROWTYPE;
> > > > site_rec record;
> > > > cntct contacts%ROWTYPE;
> > > > begin
> > > > select into site_rec * sites_table where id = $1 limit 1;
> > > > select into cntct * from contacts where id = site_rec.contact;
> > > >
> > > > -- and then i populate rows of ret.
> > > > ret.name := cntct.name;
> > > > ret.ip := site_rec.ip;
> > > > .
> > > > .
> > > > .
> > > > return ret;
> > > > end;
> > > > ' language 'plpgsql';
> > > >
> > > > now the problem is when is when I do a:
> > > > SELECT get_details(55);
> > > > all i get is a single oid-looking return value:
> > > > get_details
> > > > -------------
> > > > 136295592
> > > > (1 row)
> > >
> > > Sorry - you can't return a row from a function at the present time
(except
> > > for trigger functions which are special) although I believe this is on
the
> > > todo list for a later 7.x release.
> > >
> > > Just from the top of my head, you might try a view with a select rule,
> > > although I'm not completely clear what your objectives are.
> > >
> > > - Richard Huxton
> > >
> > >
> > > ---------------------------(end of
broadcast)---------------------------
> > > TIP 1: subscribe and unsubscribe commands go to
majordomo@postgresql.org
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> >
>
>
> --
> Bruce Momjian | http://candle.pha.pa.us
> pgman@candle.pha.pa.us | (610) 853-3000
> + If your life is a hard drive, | 830 Blythe Avenue
> + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: RE: pl/pgsql and returning rows
@ 2001-03-27 22:21 Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 7+ messages in thread
From: Bruce Momjian @ 2001-03-27 22:21 UTC (permalink / raw)
To: Jeff Eckermann <jeckermann@verio.net>; +Cc: pgsql-sql
FYI, I am always looking for additional examples that I should add in
the next edition.
> Yes: good example! I keep a printed copy on my desk... :-)
>
> > -----Original Message-----
> > From: Bruce Momjian [SMTP:pgman@candle.pha.pa.us]
> > Sent: Tuesday, March 27, 2001 3:52 PM
> > To: Jeff Eckermann
> > Cc: pgsql-sql@postgresql.org; wade
> > Subject: Re: [SQL] RE: pl/pgsql and returning rows
> >
> > MY book in chapter 18 has a Pl/PgSQL function called change_statename
> > that does insert/update automatically.
> >
> > http://www.postgresql.org/docs/awbook.html
> >
> > > As a workaround, you can insert your row into an existing table, then
> > > retrieve it from there later. I think you need to enumerate all of the
> > > fields, as in 'INSERT INTO table VALUES (ret.field1,
> > > ret.field2,...ret.fieldn);'. At least, I haven't succeeded any other
> > way.
> > > Messy, but the best method available right now.
> > >
> > > > -----Original Message-----
> > > > From: Richard Huxton [SMTP:dev@archonet.com]
> > > > Sent: Tuesday, March 27, 2001 2:27 AM
> > > > To: pgsql-sql@postgresql.org; wade
> > > > Subject: Re: pl/pgsql and returning rows
> > > >
> > > > From: "wade" <wade@wavefire.com>
> > > >
> > > > > create function get_details(int4) returns details as '
> > > > > declare
> > > > > ret details%ROWTYPE;
> > > > > site_rec record;
> > > > > cntct contacts%ROWTYPE;
> > > > > begin
> > > > > select into site_rec * sites_table where id = $1 limit 1;
> > > > > select into cntct * from contacts where id = site_rec.contact;
> > > > >
> > > > > -- and then i populate rows of ret.
> > > > > ret.name := cntct.name;
> > > > > ret.ip := site_rec.ip;
> > > > > .
> > > > > .
> > > > > .
> > > > > return ret;
> > > > > end;
> > > > > ' language 'plpgsql';
> > > > >
> > > > > now the problem is when is when I do a:
> > > > > SELECT get_details(55);
> > > > > all i get is a single oid-looking return value:
> > > > > get_details
> > > > > -------------
> > > > > 136295592
> > > > > (1 row)
> > > >
> > > > Sorry - you can't return a row from a function at the present time
> > (except
> > > > for trigger functions which are special) although I believe this is on
> > the
> > > > todo list for a later 7.x release.
> > > >
> > > > Just from the top of my head, you might try a view with a select rule,
> > > > although I'm not completely clear what your objectives are.
> > > >
> > > > - Richard Huxton
> > > >
> > > >
> > > > ---------------------------(end of
> > broadcast)---------------------------
> > > > TIP 1: subscribe and unsubscribe commands go to
> > majordomo@postgresql.org
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 2: you can get off all lists at once with the unregister command
> > > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> > >
> >
> >
> > --
> > Bruce Momjian | http://candle.pha.pa.us
> > pgman@candle.pha.pa.us | (610) 853-3000
> > + If your life is a hard drive, | 830 Blythe Avenue
> > + Christ can be your backup. | Drexel Hill, Pennsylvania 19026
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2001-03-28 10:23 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-05 19:51 pl/pgsql and returning rows wade <wade@wavefire.com>
2001-03-26 19:59 pl/pgsql and returning rows wade <wade@wavefire.com>
2001-03-27 08:26 ` Richard Huxton <dev@archonet.com>
2001-03-27 21:43 RE: pl/pgsql and returning rows Jeff Eckermann <jeckermann@verio.net>
2001-03-27 21:51 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-03-28 10:23 ` Richard Huxton <dev@archonet.com>
2001-03-27 22:21 Re: RE: pl/pgsql and returning rows Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox