开发者

invalid hexadecimal data: odd number of digits [PostgreSQL]

I'm using PostgreSQL 9

When trying to insert data, i got something wrong.

This is working

INSERT INTO unicode_blocks_bytea(
        a, z, bl开发者_开发百科ock_name)
VALUES 
(decode('FE50','hex'), decode('FE6F','hex'), 'Small Form Variants')

but this is not, i got error :

INSERT INTO unicode_blocks_bytea(
        a, z, block_name)
VALUES 
(decode('10000','hex'), decode('1007F','hex'), 'Linear B Syllabary')

the error is :

ERROR:  invalid hexadecimal data: odd number of digits
********** Error **********
ERROR: invalid hexadecimal data: odd number of digits
SQL state: 22023

What's wrong ?


It appears that you are trying to convert from hex to decimal. In this case, try this:

select x'10000'::integer

Result is

65536

Also

select x'1007f'::integer

Result is

65663

encode and decode are slightly different. For example:

select decode('FE50','hex')

produces

\376P

Is this what you want? I think you should say

select x'FE50'::integer

which gives you

65104

This is probably what you want because you seem to be recording the starting and ending codepoints of Unicode blocks. I susepect the idea is you are trying to find the block for a given codepoint and for this you will want the integer values.

It is true that encode/decode don't like strings with an odd number of characters, but I don't think that is what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜