[ https://issues.apache.org/jira/browse/DERBY-6948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16074772#comment-16074772 ]
Lukas Eder commented on DERBY-6948: ----------------------------------- >From the description, I wasn't sure if this issue is the same as >https://issues.apache.org/jira/browse/DERBY-3439 or >https://issues.apache.org/jira/browse/DERBY-4015 > INSERT .. SELECT produces NULL for getGeneratedKeys() > ----------------------------------------------------- > > Key: DERBY-6948 > URL: https://issues.apache.org/jira/browse/DERBY-6948 > Project: Derby > Issue Type: Bug > Components: JDBC > Affects Versions: 10.13.1.1 > Reporter: Lukas Eder > > The following code: > {code} > import java.sql.Connection; > import java.sql.PreparedStatement; > import java.sql.ResultSet; > import java.sql.Statement; > import org.apache.derby.jdbc.EmbeddedDataSource; > public class Derby { > public static void main(String[] args) throws Exception { > EmbeddedDataSource ds; > ds = new EmbeddedDataSource(); > ds.setDatabaseName("memory:test;create=true"); > try (Connection con = ds.getConnection(); > Statement s = con.createStatement()) { > s.execute( > "CREATE TABLE test (" > + "id INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY," > + "name VARCHAR(255))"); > try (PreparedStatement ps = con.prepareStatement("insert into > test (name) select 'a' from sysibm.sysdummy1", > Statement.RETURN_GENERATED_KEYS)) { > ps.executeUpdate(); > try (ResultSet rs = ps.getGeneratedKeys()) { > while (rs.next()) > System.out.println("GEN_ID: " + rs.getObject(1)); > } > } > try (PreparedStatement ps = con.prepareStatement("insert into > test (name) select 'a' from sysibm.sysdummy1", > Statement.RETURN_GENERATED_KEYS)) { > ps.executeUpdate(); > try (ResultSet rs = ps.getGeneratedKeys()) { > while (rs.next()) > System.out.println("GEN_ID: " + rs.getObject(1)); > } > } > try (ResultSet rs = s.executeQuery("select id from test")) { > while (rs.next()) > System.out.println(" ID: " + rs.getObject(1)); > } > } > } > } > {code} > Produces this output: > {code} > GEN_ID: null > GEN_ID: null > ID: 1 > ID: 2 > ID: 3 > {code} > The expected output would be: > {code} > GEN_ID: 1 > GEN_ID: 2 > GEN_ID: 3 > ID: 1 > ID: 2 > ID: 3 > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)