Repository: h2database/h2database

Issue #3962: Add support for PostgreSQL returning 
Created: 2024-01-12T12:49:37Z
It is a very often situation when it is necessary to get some information after INSERT/UPDATE queries. Postgresql supports it via returning  . At the same time H2 in PostgreSQL mode doesn't support it.
So, I suggest to add such support so it could be possible to test returning using H2.

Duplicate issue #4141: Syntax error with MODE=PostgreSQL with insert into returning  
Created: 2024-10-15T08:11:19Z
I have a strange error in an insert into (prepared statement).
My table (in PostgreSQL) is defined as
CREATE TABLE customer (
	customer_id integer NOT NULL generated by default as Identity,
	val000_id integer NULL,
	customer_code varchar(11) NULL, 
	business_name varchar(255) NOT NULL,
	vat_number varchar(11) NULL, 
	tax_code varchar(16) NULL, 
	ateco_code varchar(6) NULL,
	sales_volume numeric(15, 2) DEFAULT NULL::numeric NULL,
        customer_type varchar(10) DEFAULT NULL::character varying NULL, 
	customer_status varchar(100) DEFAULT NULL::character varying NULL,
	legal_status varchar(255) DEFAULT NULL::character varying NULL,
	creation_date date NULL, 
        end_validity_date date NULL
);

I googled as much as I could and I found that the returning statement should be fully implemented at least since H2 2.0.202 so I decided to use h2 for my integration tests.
Now, using hibernate (it's actually a spring-boot 3.3 application), I am trying to insert data into the table and the (generated) prepared statement throws a Systax Errror.
The Insert into statement :
insert into customer (ateco_code,business_name,creation_date,customer_code,customer_status,customer_type,end_validity_date,legal_status,sales_volume,tax_code,val000_id,vat_number) values (?,?,?,?,?,?,?,?,?,?,?,?) returning customer_id
The error code:  [42000-224]
The stack trace:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "insert into customer (ateco_code,business_name,creation_date,customer_code,customer_status,customer_type,end_validity_date,legal_status,sales_volume,tax_code,val000_id,vat_number) values (?,?,?,?,?,?,?,?,?,?,?,?) [*]returning customer_id"; SQL statement:
insert into customer (ateco_code,business_name,creation_date,customer_code,customer_status,customer_type,end_validity_date,legal_status,sales_volume,tax_code,val000_id,vat_number) values (?,?,?,?,?,?,?,?,?,?,?,?) returning customer_id [42000-224]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
	at org.h2.message.DbException.get(DbException.java:223)
	at org.h2.message.DbException.get(DbException.java:199)
	at org.h2.message.DbException.getSyntaxError(DbException.java:247)
	at org.h2.command.ParserBase.getSyntaxError(ParserBase.java:748)
	at org.h2.command.Parser.prepareCommand(Parser.java:486)
	at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
	at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
	at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
	at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:93)
	at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:1094)
	at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:335)
	at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java)
	at org.hibernate.engine.jdbc.internal.MutationStatementPreparerImpl$2.doPrepare(MutationStatementPreparerImpl.java:61)
	at org.hibernate.engine.jdbc.internal.MutationStatementPreparerImpl$StatementPreparationTemplate.prepareStatement(MutationStatementPreparerImpl.java:106)
	... 68 more

I can, for the time being, revert to development container and use postgres but I thought it might be worth asking here.
If you have any thought or need any other info, please let me know

Closing comment (2024-10-15T09:54:54Z): You must always use H2Dialect for H2 in Hibernate ORM, no matter which compatibility mode of H2 you use. Attempts to use any other dialects may lead to generation of invalid SQL.
H2 doesn't support PostgreSQL-style returning. H2 supports standard data change delta tables instead.
Duplicate of #3962.