Skip to content

Modify UUID when passing it as a bind variable#160

Merged
Mytherin merged 1 commit intoduckdb:mainfrom
staticlibs:uuid_flipped_bit
Mar 17, 2025
Merged

Modify UUID when passing it as a bind variable#160
Mytherin merged 1 commit intoduckdb:mainfrom
staticlibs:uuid_flipped_bit

Conversation

@staticlibs
Copy link
Collaborator

When parsing an UUID from a string literal DuckDB modifies it with flipping the most significant bit in UUID::FromString for the following reason:

"Flip the first bit to make order by uuid same as order by uuid::varchar"

When an UUID is read from a result set, JDBC driver flips the MSB again to get back the original UUID in Java.

This bit-flipping logic was missing when an UUID was passed from Java as a bind variable. The proposed change adds the same logic when passing bind variables.

Testing: existing test is improved to cover both string literal and a bind variable.

Fixes: #147

When parsing an UUID from a string literal DuckDB modifies it with
flipping the most significant bit in `UUID::FromString` for the
following reason:

"Flip the first bit to make `order by uuid` same as `order by
uuid::varchar`"

When an UUID is read from a result set, JDBC driver flips the MSB again
to get back the original UUID in Java.

This bit-flipping logic was missing when an UUID was passed from Java
as a bind variable. The proposed change adds the same logic when
passing bind variables.

Testing: existing test is improved to cover both string literal and a
bind variable.

Fixes: duckdb#147
@Mytherin Mytherin merged commit aaacc82 into duckdb:main Mar 17, 2025
7 checks passed
@Mytherin
Copy link
Contributor

Thanks!

@staticlibs staticlibs deleted the uuid_flipped_bit branch March 17, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mismatch between uuid bind to as variable vs value returned from db with jdbc

2 participants