Re: Using the database to validate data - Mailing list pgsql-general

From JPLapham
Subject Re: Using the database to validate data
Date
Msg-id 1437745892647-5859237.post@n5.nabble.com
Whole thread Raw
In response to Re: Using the database to validate data  (林士博 <lin@repica.co.jp>)
Responses Re: Using the database to validate data
List pgsql-general
林士博 wrote
> If I am following correctly, you can do it in your application as follows.
> 1.begin transaction
> 2.insert each data. Catch db exception,
> and save exception message and other information you need to array.
> 3.in the end ,you can get all the information about the wrong data in
> array
> if there is any.
>    and then you can decide whether it is need to rollback or to commit.

Yes, I agree that I could do that, which I believe is my "IDEA 1" from my
original message. This method will naturally work, but it is a very slow
iterative process because you can only catch the *first* error, after which
new INSERTS are not allowed. If you have a data input with say 1000 record,
and there are 50 errors, it would require 50 iterations of fixing the input
data, running it again, to find them all.


林士博 wrote
> By the way, this is about programming but not postgresql.

I was hoping that there would be a way to have Postgresql run in a mode
where it allows INSERTS within a transaction even after an error. Naturally
when the error condition occurs, COMMIT would not be allowed at the end of
the transaction block.

But, this way, you could collect all the error information in one pass.
Seemed postgresql related to me.  :)



--
View this message in context: http://postgresql.nabble.com/Using-the-database-to-validate-data-tp5859046p5859237.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Tim Smith
Date:
Subject: Re: Delete rule does not prevent truncate
Next
From: JPLapham
Date:
Subject: Re: Using the database to validate data