Carlo Vitolo <carlino@ilrspa.com> writes:
> This does not work. The error is ERROR: pg_atoi: error in "12.00": can't
> parse ".00"
What PG version are you running? It seems to work fine for me in
current sources:
regression=# create table magazzino (quantita numeric(10,2),
regression(# descrizione text);
CREATE
regression=# create table scarico (quantita numeric(10,2),
regression(# descrizione text);
CREATE
regression=# insert into magazzino values(100, 'test1');
INSERT 400688 1
regression=# insert into magazzino values(200, 'test2');
INSERT 400689 1
<< create functions and triggers copied from your mail >>
regression=# insert into scarico values(10.4, 'test1');
INSERT 400694 1
regression=# select * from magazzino ;quantita | descrizione
----------+------------- 200.00 | test2 89.60 | test1
(2 rows)
regression=# delete from scarico;
DELETE 1
regression=# select * from magazzino ;quantita | descrizione
----------+------------- 200.00 | test2 100.00 | test1
(2 rows)
BTW, the way you are writing the functions seems bizarrely inefficient.
Why not just:
CREATE FUNCTION "togliscar" () RETURNS opaque AS 'BEGIN
UPDATE magazzino SET quantita = quantita - NEW.quantita WHERE descrizione = NEW.descrizione;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
regards, tom lane