Postgresql: Convert bytea to bigint

I need to convert the bytea entry for the request to bigint. How can I do that?

Additional Information:

I have a sleeping repository as shown below -

@Query(value = "update Sample_Table set other_id = ?1 where id = ?2", nativeQuery = true) void saveOrUpdateOtherId(Long other_id, Long id); 

Hibernate somehow accepts the id (in where where) as bytea , and since "Sample_Table" has this id field as bigint and thus causes a type mismatch problem.

I tried using CAST to convert bytea to bigint , but it failed, and the msg: bytea error message could not be sent to bigint .

How to change bytea to bigint ?


Edit:

Sample_Table DAO:

 @Table(name = "Sample_Table") public class Sample{ @Id @Column(name = "id", unique = true) @GeneratedValue private Long id; @Column(name = "other_id") private Long other_id; } 
Field

id defined here as Long.


Edit-2 If someone gets such a problem, most likely they will pass a null value in the request.

+5
source share
2 answers

It seems that there is no simple function to translate from a byte (a piece of memory) into a basic data type, other than passing through a data type bit from a correctly filled hexadecimal string:

 SELECT ('x'||lpad(encode('\001'::bytea, 'hex'), 16, '0'))::bit(64)::bigint 
0
source

One of your options is null , which cannot be converted to bigint .

0
source

Source: https://habr.com/ru/post/1232948/


All Articles