Skip to content

Issue with sql connector from python using Hashbytes #718

@anindya5

Description

@anindya5

I am sending this code via odbc connector to my sql server

Select Column,HASHBYTES('SHA2_256', CONVERT(VARBINARY(8),Column)) as Encoded_Column from table

Result is different if I run using connector vs if I run it on the sql server as a query.

I understand the issues with doing it via python hashlib and all, but why if I am just querying database with a connector and querying it, result is different.

One of our old sql legacy code, converts a numerical column in sql using the HASHBYTES function and sha2_256.

The entire process is moving to python as we are putting in some advanced usage on top of the legacy work. However, when using connector, we are calling the same sql code, the HASHBYTES('sha2_256',column_name) id returning values with lot of garbage.

Running the code in sql result in this

Column      Encoded_Column
101286297   0x7AC82B2779116F40A8CEA0D85BE4AA02AF7F813B5383BAC60D5E71B7BDB9F705

Running same sql query from python result in

Column      Encoded_Column
101286297 
b"z\xc8+'y\x11o@\xa8\xce\xa0\xd8[\xe4\xaa\x02\xaf\x7f\x81;S\x83\xba\xc6\r^q\xb7\xbd\xb9\xf7\x05"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions