SQL 속성 그래프 질의

SQL property graph queries

PostgreSQL 19 베타는 SQL/PGQ로 테이블의 관계 경로를 질의할 수 있습니다.

···
html
<div class="demo"><div class="head"><b>SQL/PGQ PATH</b><span>MATCH (A)-[]->(next)</span></div><div class="stage pgq"><div class="vertex" id="graphA">A</div><div class="edge" id="edgeAB">→</div><div class="vertex" id="graphB">B</div><div class="edge" id="edgeBC">→</div><div class="vertex" id="graphC">C</div></div><div class="foot"><span id="graphstatus">start at A</span><span>1 · 2 hops</span></div></div>
css
*{box-sizing:border-box}.demo{width:min(96vw,820px);height:min(94vh,350px);padding:clamp(8px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);display:flex;flex-direction:column;gap:clamp(5px,1.5vmin,12px);font:600 clamp(12px,3.5vmin,15px)/1.25 var(--font-sans),sans-serif;overflow:hidden}.head,.foot,.row{display:flex;justify-content:space-between;align-items:center;gap:8px}.head b{color:var(--accent)}.head span,.foot,.muted{color:var(--muted)}.stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;gap:8px}.cell,.pill{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(4px,1.2vmin,9px);text-align:center}.pill{border-radius:999px}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 17%,var(--surface))!important;color:var(--fg)!important}.bad{border-color:#e16a5d!important;background:color-mix(in srgb,#e16a5d 18%,var(--surface))!important}.foot{font-size:clamp(12px,3vmin,14px)}.pgq{gap:clamp(4px,2vmin,18px)}.vertex{width:clamp(34px,13vmin,64px);aspect-ratio:1;border:2px solid var(--line);border-radius:50%;display:grid;place-items:center;background:var(--bg);font:700 clamp(17px,5vmin,26px) ui-monospace,monospace;transition:.3s}.vertex.on{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 20%,var(--surface))}.edge{font-size:clamp(16px,5vmin,26px);color:var(--line);transition:.3s}.edge.on{color:var(--accent)}
js
let n=0;function tick(){['graphA','graphB','graphC'].forEach((id,i)=>document.getElementById(id).classList.toggle('on',i<=n));['edgeAB','edgeBC'].forEach((id,i)=>document.getElementById(id).classList.toggle('on',i<n));document.getElementById('graphstatus').textContent=['start at A','A → B: 1 hop','A → B → C: 2 hops'][n];n=(n+1)%3}tick();const t=setInterval(tick,900);document.querySelector('.demo').onclick=()=>{clearInterval(t);tick()}

SQL/PGQ는 노드와 간선으로 표현한 속성 그래프를 SQL 안에서 질의하는 표준 기능입니다. PostgreSQL 19 베타는 이 구문을 지원해 관계를 따라가는 경로 패턴을 작성할 수 있습니다.

데모는 A에서 출발해 연결된 사람을 한 단계씩 찾습니다. 그래프 질의가 모든 조인을 대체하는 것은 아니며, 관계 방향과 반복 범위를 명시해야 의도한 경로만 얻습니다. 베타 기능이므로 정식 릴리스 전에 구문과 동작이 바뀔 수 있습니다.

언제 쓰나

사람·상품·계정 사이의 다단계 관계를 SQL에서 탐색할 때 베타 기능으로 평가합니다.

페이지로 열기 ↗