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

How to search a partial uuid? #440

Open
chateaux opened this issue Aug 28, 2022 · 1 comment
Open

How to search a partial uuid? #440

chateaux opened this issue Aug 28, 2022 · 1 comment
Labels

Comments

@chateaux
Copy link

My transactions table uses a uuid which is stored as bytes in the database.

I would like to know how to search for a partial uuid? Obviously, since we are using bytes, the data is stored as a binary in the table so in theory I need to convert the partial uuid string to a binary and then to search on that.

Is there anyway to do this natively with UUID?

If I had a full UUID, I am simply going to use something like so:

$qb->andWhere('transactions.uuid = :uuid')->setParameter('uuid', Uuid::fromString($options['transactionUuid'])->getBytes());

But to search a partial uuid, I am looking to do something as follows:

$qb->expr()->like('transaction.uuid', Uuid:fromString(':search')->getBytes()),

But obviously the fromString requires a correctly formed uuid string as apposed to a partial.

I am not sure this is possible and perhaps is one of the downfalls of using bytes in the table as apposed to string.

@7thSENSE-GmbH
Copy link

Hi @chateaux ,
you could use lower() and hex() to convert the transaction.uuid into something searchable.

$qb->andWhere('LOWER(HEX(transactions.uuid)) LIKE :uuid')->setParameter('uuid', '%f68f66cd%');

It is not a solution withing this library but it should work. Although I have not tested the above line.

Best
Sebastian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants