3 ms·
> I don't think Postgres has any built-in support for JSON schematization. Guess again. You can use JSON functions¹ in constraints: create table foo ( b
by PeCaN 10y ago
> I don't think Postgres has any built-in support for JSON schematization.
Guess again. You can use JSON functions¹ in constraints:
create table foo (
bar jsonb,
constraint bar_count_is_positive check (bar->>'count' is not null and (bar->>'count')::integer >= 0)
);
etc
You could probably write a tool pretty easily to convert a JSON schema to Postgres constraints.
1. https://www.postgresql.org/docs/current/static/functions-json.html https://www.postgresql.org/docs/current/static/functions-jso...
- seagreen 10y agoSlick, thanks!