Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph schemas #10

Open
nichtich opened this issue Jun 13, 2024 · 0 comments
Open

Graph schemas #10

nichtich opened this issue Jun 13, 2024 · 0 comments
Labels
extension Beyond 1.0.0

Comments

@nichtich
Copy link
Contributor

nichtich commented Jun 13, 2024

Graph schemas are required in practice for database management systems and for validation but they won't be part of version 1.0.0 of PG specification. A graph schema can be a graph of its own.

For instance GQL Example from this article

CREATE GRAPH TYPE socialNetworkSchema AS {
    (Person :Person&TaxPayer {name STRING, dob DATE, taxNo STRING}),
    (City :City {name STRING, state string, country STRING}),
    (Company :Company {name STRING, description STRING}),
    (Person)-[LivesIn :LIVES_IN {since DATE}]->(City),
    (Company)-[HeadquartersIn :HEADQUARTERS_IN {since DATE}]->(City),
    (Person)-[WorksFor :WORKS_FOR {since DATE}]->(Company),
    (Person)~[MarriedTo :MARRIED_TO {since DATE, until DATE}]~(Person)
}

as graph in PG format:

Person  :Person :TaxPayer name:STRING dob:DATE taxNo:STRING
City    :City             name:STRING state:STRING country:STRING
Company :Company          name:STRING description:STRING

# Edge identifiers are optional but included here
LivesIn:        Person  -> City :LIVES_IN        since:DATE
HeadquartersIn: Company -> City :HEADQUARTERS_IN since:DATE
WorksFor:       Person  -> Company :WORKS_FOR    since:DATE
MarriedTo:      Person -- Person :MARRIED_TO     since:DATE until:DATE

PG currently only supports data types STRING, BOOL and NUMBER. In practice INT and FLOAT should also be supported

Each property can be constraint as unique (-ID), required/optional (!/?) and/or repeatable ( */+). Examples:

title:STRING!   # required, non-repeatable
uri:STRING-ID!  # required, unique, non-repeatable
alias:STRING*   # repeatable, optional

Without cardinality and uniqueness indicator the constraint is unknown and thus may differ between implementations in different database management systems.

To specify schema for all nodes:

* key:INT-ID! # no labels => all nodes
* -> * date:STRING? # special node identifier "*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension Beyond 1.0.0
Projects
None yet
Development

No branches or pull requests

1 participant