Answer the question
In order to leave comments, you need to log in
Binary UUID in Laravel with Postgres?
There is a need to store the ID in the UUID format After reading
various sources, it was decided to generate a uuid, convert it to a binary and store it in the database in this form, and convert it from a binary form to a regular uuid when outputting
What was done:
In migration:
In the model:
$table->binary('id')->primary();
parent::creating(static function (self $model) {
$model->setIncrementing(false);
$model->{$model->getKeyName()} = Uuid::uuid4()->toString();
});
SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x85 (SQL: insert into "users" ("name", "email", "email_verified_at", "password", "remember_token", "id", "updated_at", "created_at") values (Rocky Bartoletti, [email protected], 2020-05-06 08:03:08, $2y$10$b/4r5FCM5tlAj6XG1fu7Ie4OPFmS5BhU3ssKAswbo2yUTYerOpI2W, IctZ1tOPQg, ��z�]�Dq�7��6L�
, 2020-05-06 08:03:08, 2020-05-06 08:03:08))
insert into "users" ("name", "email", "email_verified_at", "password", "remember_token", "id", "updated_at",
"created_at")
values ('Rocky Bartoletti', '[email protected]', '2020-05-06 08:03:08', '$2y$10$b/4r5FCM5tlAj6XG1fu7Ie4OPFmS5BhU3ssKAswbo2yUTYerOpI2W', 'IctZ1tOPQg', '��z�]�Dq�7��6L�
', '2020-05-06 08:03:08', '2020-05-06 08:03:08')
Answer the question
In order to leave comments, you need to log in
Before trying to reinvent the wheel, check out the stock features. If you really really want to use uuid instead of the more compact and faster bigint, then postgresql already has this data type.
Stored as a fixed length field of 16 bytes.
By converting it to bytea, you will only increase, not decrease, its size. Because for bytea, it will also need to store the length of the data in this field.
With postgres so far on you and I can’t understand what he wants from me .. As I understand from the Internet, he does not perceive the binary in UTF well
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question