Re: accessing fully qualified fields in records in PLPGSQL?

From: Darren Ferguson <darren(at)crystalballinc(dot)com>
To: "Oberpriller, Wade D(dot)" <oberpwd(at)nsc-msg01(dot)network(dot)com>
Cc: "PostgreSQL General Help (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: accessing fully qualified fields in records in PLPGSQL?
Date: 2002-03-25 16:52:11
Message-ID: Pine.LNX.4.10.10203251151220.16838-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

dev=> CREATE FUNCTION test() RETURNS INTEGER AS '
dev'> DECLARE
dev'> rec RECORD;
dev'> val INTEGER;
dev'> BEGIN
dev'> FOR rec IN SELECT oid FROM inv_locations LOOP
dev'> val := rec.oid;
dev'> END LOOP;
dev'> RETURN val;
dev'> END;' LANGUAGE 'plpgsql';
CREATE
dev=> select test();
test
--------
534321
(1 row)

Did not see your declare etc but this one works. Returns the final oid for
that table

HTH

Darren Ferguson

On Mon, 25 Mar 2002, Oberpriller, Wade D. wrote:

> How does one access a field in a record from a query like so:
>
> FOR REC IN SELECT myTable.oid FROM myTable, yourTable WHERE (myTable.id =
> yourTable.id) LOOP
> VAL := REC.oid;
> VAL := REC.myTable.oid;
> END LOOP;
>
> I get errors in PLPGSQL compilation for both the assignment statements
> above. What is the correct way to get the myTable oid in the REC record?
>
> Wade Oberpriller http://www.storagetek.com
> Software Development Phone: (763) 424-1538
> StorageTek: MRDC (800) 328-9108 ext. 1538
> wade_oberpriller(at)storagetek(dot)com Fax: (763) 391-1095
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas F. O'Connell 2002-03-25 17:50:32 Re: logging all queries in 7.1.3
Previous Message Oberpriller, Wade D. 2002-03-25 16:20:58 accessing fully qualified fields in records in PLPGSQL?