-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Storing uuid byte sequence to postgres. #179
Comments
Isn't it better to use native UUID type that PostgreSQL provides? I think that the guide you linked in your post is about MySQL/MariaDB which does not provide native UUID type. |
@N-Zaaijer, can you share the code you're using to try to store the UUID to the database? |
Thanks, @N-Zaaijer. I'm not very familiar with Laravel's Eloquent ORM. Can you provide a short reproducible script that I can use to run against Postgres to see the problem? |
I'll try and come up with something. |
Thanks. That will help a lot. All I need is an SQL |
Is this something you can work on? I added a native uuid field and a bytea field for comparison. |
I can try to make that work. Thanks! |
@ramsey did you get it to work? |
I stumbled upon something. The hex2bin doesn't convert all characters. Dumping the 'binary' results in b"\x11þîØ\x18·■\x1C¥õ\fx╬#\x029" for example. Here's an other test setup https://3v4l.org/ND2O3 |
The I haven’t been able to reproduce your issue yet. It will take some time, as I’m unfamiliar with Laravel and will need to learn how to set it up to run the script. Sorry for the delay. |
I ran into this issue as well today while using Symfony, Doctrine and Postgres. The error was thrown when inserting a row into a table with |
You don't need Laravel to reproduce it. You can just use Symfony + Doctrine + Postgres, define a doctrine entity with binary uuid field and try to insert something. I assume this is the same issue. |
Thanks, @enumag. I didn’t think this was specific to Laravel; the reproduction script requires Laravel, though. Would you be able to provide a small reproduction script that I can run outside of a framework to help debug this? Thanks! |
@ramsey Making framework-independent script is a little more complicated. Not sure when or if I'll have time for that. |
@ramsey Same for me with Symfony + Doctrine + Postrgres when i try to use binary type uuid. Im new to PostgreSQL so im wondering if the problem is in my configuration of database (i kept default posgre settings) or its in library. Any news about this problem ? |
It should be noted that when using postgresql's UUID data type, inserting/updating UUIDs stored in the field should specify the UUID in one of the following formats as a string rather then as the raw bytes in the SQL query: |
@jobe1986, I think the issue here is when attempting to store the bytes to a |
In that case, whilst I'm not familiar with Illuminate\Support\Facades\DB for postgresql database support in PHP, in the code I am familiar with I would use pg_escape_bytea() to escape the binary data first. Or I would look at pg_query_params() or a similar method to avoid directly concatenating the parameters into the SQL query itself. I offer this information as it may provide a hint or point you in the right direction. |
Thanks for that, @jobe1986. Do you know if bound parameters with PDO will escape the bytea data properly? |
I believe so, as https://stackoverflow.com/questions/5313066/bind-bytea-to-pgsql-pdo-prepared-statement-in-php5 suggests using PDO::PARAM_LOB as the data type for bindParam() |
In that case we just need to add I will try to test it tomorrow and send a PR if it works. |
Thanks to @enumag, this has been fixed in 1.4.2 of ramsey/uuid-doctrine. I'm leaving this issue open until I've been able to provide direction in how to address this problem in Laravel (and potentially other frameworks). Once I come up with a good, easy-to-explain solution, I'll update the README or the wiki with examples. |
We had to roll-back the changes made to ramsey/uuid-doctrine, since they broke MySQL/MariaDB implementations. I'll leave this issue open to continue researching and see if there's a solution I can offer. |
The solution is TO NOT use bytea and use native uuid type. The native type already stores uuid as a binary, but returns/requires the text representation for SQL |
@ramsey Hello. I have critical problem because of this. I'm using symfony/messenger component that store failed messages through Doctrine into PostgreSQL table. And messages that contain Uuid can't be saved. |
Are you able to provide a short script (that doesn't depend on a framework) to reproduce the issue? I've not been able to reproduce it on my own. |
I don't know at the moment how to reproduce this problem, but I see that when I try to serialize Uuid, I get Maybe it somehow related on |
@ramsey I think the problem is that people are using So solution would be to perhaps nudge people to switching to |
@kgilden Thanks for posting! This sounds like the missing piece here. I'll be sure to update the docs so others know. Thanks! |
Took me while to figure out that binary type should not be used with postgres. DBAL driver will fail for postgres with message: |
I had the same problem, I'm using binary (16) to store with postgres, I solved it in this simple way '\x'.bin2hex(Uuid::fromString($uuid)->getBytes()); |
`Ramsey\Uuid` doesn't support storing byte sequence to PostgreSQL. We need to use `Ramsey\Uuid\Doctrine\UuidType` and store it in PostgreSQL as `uuid` type. - ramsey/uuid#179
Hi,
I'm currently having problems to store the optimized byte sequence to my postgres database. I keep getting the error
SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xe7 0x87 0xf3
I've followed the guide and used the OrderedTimeCodec in my uuid factory.
My database table alteration script:
DB::statement('ALTER TABLE entity_groups ADD uuid bytea');
I'm using php 7.1, laravel 5.4 and postgres 9.4.
Thanks in advance.
The text was updated successfully, but these errors were encountered: