Last active
May 18, 2024 11:02
-
-
Save sanemat/cf7f6114c8af54130cd083450cc8c2d8 to your computer and use it in GitHub Desktop.
postgresql uuid v4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data/ | |
!data/.keep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.8' | |
services: | |
postgres: | |
image: postgres:16 | |
environment: | |
- POSTGRES_USER=postgres | |
- POSTGRES_PASSWORD=password | |
- POSTGRES_DB=sandbox | |
volumes: | |
- postgres-db-volume:/var/lib/postgresql/data | |
ports: | |
- 5432:5432 | |
networks: | |
- postgres-db-network | |
volumes: | |
postgres-db-volume: | |
driver: local | |
driver_opts: | |
type: none | |
o: bind | |
device: ./data | |
networks: | |
postgres-db-network: | |
driver: bridge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table | |
users (user_id uuid primary key, name varchar(255)); | |
-- uuid v4 | |
insert into | |
"users" (user_id, name) | |
values | |
(gen_random_uuid (), 'Kevin'), | |
(gen_random_uuid (), 'John'); | |
select | |
* | |
from | |
users; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ psql -h localhost -p 5432 -U postgres | |
sandbox=# select * from users; | |
user_id | name | |
--------------------------------------+------- | |
77287474-f186-40ac-88a8-6fa340c4538c | Kevin | |
9bc76a76-8030-4984-bbb0-93943d848f07 | John | |
(2 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment