oracle / pgql-lang

PGQL is an SQL-based query language for property graphs
https://pgql-lang.org/
Other
184 stars 44 forks source link

Question about the `CREATE PROPERTY GRAPH` statement #85

Closed sleepymole closed 2 years ago

sleepymole commented 2 years ago

I'm reading PGQL 1.4 Specification. I have some questions about the CREATE PROPERTY GRAPH statement.

In the specification, we can specify the keys in the CREATE PROPERTY GRAPH statement itself. An example is:

CREATE PROPERTY GRAPH financial_transactions
  VERTEX TABLES (
    Accounts
      KEY ( number )
      LABEL Account
      PROPERTIES ( number ),
    ...
  )
  EDGE TABLES (
    Transactions
      SOURCE KEY ( from_account ) REFERENCES Accounts
      DESTINATION KEY ( to_account ) REFERENCES Accounts
      LABEL transaction PROPERTIES ( amount ),
    Accounts AS PersonOwner
      SOURCE KEY ( number ) REFERENCES Accounts
      DESTINATION Persons
      LABEL owner NO PROPERTIES,
    ...
  )

I want to know which key in vertex table does the edge table PersonOwner 's source key actually reference? My understanding is it will reference the key explicitly defined in vertex table first. If the key clause is missing in vertex table, it will try to references the underlying primary key.

In addition, if two vertex table use the same underlying table, at least one table name need to be aliased. In this case, do we need to use the aliased table name in edge table's definition?

oskar-van-rest commented 2 years ago

@gozssky

My understanding is it will reference the key explicitly defined in vertex table first. If the key clause is missing in vertex table, it will try to references the underlying primary key.

You're right, that's how it works.

In addition, if two vertex table use the same underlying table, at least one table name need to be aliased. In this case, do we need to use the aliased table name in edge table's definition?

Yes you would indeed need to use the alias in the edge table's definition. If no alias is specified, the alias defaults to the table name without the schema part (i.e. my_schema.my_table translates to my_schema.my_table AS my_table).

sleepymole commented 2 years ago

@oskar-van-rest I got it, thank you very much for your reply!