BUG #8027: Get generated key value while inserting in partitioned table - Mailing list pgsql-bugs

From mohansammeta@gmail.com
Subject BUG #8027: Get generated key value while inserting in partitioned table
Date
Msg-id E1UMvNP-0002z1-Fr@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #8027: Get generated key value while inserting in partitioned table  (bricklen <bricklen@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      8027
Logged by:          mohan sammeta
Email address:      mohansammeta@gmail.com
PostgreSQL version: 8.4.0
Operating system:   ubuntu
Description:        =




Hi I have a table in Postgres, say email_messages. It is partitioned so
whatever the inserts i do it using my java application will not effect the
master table, as the data is actually getting inserted in the child tables.
Here is the problem, I want to get an auto generated column value (say
email_message_id which is of big serial type). Postgres is returning it as
null since there is no insert being done on master table. For oracle I used
GeneratedKeyHolder to get that value. But I'm unable to do the same for
partitioned table in postgres. Please help me out.

Here is the code snippet we used for oracle

public void createAndFetchPKImpl(final Entity pEntity, final String
pStatementId, final String pPKColumnName) {

final SqlParameterSource parameterSource =3D
  new BeanPropertySqlParameterSource(pEntity);

  final String[] columnNames =3D new String[]{"email_message_id"};
  final KeyHolder keyHolder =3D new GeneratedKeyHolder();
  final int numberOfRowsEffected =3D mNamedParameterJdbcTemplate.update(
      getStatement(pStatementId), parameterSource, keyHolder, columnNames);
  pEntity.setId(ConversionUtil.getLongValue(keyHolder.getKey()));

}
We are using spring 3.1.1.
I am getting numberOfRowsEffected as zero and keyHolder.getKey() as null
even though the insert is happening in the table.

pgsql-bugs by date:

Previous
From: Andres Freund
Date:
Subject: Re: Completely broken replica after PANIC: WAL contains references to invalid pages
Next
From: bricklen
Date:
Subject: Re: BUG #8027: Get generated key value while inserting in partitioned table