Thread: Accessing table attributes from within PlPgSQL

Accessing table attributes from within PlPgSQL

From
Ron Johnson
Date:
Hi,

What is the method of accessing fields from within records?

Apparently, PlPgSQL doesn't these methods
    raise notice x.bar;
    raise notice :x.bar;
It must be something similar, right.

As always, TIA from this postgresql newbie.

test2=# select * from foo;
 bar
-----
   1
   2
   3
(3 rows)

test2=# create or replace function curstst1() RETURNS INTEGER AS '
test2'# declare x record;
test2'# begin
test2'#     for x in select * from foo loop
test2'#         raise notice x.bar;
test2'#     end loop;
test2'#     return 1;
test2'# end;
test2'# ' LANGUAGE 'plpgsql';
CREATE
test2=# select curstst1();
NOTICE:  plpgsql: ERROR during compile of curstst1 near line 4
ERROR:  parse error at or near "x.bar"

--
+---------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson@cox.net     |
| Jefferson, LA  USA      http://ronandheather.dhs.org:81 |
|                                                         |
| "I have created a government of whirled peas..."        |
|   Maharishi Mahesh Yogi, 12-May-2002,                   |
!   CNN, Larry King Live                                  |
+---------------------------------------------------------+


Re: Accessing table attributes from within PlPgSQL

From
"Henshall, Stuart - WCP"
Date:

RAISE NOTICE ''%'',x.bar;
should work (not tested it though)
hth,
- Stuart

> -----Original Message-----
> From: Ron Johnson [mailto:ron.l.johnson@cox.net]
> Sent: 20 May 2002 00:34
> To: PgSQL Novice ML
> Subject: [NOVICE] Accessing table attributes from within PlPgSQL
>
>
> Hi,
>
> What is the method of accessing fields from within records?
>
> Apparently, PlPgSQL doesn't these methods
>     raise notice x.bar;
>     raise notice :x.bar;
> It must be something similar, right.
>
> As always, TIA from this postgresql newbie.
>
> test2=# select * from foo;
>  bar
> -----
>    1
>    2
>    3
> (3 rows)
>
> test2=# create or replace function curstst1() RETURNS INTEGER AS '
> test2'# declare x record;
> test2'# begin
> test2'#     for x in select * from foo loop
> test2'#         raise notice x.bar;
> test2'#     end loop;
> test2'#     return 1;
> test2'# end;
> test2'# ' LANGUAGE 'plpgsql';
> CREATE
> test2=# select curstst1();
> NOTICE:  plpgsql: ERROR during compile of curstst1 near line 4
> ERROR:  parse error at or near "x.bar"
>
> --
> +---------------------------------------------------------+
> | Ron Johnson, Jr.        Home: ron.l.johnson@cox.net     |
> | Jefferson, LA  USA      http://ronandheather.dhs.org:81 |
> |                                                         |
> | "I have created a government of whirled peas..."        |
> |   Maharishi Mahesh Yogi, 12-May-2002,                   |
> !   CNN, Larry King Live                                  |
> +---------------------------------------------------------+
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo@postgresql.org
>