Unix Technical Forum

Re: error handling

This is a discussion on Re: error handling within the pgsql Novice forums, part of the PostgreSQL category; --> Hello, sorry for answering so late, ... > I do not know if there is an specific error handler ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 09:51 PM
Verena Ruff
 
Posts: n/a
Default Re: error handling

Hello,

sorry for answering so late, ...
> I do not know if there is an specific error handler built in postgresql (besides error-codes).
>
> If you break the unique constraint an error will be thrown. A
> workaround may be to launch a trigger BEFORE the insertion and do whatever is necessary within the trigger.
>

This is possibillity I was thinking of, too. But if there are many
inserts and (probably) only a few of them would break the unique
constraint, there would be a great overhead. This was what I'd like to
avoid with a custom error handler.

Regards,
Verena



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 09:51 PM
Sean Davis
 
Posts: n/a
Default Re: error handling




On 5/10/06 9:35 AM, "Verena Ruff" <lists@triosolutions.at> wrote:

> Hello,
>
> sorry for answering so late, ...
>> I do not know if there is an specific error handler built in postgresql
>> (besides error-codes).
>>
>> If you break the unique constraint an error will be thrown. A
>> workaround may be to launch a trigger BEFORE the insertion and do whatever is
>> necessary within the trigger.
>>

> This is possibillity I was thinking of, too. But if there are many
> inserts and (probably) only a few of them would break the unique
> constraint, there would be a great overhead. This was what I'd like to
> avoid with a custom error handler.


Probably the simplest way to do this is to load the data into a temporary
table without the unique constraint then use SQL to insert a "clean" version
into the new table. Alternatively, you could use savepoints. If an insert
fails, just rollback to that savepoint. If it succeeds, commit that
savepoint.

Sean


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 09:51 PM
Verena Ruff
 
Posts: n/a
Default Re: error handling

Hi,

Sean Davis schrieb:
> Probably the simplest way to do this is to load the data into a temporary
> table without the unique constraint then use SQL to insert a "clean" version
> into the new table. Alternatively, you could use savepoints. If an insert
> fails, just rollback to that savepoint. If it succeeds, commit that
> savepoint.
>

But isn't that more overhead than using the trigger? And while inserting
into the clean table, I would have to test if the value is existing or
not. I don't see the advantage of this compared to the script which was
posted a few weeks ago.

Regards,
Verena

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

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 09:51 PM
Sean Davis
 
Posts: n/a
Default Re: error handling




On 5/10/06 9:09 AM, "Verena Ruff" <lists@triosolutions.at> wrote:

> Hi,
>
> Sean Davis schrieb:
>> Probably the simplest way to do this is to load the data into a temporary
>> table without the unique constraint then use SQL to insert a "clean" version
>> into the new table. Alternatively, you could use savepoints. If an insert
>> fails, just rollback to that savepoint. If it succeeds, commit that
>> savepoint.
>>

> But isn't that more overhead than using the trigger? And while inserting
> into the clean table, I would have to test if the value is existing or
> not.


If you are copying bulk data into the table only once, then cleaning the
data up front will not impact your actual use down the road. If you are
saying that you will be inserting non-unique values and need to catch that,
a trigger is the better way to go. As for testing if the value is existing
or not, you can avoid that by using SQL functions (like the postgresql
specific distinct on) to select from the temporary table only those values
that are unique. See here in the docs:

http://www.postgresql.org/docs/8.1/i...l#SQL-DISTINCT

> I don't see the advantage of this compared to the script which was
> posted a few weeks ago.


I should have pointed out that the solution depends on your needs. If you
don't see an advantage, it is likely because there isn't one for your
particular needs, so feel free to use some other option.

Sean


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

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com