Hacker News new | ask | show | jobs
by PeCaN 3600 days 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-jso...

1 comments

Slick, thanks!