Skip site navigation (1) Skip section navigation (2)

Re: pl/pgsql documentation

From: Darcy Buskermolen <darcy(at)ok-connect(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: pl/pgsql documentation
Date: 2001-01-26 03:13:06
Message-ID: 3.0.32.20010125191306.034ef4b0@mail.ok-connect.com (view raw or flat)
Thread:
Lists: pgsql-bugs
Ok this has since been sorted out, however I propose that it is better
layed out in the documentation, or at the veryleast an example is given.
i MUST be defined as a RECORD, and you then refrence the returned result as
RECORD.field, Also you can NOT have ()'s arouns the select statement.

CREATE FUNCTION test3(INT4) RETURNS INT4 AS '
  DECLARE
    loc  INT4;
    i    RECORD;
  BEGIN
    loc := $1;
    FOR i IN  SELECT id FROM major_groups LOOP
      loc := loc + i.id;
    END LOOP;
    RETURN loc;
  END;
' LANGUAGE 'plpgsql';

select test3(2);


>Short Description
>pl/pgsql documentation
>
>Long Description
>The following documentation does not apear to reflect real world use.
>
>[<<label>>]
>FOR record | row IN select_clause LOOP
>    statements
>END LOOP;
>
>(as snipped from
http://postgresql.readysetnet.com/users-lounge/docs/7.0/postgres/c40914117.h
tm)
>
>Sample Code
>CREATE TABLE major_groups(id SERIAL, name TEXT);
>INSERT INTO major_groups(name) VALUES 'one';
>INSERT INTO major_groups(name) VALUES 'two';
>INSERT INTO major_groups(name) VALUES 'three';
>
>CREATE FUNCTION test3(INT4) RETURNS INT4 AS '
>  DECLARE
>    loc  INT4;
>  BEGIN
>    loc := $1;
>    for i IN (select id from major_groups) loop
>      (
>      loc := $loc + $i;
>      )
>    end loop;
>    return $loc;
>  end;
>' language 'plpgsql';
>
>select test3(2);
>
>NOTICE:  plpgsql: ERROR during compile of test3 near line 10
>ERROR:  parse error at or near ";"
>
>
>No file was uploaded with this report
>
>
>

pgsql-bugs by date

Next:From: Tom LaneDate: 2001-01-26 03:45:44
Subject: Re: large objects overwriting bug
Previous:From: Karel ZakDate: 2001-01-26 02:31:55
Subject: Re: round - timestamp bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group