Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha family hash function errors when meetting '\' #13334

Closed
NiuBlibing opened this issue Nov 9, 2023 · 7 comments
Closed

sha family hash function errors when meetting '\' #13334

NiuBlibing opened this issue Nov 9, 2023 · 7 comments
Assignees
Labels
type/bug Something isn't working
Milestone

Comments

@NiuBlibing
Copy link
Contributor

Describe the bug

When using sha family hash with input containing '', it will failed.

Error message/log

ERROR:  QueryError: Expr error: Parse error: invalid input syntax for type bytea

To Reproduce

-- sha family hash failed
select sha1('\');
select sha224('\');
select sha256('\');
select sha384('\');
select sha512('\');

-- MD5 success
select md5('\');

Expected behavior

I expect sha family functions work well with ''.
Or support convert_to so we can convert the varchat to utf8 bytes.

How did you deploy RisingWave?

via docker risingwave playground: ./bin/risingwave playground

The version of RisingWave

PostgreSQL 9.5-RisingWave-1.3.0 (unknown)
risingwavelabs/risingwave latest 11a43456396f 2 weeks ago 4.81GB

Additional context

No response

@NiuBlibing NiuBlibing added the type/bug Something isn't working label Nov 9, 2023
@github-actions github-actions bot added this to the release-1.5 milestone Nov 9, 2023
@fuyufjh
Copy link
Member

fuyufjh commented Nov 9, 2023

Thanks for reporting this. Let me take a look.

@fuyufjh fuyufjh self-assigned this Nov 9, 2023
@fuyufjh
Copy link
Member

fuyufjh commented Nov 9, 2023

The behavior is consistent with PostgresQL:

test=# select sha384('\');
ERROR:  invalid input syntax for type bytea
LINE 1: select sha384('\');
                      ^
test=# select md5('\');
               md5                
----------------------------------
 28d397e87306b8631f3ed80d858d35f0
(1 row)

This is because sha functions accept a bytea, so you need to cast a string to bytea:

sha256 ( bytea ) → bytea

https://pgpedia.info/s/sha256.html

example:

postgres=# SELECT sha256('foo'::bytea);
                               sha256                               
--------------------------------------------------------------------
 \x2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae

@fuyufjh fuyufjh closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
@NiuBlibing
Copy link
Contributor Author

But convert 'select '\'::bytea; will failed also.

@xiangjinwu
Copy link
Contributor

xiangjinwu commented Nov 9, 2023

But convert 'select '\'::bytea; will failed also.

There are two ways to input a bytea value of a single byte 0x5c (\):

test=# select '\\'::bytea;
 bytea 
-------
 \x5c
(1 row)

test=# select '\x5c'::bytea;
 bytea 
-------
 \x5c
(1 row)

test=# select '\\'::bytea = '\x5c'::bytea;
 ?column? 
----------
 t
(1 row)

More options if using conversion functions:

@NiuBlibing
Copy link
Contributor Author

Is there a way to convert it in table so that I can use sha family hash?

-- create table
create table test (
    test varchar
);

-- insert data
insert into test values ('\=');

-- this will failed
-- ERROR:  QueryError: Internal(Expr error: Parse error: invalid input syntax for type bytea)
select test::bytea from test;
select sha512(test::bytea) from test;

@xiangjinwu
Copy link
Contributor

replace(test, '\', '\\')::bytea

@NiuBlibing
Copy link
Contributor Author

Thanks, it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants