Skip to content

Instantly share code, notes, and snippets.

@sanemat
Last active May 18, 2024 11:02
Show Gist options
  • Save sanemat/cf7f6114c8af54130cd083450cc8c2d8 to your computer and use it in GitHub Desktop.
Save sanemat/cf7f6114c8af54130cd083450cc8c2d8 to your computer and use it in GitHub Desktop.
postgresql uuid v4
data/
!data/.keep
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
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;
$ 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