473,394 Members | 1,371 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,394 software developers and data experts.

Trigger function aborts the transaction on exception

Hi:
I came to know from the postgresql documentation that PostgreSQL does not have a very smart exception handling model. I wonder whether anyone can helpme or suggest some alternate solution for the problem stated below:

I have a trigger function defined for the insert and iam executing sql statement as:

insert into target_table select * from source_table;

Now there could be scenario that in some record error occured due to the typecast of char ---> numeric (e.g if it try to insert alphanumeric characters in the numeric datatype ) therefore i want to catch the execption and want to make it entry in some other table but my process of insertion for the other records should go on as they have valid records. But it throws the exception and aborts the transaction.

Please help me and suggest some solution for this problem.

Thanks in advance.

Rajat.

Nov 23 '05 #1
1 3087
On Sat, Feb 28, 2004 at 03:21:25PM +0530, Rajat Katyal wrote:
insert into target_table select * from source_table;

Now there could be scenario that in some record error occured due to
the typecast of char ---> numeric (e.g if it try to insert
alphanumeric characters in the numeric datatype ) therefore i want to
catch the execption and want to make it entry in some other table but
my process of insertion for the other records should go on as they
have valid records. But it throws the exception and aborts the
transaction.
Add a where condition to only add lines that are numbers. For example:

insert into target_table select * from source_table where field ~ '^[0-9.]+$';

Hope this helps,
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ If the Catholic church can survive the printing press, science fiction
will certainly weather the advent of bookwarez.
http://craphound.com/ebooksneitherenorbooks.txt - Cory Doctorow


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAQGzYY5Twig3Ge+YRAu5YAKCXqHUdkcA5QBJr5cX5nB RZumcuPgCZAQGf
i11wyDRhf/bodZzFGDmGEdk=
=WsuM
-----END PGP SIGNATURE-----

Nov 23 '05 #2

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

Similar topics

1
by: RobertGl | last post by:
Hi everybody! My problem is as following: I have a trigger which fires on delete of a table row. The body of the trigger checks and manipulates entries in other tables. If the entries have...
0
by: Mark Vuksani | last post by:
Hi, I have a trigger like this (simplified to illustrate the problem): -------- CREATE TRIGGER Test ON . FOR INSERT, UPDATE, DELETE AS RAISERROR( 'test trigger error !', 16, 1)
11
by: Peter Childs | last post by:
Is it possible to deferr a trigger until commit, Or to have the trigger not occur if the transaction is rolled back? Like transaction. I think its possible since constraints use triggers and if so...
3
by: ChrisN | last post by:
Hello all, I have a quick question. I'm using a C# object to commit new rows to a database. In the database I have an INSERT Trigger watching values come in. If the record to be committed...
1
by: Terry Lee Tucker | last post by:
Hi, I have a simple question. I have been looking at the HTML docs for Postgres version: PostgreSQL 7.2.3-RH on i686-pc-linux-gnu, compiled by GCC 2.96. I need to know if it is necessary to...
0
by: Rajat Katyal | last post by:
----- Original Message ----- From: Rajat Katyal To: pgsql-jdbc@postgresql.org Sent: Saturday, January 31, 2004 10:15 AM Subject: Trigger function aborts the transaction on exception Hi:...
1
by: Robert Fitzpatrick | last post by:
I am running PostgreSQL 7.4.5 and have a trigger on a table called tblriskassessors which inserts, updates or delete a corresponding record in tblinspectors by lookup of a contact id and license...
1
by: DennBen | last post by:
I am doing an update to set a field value = anothe field value (in the same table) where it is not supplied. I'm handling this in the trigger, but am getting deadlocks. Do you see anything...
1
by: djdevx | last post by:
Dear all PostgreSQL xperts! Hi, I am newbie in PostgreSQL. I am currently developing an app that use PostgreSQL as a BackEnd Database. Now I am having problem with the function trigger since last...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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...

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.