cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert a bytestring into HANA table

Former Member
0 Kudos

Hi! I'm trying to insert a row into my table that is formatted like this:

CREATE TABLE test (COL1 VARBINARY, COL2 VARBINARY)

I tried two insert statements that look like this:

insert into TESTBYTE values(
"b'708ca7fbb701799bb387f2e50deaca402e8502abe229f705693d2d4f350e1ad6'", "b'G\xa2ac\xa0av\xf6'"
);
insert into TESTBYTE values( 
CAST('708ca7fbb701799bb387f2e50deaca402e8502abe229f705693d2d4f350e1ad6'ASVARBINARY), 
CAST('G\xa2ac\xa0av\xf6'ASVARBINARY)
);

The first one errors out as a syntax error and the second seems to be converting the given string into binary again. Is there any way to do this properly? Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

pfefferf
Active Contributor
0 Kudos

Hello Anton,

as the documentation says binary strings have to be prefix with an X and the binary value has to be enclosed in single quotes (please check paragraph binary string contants in the documentation).

In addition I think you will not be able to insert your binary value in the table with the current definition. That's because you have not defined a length for the VARBINARY type, so the default is 1 byte (which is to small for the content to be inserted).

Regards,
Florian

Former Member
0 Kudos

Hi Florian,

Thanks for your response. I tried that out and made my query:

INSERT INTO TESTBYTE VALUES(
    X'708ca7fbb701799bb387f2e50deaca402e8502abe229f705693d2d4f350e1ad6',
    X'\xa2ac\xa0av\xf6'
);

But I am still getting a syntax error. Any ideas?

Thanks again!

Anton

pfefferf
Active Contributor
0 Kudos

Please can you share the error (error message, screenshot, etc.), instead of just saying you get an error 🙂

Former Member
0 Kudos

Of course. The error I got for the above query is as such:

pfefferf
Active Contributor
0 Kudos

The issue is, that '\xa2ac\xa0av\xf6'is not a valid binary string. The value is checked before it is inserted into a VARBINARY column. The value which you try to insert in the first column is a valid binary string, therefore you do not get an error for it.

Regards,
Florian

lbreddemann
Active Contributor
0 Kudos

Also discussed on SO...