File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ # postgres-json-schema
2
+
3
+ postgres-json-schema allows validation of [ JSON
4
+ schemas] ( http://json-schema.org/ ) in PostgreSQL. It is implemented as a
5
+ PL/pgSQL function and you can use it as a check constraint to validate the
6
+ format of your JSON columns.
7
+
8
+ postgres-json-schema supports the entire JSON schema draft v4 spec, except for
9
+ remote (http) references. It's tested against the official
10
+ [ JSON-Schema-Test-Suite] ( https://github.com/json-schema-org/JSON-Schema-Test-Suite ) .
11
+
12
+ # Installation
13
+
14
+ postgres-json-schema is packaged as an PGXS extension. To install, just run
15
+ ` make install ` as root, then ` CREATE EXTENSION "postgres-json-schema"; ` as the
16
+ database superuser.
17
+
18
+ # Example
19
+
20
+ CREATE TABLE example (id serial PRIMARY KEY, data jsonb);
21
+ ALTER TABLE example ADD CONSTRAINT data_is_valid CHECK (validate_json_schema('{"type": "object"}', data));
22
+
23
+ INSERT INTO example (data) VALUES ('{}');
24
+ -- INSERT 0 1
25
+
26
+ INSERT INTO example (data) VALUES ('1');
27
+ -- ERROR: new row for relation "example" violates check constraint "data_is_valid"
28
+ -- DETAIL: Failing row contains (2, 1).
You can’t perform that action at this time.
0 commit comments