On Wed, 2022-05-25 at 22:25 -0700, 'Balamurali Krishna Ippili' via H2
Database wrote:
> Hi Team,
> 
> We have a requirement where we are executing an sql script on h2 db
> and there is a primary key constraint on the table and if there is
> any single failure in the script is stop executing the rest of the
> script. How can we allow the java program to ignore the failed query
> and continue with rest of the script execution?

Greetings,

while I am not a H2 developer, but just a user I would like to advise
the following approach:

1) Do not rely on ignoring duplicates, but filter for distinct by using
GROUP BY and Min(_rowid_) or Max(_rowid)

2) Example:

DELETE FROM cfe.instrument_attribute
WHERE ( id_instrument, id_attribute, _rowid_ ) IN ( SELECT  id_instrument
                                                            , id_attribute
                                                            , Min( _rowid_ )
                                                    FROM 
cfe.instrument_attribute
                                                    GROUP BY    id_instrument
                                                                , id_attribute
                                                    HAVING Count( * ) > 1 )
;

The example above would ensure a UNBIQUE KEY (id_instrument,
id_attribute) in table cfe.instrument_attribute (although you would
need to repeat that delete until no row is returned).

Good luck
Andreas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/23f46631af09f2415f879d6aab19b5a639107ef7.camel%40manticore-projects.com.

Reply via email to