473,667 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_part y_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 1631
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
3342
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 city_id 1 john newyork null
19
2964
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 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury <nidoizo at gmail.com> Status: Draft Type: Standards Track
8
4322
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. Basically I want to say: If fk_ID is in list then do these statements to that record
8
3322
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
3938
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 the insert into the second table section: ' Copy LOB entries now. fails on unique index constraint (understandable because it has the orig rate_id). The strange thing is that it works fine for new records that have beend added and then...
18
2940
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 have a local identical variable name and want to save/load it to/from the global with same name * while you add code, the definition of globals moves more and more apart from their use cases -> weirdness; programmers thinking is fragmented * using...
20
2586
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
1219
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 EACH ROW MODE DB2SQL WHEN ('YES' IN SELECT CONTROLFLAG FROM TRIGGERCONTROL WHERE TRIGGERNAME = 'AUDIT') BEGIN ATOMIC
1
3193
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 IO_Trig_INS_Employee, Line 2 Line 2: Incorrect syntax near 'INSTEAD'. CREATE TABLE Person ( SSN char(11) PRIMARY KEY, Name nvarchar(100), Address nvarchar(100),
0
8458
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8366
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.