Re: Problem with function & trigger

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: carlino(at)ilrspa(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with function & trigger
Date: 2001-07-07 19:28:06
Message-ID: 29529.994534086@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Carlo Vitolo <carlino(at)ilrspa(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-07-07 23:12:49 Re: creating variable views
Previous Message Tom Lane 2001-07-07 19:11:15 Re: creating variable views