This is the query:
UPDATE einvoice_message AS e1
SET message = null
FROM (
SELECT *
FROM einvoice_message
where created < :created
ORDER BY :created LIMIT :limit
FOR UPDATE SKIP LOCKED
) AS e2
WHERE e1.einvoice_message_id = e2.einvoice_message_id
RETURNING e1.einvoice_message_id
I'm getting SqlExceptionHelper - The column name created was not found in this ResultSet.
Don't understand why and where? Need help.
Java code:
@Query(value = "UPDATE einvoice_message AS e1 SET message = null FROM (SELECT * FROM einvoice_message
where created < :created ORDER BY :created LIMIT :limit FOR UPDATE SKIP LOCKED) AS e2 WHERE
e1.einvoice_message_id = e2.einvoice_message_id RETURNING e1.einvoice_message_id", nativeQuery = true)
List<EinvoiceMessage> deleteEinvoiceMessageContent(@Param("created") OffsetDateTime created,
@Param("limit") int limit);
Here is my table ddl:
create table einvoice_message
(
einvoice_message_id bigserial not null
constraint einvoice_message_pk
primary key,
message bytea not null,
created timestamp default now() not null
);
Changing :created
variable to column created
didn't solve the issue.
The problem was with the return value of this. RETURNING e1.einvoice_message_id
will return a number not a List as I've mentioned. The correct answer would be:
@Query(value = "UPDATE einvoice_message AS e1 SET message = null FROM (SELECT * FROM einvoice_message
where created < :created ORDER BY :created LIMIT :limit FOR UPDATE SKIP LOCKED) AS e2 WHERE
e1.einvoice_message_id = e2.einvoice_message_id RETURNING e1.einvoice_message_id", nativeQuery = true)
int deleteEinvoiceMessageContent(@Param("created") OffsetDateTime created,
@Param("limit") int limit);