Search code examples
sql-inserthsqldb

How to insert a hex string to a longvarbinary column in hsql?


How to make this work in HSQL insert script? Image column datatype is longvarbinary.

insert into Item (ID, Image)
values (1, '0xFFD8FFE000104A464');

Solution

  • The binary literal format in SQL language has an X prefix outside the quoted string.

    Note the string must have an even number of characters. Your example will work if you add one character to make the string length even.

    insert into Item (ID, Image) values (1, X'FFD8FFE000104A4640');
    

    See http://www.hsqldb.org/doc/guide/dataaccess-chapt.html#dac_literals