cwida / duckpgq-extension

DuckDB extension that adds support for SQL/PGQ
https://duckpgq.notion.site/b8ac652667964f958bfada1c3e53f1bb?v=3b47a8d44bdf4e0c8b503bf23f1b76f2
MIT License
72 stars 7 forks source link

Support optional match #112

Open Dtenwolde opened 7 months ago

Dtenwolde commented 7 months ago

Many SNB queries such as IC1, IC4, IC5 (see https://github.com/cwida/duckpgq-experiments/issues/26 for all) require optional matches. The PGQ syntax would be ()-[]->?().

Snippet from the SQL/PGQ specification section 10.6:

<questioned path primary> ::=
  <path primary> <question mark>

"NOTE 130 — Unlike most regular expression languages, is not equivalent to the quantifier {0,1}: the quantifier {0,1} exposes variables as group, whereas does not change the singleton variables that it exposes to group. However, does expose any singleton variables as conditional singletons."

The way to translate this would be with a LEFT OUTER JOIN

(b:Student)<-[k:Know]-(a:Student)-[sa:studyAt]->?(u:University)
select * from student s
join know k on s.id = k.src
join student s2 on s2.id = k.dst
left join studyat sa on sa.studentid = s.id
join university u on sa.universityid = u.id;
github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.