You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try (Statements = c.createStatement()) {
try {
s.executeUpdate("create table t (i int not null primary key, j int)");
try (PreparedStatementps = c.prepareStatement(
"merge into t using (select 1 x from rdb$database) on 1 = 1 "
+ "when matched then update set j = ? "
+ "when matched and i = ? then delete "
)) {
ps.setInt(1, 2);
ps.setInt(2, 1);
}
}
finally {
s.executeUpdate("drop table t");
}
}
Notice, the MERGE statement's second WHEN MATCHED clause doesn't really make any sense, because the first one matches all rows. Nevertheless, it seems to be valid syntax, and the second bind parameter marker should be accepted. Yet I get this exception:
Caused by: java.sql.SQLException: Invalid column index: 2
at org.firebirdsql.jdbc.AbstractPreparedStatement.getField(AbstractPreparedStatement.java:330)
at org.firebirdsql.jdbc.AbstractPreparedStatement.setInt(AbstractPreparedStatement.java:254)
at org.jooq.test.all.testcases.InsertUpdateTests.lambda$9(InsertUpdateTests.java:2889)
... 36 more
As a workaround, this seems to work:
try (Statements = c.createStatement()) {
try {
s.executeUpdate("create table t (i int not null primary key, j int)");
try (PreparedStatementps = c.prepareStatement(
"merge into t using (select 1 x from rdb$database) on 1 = 1 "
+ "when matched and 1 = 1 then update set j = ? "
+ "when matched and i = ? then delete "
)) {
ps.setInt(1, 2);
ps.setInt(2, 1);
}
}
finally {
s.executeUpdate("drop table t");
}
}
The text was updated successfully, but these errors were encountered:
When using the PSQL execute statement to execute this, it results in an equivalent error (Input parameters mismatch), so the problem in Firebird itself:
EXECUTE BLOCK
AS
BEGIN
EXECUTE STATEMENT ('merge into t using (select 1 x from rdb$database) on 1 = 1
when matched then update set j = ?
when matched and i = ? then delete') (2, 1);
END
Submitted by: Lukas Eder (lukas.eder)
Duplicates CORE6280
Consider this code:
Notice, the MERGE statement's second WHEN MATCHED clause doesn't really make any sense, because the first one matches all rows. Nevertheless, it seems to be valid syntax, and the second bind parameter marker should be accepted. Yet I get this exception:
As a workaround, this seems to work:
The text was updated successfully, but these errors were encountered: