GithubHelp home page GithubHelp logo

gavinwahl / postgres-json-schema Goto Github PK

View Code? Open in Web Editor NEW
469.0 469.0 35.0 12 KB

JSON Schema validation for PostgreSQL

License: PostgreSQL License

PLpgSQL 86.88% Python 11.92% Makefile 1.20%

postgres-json-schema's People

Contributors

gavinwahl avatar kwakwaversal avatar vergenzt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postgres-json-schema's Issues

Building on Windows?

Is there any documentation for building this project on Windows? Any guidance would be appreciated.

Please add a license

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 not supported

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.

Trouble with pg_gump

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, ...

draft-06/draft-07 support?

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.

Fix relocatability

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)

[Suggestion] Validation error messages

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 )

[Suggestion] Publish to PostgreSQL Extension Network

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.

Performance

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"}
    }
}

Problem with installation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.