Re: Why this does not work ?? - Mailing list pgsql-novice

From Jason Davis
Subject Re: Why this does not work ??
Date
Msg-id 5.1.0.14.0.20040702153706.0270b8f0@mail.bigpond.com
Whole thread Raw
In response to Why this does not work ??  (Roberto Rezende de Assis <rezende_assis@yahoo.com.br>)
List pgsql-novice
>Hello all, why this does not work ?
>
>-----------------------------------------
>create table original(num int);
>-----------------------------------------
>create table copia(num int);
>-----------------------------------------
>insert into original(num) values (1);
>insert into original(num) values (2);
>insert into original(num) values (3);
>-----------------------------------------
>create function copiar()
>    returns int as '
>    declare
>        ponteiro int;
>    begin
>        for ponteiro in select * from original order by num asc loop
>            insert into copia(num) values(ponteiro);
>        end loop;
>        return 1;
>    end;
>    ' language plpgsql;
>-----------------------------------------
>-----------------------------------------
>-----------------------------------------

Try this...

create function copiar()
    returns int as '
    declare
        ponteiro record;
    begin
        for ponteiro in select * from original order by num asc loop
            insert into copia(num) values(ponteiro.num);
        end loop;
        return 1;
    end;
    ' language plpgsql;

cheers
Jason




pgsql-novice by date:

Previous
From: Vitaly Belman
Date:
Subject: Storage space lost during an UPDATE
Next
From: vera schulze
Date:
Subject: PostgreSQL with Esri SDE