Re: function problem - Mailing list pgsql-sql

From Tom Lane
Subject Re: function problem
Date
Msg-id 5306.1066763319@sss.pgh.pa.us
Whole thread Raw
In response to function problem  ("geraldo" <geraldo@umc.br>)
List pgsql-sql
"geraldo" <geraldo@umc.br> writes:
> Can anybody tell me why the following code when activated
> by a select only affects the first line of the table???
> create or replace function increase(integer)
> returns void as 'update tab set price=price*(1+$1/100.0)' 
> language sql;

Works fine here.

regression=# create table tab (price numeric);
CREATE TABLE
regression=# insert into tab values(1);
INSERT 154584 1
regression=# insert into tab values(10);
INSERT 154585 1
regression=# insert into tab values(100);
INSERT 154586 1
regression=# select * from tab;price
-------    1   10  100
(3 rows)

regression=# create or replace function increase(integer)
regression-# returns void as 'update tab set price=price*(1+$1/100.0)'
regression-# language sql;
CREATE FUNCTION
regression=# select increase(42);increase
----------

(1 row)

regression=# select * from tab;         price
--------------------------  1.42000000000000000000 14.20000000000000000000142.00000000000000000000
(3 rows)

regression=#
        regards, tom lane


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: [GENERAL] Alias-Error
Next
From: Stephan Szabo
Date:
Subject: Re: plpgsql related question: intervals and variables