gavinwahl / postgres-json-schema Goto Github PK
View Code? Open in Web Editor NEWJSON Schema validation for PostgreSQL
License: PostgreSQL License
JSON Schema validation for PostgreSQL
License: PostgreSQL License
Is there any documentation for building this project on Windows? Any guidance would be appreciated.
I would like to use your extension in one of my projects, but without a explicit license that is not possible. Please consider using the PostgreSQL License for this.
Negative integers are not validated correctly:
select validate_json_schema('{"type": "integer"}', '-103948');
validate_json_schema
----------------------
f
(1 row)
I think the answer is to look at the type check where data
is coerced to text
and compared to a regex -- I'm not sure what's most performant, but maybe there's a built-in function to fulfill this check.
Hi, thank you for the great extension, but I have a little trouble with restoring my dump. When I run psql -d mydb < dump.sql I have get an error:
ERROR: function _validate_json_schema_type(text, jsonb) does not exist
LINE 1: SELECT (SELECT NOT bool_or(_validate_json_schema_type(type, ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT (SELECT NOT bool_or(_validate_json_schema_type(type, data)) FROM unnest(types) type)
CONTEXT: PL/pgSQL function public.validate_json_schema(jsonb,jsonb,jsonb) line 20 at IF
COPY role, line 1: "1a16d831-abb5-4e02-b905-159fd8e9c49e {"id": "1a16d831-abb5-4e02-b905-159fd8e9c49e", "name": "admin",..."
ERROR: function _validate_json_schema_type(text, jsonb) does not exist
LINE 1: SELECT (SELECT NOT bool_or(_validate_json_schema_type(type, ...
Hello from the JSON Schema specification team!
Does this project intend to update to more recent drafts? We have published some release migration notes and are happy to answer any questions that might come up.
Sometime before the end of the year, we will be re-organizing our implementations page to highlight implementations that support at least draft-06. Implementations supporting draft-04 and older will still be on the site, but not as visible.
Currently if you try and load postgres-json-schema into a non-default schema, it fails to find it's function _validate_json_schema_type
.
psql:fixtures.psql:37: ERROR: function _validate_json_schema_type(text, jsonb) does not exist
LINE 1: SELECT (SELECT NOT bool_or(_validate_json_schema_type(type, ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT (SELECT NOT bool_or(_validate_json_schema_type(type, data)) FROM unnest(types) type)
CONTEXT: PL/pgSQL function validate_json_schema(jsonb,jsonb,jsonb) line 20 at IF
You should qualify your intra-module calls with @extschema@.
(see https://www.postgresql.org/docs/current/extend-extensions.html)
My understanding is that at the moment this extension allows you to get answer if validation failed or succeeded. But would be great if you could also error messages. Possible format:
{"name": ["is required"]}
Not sure about exact format, but that would definitely be useful in some cases (my use-case is trying to process http request in postgres function. And this would provide validation messages )
I'm using this handy extension to test stored procedures which return JSON objects and, while it's already easy enough to install by cloning the repository and running make, I was wondering if this could be published to PGXN, the PostgreSQL Extension network.
This way, one could install the latest stable version using the package manager, i.e. with a command like pgxn install postgres-json-schema
.
I don't see any performance numbers so I thought I'd throw this up as reference.
No validation:
CREATE TABLE test (
json jsonb NOT NULL
);
INSERT INTO test
SELECT json_build_object('a', i, 'b', i::text)
FROM generate_series(1, 200000) t(i);
-- Time: 951.560 ms
Validation:
CREATE TABLE test (
json jsonb NOT NULL,
CHECK (validate_json_schema('{"type": "object", "properties": {"a": {"type": "number"}, "b": {"type": "string"}}}', json))
);
INSERT INTO test
SELECT json_build_object('a', i, 'b', i::text)
FROM generate_series(1, 200000) t(i);
-- Time: 17772.752 ms (00:17.773)
Conclusion
The following two-key object schema validates at ~11k values/s.
{
"type": "object",
"properties": {
"a": {"type": "number"},
"b": {"type": "string"}
}
}
Hi, thank you for the great work, but after rebuilding my docker machine I have a problem:
DockerFile
FROM postgres:12
ADD postgres-json-schema /postgres-json-schema
RUN apt-get update && apt-get install -y build-essential postgresql-server-dev-all
RUN cd /postgres-json-schema && make install && make installcheck
COPY install-json.sh /docker-entrypoint-initdb.d/
install-json.sh
#!/bin/bash
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -c 'CREATE EXTENSION IF NOT EXISTS "postgres-json-schema"'
Problem:
[58P01] ERROR: could not open extension control file "/usr/share/postgresql/12/extension/postgres-json-schema.control": No such file or directory
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.