abs() does not exists..

Started by mazzoalmost 25 years ago5 messagesgeneral
Jump to latest
#1mazzo
jambo@aruba.it

Hi all..i'm trying to create a trigger that fires before i insert a value into a column and if the value i insert is negative, it will change it to positive...
I was trying with:

create trigger postv before insert on my_table for each row execute procedure abs (column);

But this doesn't seem to work and gives me the error i wrote in the subject...

Can anyone help me out please..??
Sorry if i post here but i looked on deja.com but i didn't find anything..

Thanks in advance..

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: mazzo (#1)
Re: abs() does not exists..

Trigger functions take no arguments (their arguments
are passed in differently) and return opaque.
That's why it's looking for abs() rather than
abs(<type>).

Write a plpgsql trigger function that makes the
change to the value.

On Tue, 12 Jun 2001, mazzo wrote:

Show quoted text

Hi all..i'm trying to create a trigger that fires before i insert a
value into a column and if the value i insert is negative, it will
change it to positive... I was trying with:

create trigger postv before insert on my_table for each row execute
procedure abs (column);

But this doesn't seem to work and gives me the error i wrote in the
subject...

Can anyone help me out please..?? Sorry if i post here but i looked on
deja.com but i didn't find anything..

Thanks in advance..

#3Peter Eisentraut
peter_e@gmx.net
In reply to: mazzo (#1)
Re: abs() does not exists..

mazzo writes:

Hi all..i'm trying to create a trigger that fires before i insert a value into a column and if the value i insert is negative, it will change it to positive...
I was trying with:

create trigger postv before insert on my_table for each row execute procedure abs (column);

But this doesn't seem to work and gives me the error i wrote in the subject...

Trigger procedures and regular functions cannot be mixed. You need to
write a special procedure that takes the old value and alters it to your
liking. See programmer's guide how to write trigger functions. PL/pgSQL
is probably best.

Sorry if i post here but i looked on deja.com but i didn't find anything..

There are mailing list archives on the postgresql.org site and at
geocrawler.com.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#4Bruno Wolff III
bruno@wolff.to
In reply to: Peter Eisentraut (#3)
Re: abs() does not exists..

On Wed, Jun 13, 2001 at 12:11:42AM +0200,
Peter Eisentraut <peter_e@gmx.net> wrote:

mazzo writes:

Hi all..i'm trying to create a trigger that fires before i insert a value into a column and if the value i insert is negative, it will change it to positive...

Couldn't you do this using a rule to update the table and a constraint on
the table to prevent bad data from getting into the table without using the
rule?

#5rob
rob@cabrion.com
In reply to: mazzo (#1)
Re: abs() does not exists..

How about a trigger/function that does this:

if val < 0 then val = val * -1

--rob

----- Original Message -----
From: "Bruno Wolff III" <bruno@wolff.to>
To: "Peter Eisentraut" <peter_e@gmx.net>
Cc: "mazzo" <jambo@aruba.it>; <pgsql-general@postgresql.org>
Sent: Wednesday, June 13, 2001 10:45 AM
Subject: Re: abs() does not exists..

On Wed, Jun 13, 2001 at 12:11:42AM +0200,
Peter Eisentraut <peter_e@gmx.net> wrote:

mazzo writes:

Hi all..i'm trying to create a trigger that fires before i insert a

value into a column and if the value i insert is negative, it will change it
to positive...

Couldn't you do this using a rule to update the table and a constraint on
the table to prevent bad data from getting into the table without using

the

Show quoted text

rule?