Skip to Content
0

How to insert a bytestring into HANA table

Jul 26, 2017 at 05:08 PM

47

avatar image
Former Member

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!

SQL
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Jul 26, 2017 at 07:44 PM
0

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

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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

0
Former Member
Florian Pfeffer

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

0

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

0

Also discussed on SO...

0