Skip to content

Instantly share code, notes, and snippets.

@squarism
Last active October 27, 2021 23:59
Show Gist options
  • Save squarism/1913c6411428057e12aef07164876aa0 to your computer and use it in GitHub Desktop.
Save squarism/1913c6411428057e12aef07164876aa0 to your computer and use it in GitHub Desktop.
Schemaless Postgres
psql=# create table schemaless (
id json,
email json,
active json,
name json,
subscription json
);
CREATE TABLE
Table "public.schemaless"
Column | Type | Collation | Nullable | Default
--------------+------+-----------+----------+---------
id | json | | |
email | json | | |
active | json | | |
name | json | | |
subscription | json | | |
psql=# insert into schemaless (id, email, active, name, subscription) values
(
'{"id": 42}',
'{"email": "[email protected]"}',
'{"active": true}',
'{"name": "Fred Flintstone"}',
'{"subscription": "Omega Tier!"}'
);
psql=# \x
Expanded display is on.
psql=# select * from schemaless limit 1;
-[ RECORD 1 ]+--------------------------------
id | {"id": 42}
email | {"email": "[email protected]"}
active | {"active": true}
name | {"name": "Fred Flintstone"}
subscription | {"subscription": "Omega Tier!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment