473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Syntax Issue in Trigger Function??

In Postgres 7.3.5 -
When we try to insert a new record into our parties.party table which
is then meant to fire off a trigger to update a column in the table
with some de-normalised information, we get the following error:
ERROR: FLOATING POINT EXCEPTION! The last floating point operation
either exceeded the legal ranges or was a divide by zero.

Can someone help spot our syntax erorr, please?

Many thanks!

===============================================
CREATE TABLE parties.party
(
party_id serial NOT NULL,
parent_party_id int4,
party_type char(1) NOT NULL,
party_name text NOT NULL,
party_path text,
modified_by text,
modified_dtm timestamp,
created_by text,
created_dtm timestamp
);
===============================================
CREATE OR REPLACE FUNCTION parties.update_party_ref()
RETURNS trigger AS
' DECLARE
v_party_id INTEGER;
v_parent_party_id INTEGER;
v_ref TEXT;

BEGIN
/* from the end to the beginning (i.e backwards)
navigate up the tree of parties adding the party
ids separated by the backslash character */

-- we always start with backslash
v_ref := \'\'/\'\';

-- grab the first party id to look at
v_party_id := new.party_id;

-- set the loop up with an initial read
SELECT INTO v_parent_party_id parent_party_id FROM parties.party
WHERE party_id = v_party_id AND parent_party_id IS NOT NULL;

WHILE FOUND LOOP
-- prefix the ref weve already accumulated with backslash followed
by the parent party id
v_ref := \'\'/\'\' || v_parent_party_id || v_ref;

-- the parent party id now becomes the party id one level up
v_party_id := v_parent_party_id;

-- look for more parents
SELECT INTO v_parent_party_id parent_party_id FROM parties.party
WHERE party_id = v_party_id AND parent_party_id IS NOT NULL;
END LOOP;

-- now we can perform the update
update parties.party set party_path = v_ref;

RETURN NULL;
END;

'
LANGUAGE 'plpgsql' VOLATILE;
===============================================
CREATE TRIGGER trg_update_party_ref
AFTER INSERT OR UPDATE
ON parties.party
FOR EACH ROW
EXECUTE PROCEDURE parties.update_party_ref();
===============================================

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
3 1613
ts*******@gmail.com wrote:
In Postgres 7.3.5 -
When we try to insert a new record into our parties.party table which
is then meant to fire off a trigger to update a column in the table
with some de-normalised information, we get the following error:
ERROR: FLOATING POINT EXCEPTION! The last floating point operation
either exceeded the legal ranges or was a divide by zero.

Can someone help spot our syntax erorr, please?
This looks to me like a candidate: v_ref := \'\'/\'\'; Without escaping it looks like v_ref := ''/'';
dividing 2 empty strings, and indeed gives
division by zero in psql. What dividing 2 strings is actually
supposed to mean is not evident form the docs in the first glance.
v_ref := \'\'/\'\' || v_parent_party_id || v_ref;


This one too.

Andre

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2
Andre Maasikas <an************@abs.ee> writes:
Without escaping it looks like v_ref := ''/'';
dividing 2 empty strings, and indeed gives
division by zero in psql. What dividing 2 strings is actually
supposed to mean is not evident form the docs in the first glance.


This is a pet peeve of mine that I unfortunately forgot to do anything
about before 8.0 beta started; so it's too late for this release, unless
there is another reason for forcing initdb before final. The problem is
that the "char" type (not to be confused with CHAR(n) type) has basic
arithmetic operators defined, and since it is considered a member of the
STRING type class, these operators get selected whenever a couple of
undecorated strings are provided.

Try these on for size :-(

regression=# select '2' + '2';
?column?
----------
d
(1 row)

regression=# select 'A' * 'B';
?column?
----------
ô
(1 row)

regression=# select '1' / '';
ERROR: division by zero

Given the one-byte precision, these operators are surely of pretty
marginal use. I'd leave 'em alone if it weren't that the type coercion
rules cause the parser to seize on these operators in cases where a "no
operator could be identified" error would be far more appropriate.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #3
Cheers for that! We did catch it eventually. My colleague was using
pgAdminIII and was apparently typing:
v_ref := ''/'';
and pgAdminIII "appears" to have been "helping out" by escaping the
single quotes.
On Tue, 28 Sep 2004 22:46:31 +0300, Andre Maasikas
<an************@abs.ee> wrote:
ts*******@gmail.com wrote:
In Postgres 7.3.5 -
When we try to insert a new record into our parties.party table which
is then meant to fire off a trigger to update a column in the table
with some de-normalised information, we get the following error:
ERROR: FLOATING POINT EXCEPTION! The last floating point operation
either exceeded the legal ranges or was a divide by zero.

Can someone help spot our syntax erorr, please?


This looks to me like a candidate:
v_ref := \'\'/\'\';

Without escaping it looks like v_ref := ''/'';
dividing 2 empty strings, and indeed gives
division by zero in psql. What dividing 2 strings is actually
supposed to mean is not evident form the docs in the first glance.
v_ref := \'\'/\'\' || v_parent_party_id || v_ref;


This one too.

Andre


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
8
by: BobTheDatabaseBoy | last post by:
the following syntax is accepted: alter table DB2ADMIN.APPTS add constraint appts_status check (lob_appt_status in ( case when state_code = 'VA' then 'P' -- , 'I' else 'X'
7
by: peter.morin | last post by:
Issue: I am inserting an Oracle record containing insert trigger via Access 2002 using the code below. The issue is that the sequence from the acSaveRecord is not reflected after the insert so...
18
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you...
20
by: W Karas | last post by:
Would the fear factor for concepts be slightly reduced if, instead of: concept C<typename T> { typename T::S; int T::mem(); int nonmem(); };
0
by: chappy | last post by:
Hi, I'm new to DB2 from SQL Server, There's a problem with the syntax below, is anyone able to see what the issue is? CREATE TRIGGER AUDIT AFTER UPDATE ON ABEFORE REFERENCING OLD AS O FOR...
1
by: asf93555 | last post by:
Running under SQL2000 I can not get an INSTEAD trigger to function. I've even copied the example directl from books online - no joy . . . Server: Msg 170, Level 15, State 1, Procedure...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.