Dropping unique constraint for column in H2
In the SQL language, identifier names can't be expressions. You need to run two statements:
select distinct constraint_name from information_schema.constraints
where table_name='PUBLIC_PARTNER' and column_list='INFO'
and then get the identifier name, and run the statement
ALTER TABLE PUBLIC_PARTNER DROP CONSTRAINT <xxx>
You could use a user defined function to execute a dynamically created statement. First to create the execute
alias (only once):
CREATE ALIAS IF NOT EXISTS EXECUTE AS $$ void executeSql(Connection conn, String sql)
throws SQLException { conn.createStatement().executeUpdate(sql); } $$;
Then to call this method:
call execute('ALTER TABLE PUBLIC_PARTNER DROP CONSTRAINT ' ||
(select distinct unique_index_name from in formation_schema.constraints
where table_name='PUBLIC_PARTNER' and column_list='INFO'));
... where execute
is the user defined function that runs a statement.