포스트 그레스가에 의해 연결에 동등한를 가지고있다. 모듈을 활성화해야합니다. 기본적으로 해제되어 있습니다.
tablefunc이라고합니다. 친숙한 "연결"및 "시작 번호"과 같이 멋진 크로스 탭 기능을 지원합니다. 재귀 CTE보다 훨씬 능숙하고 논리적으로 작동한다는 것을 알았습니다. DBA가이 기능을 사용할 수없는 경우 Erwin이 수행하는 방식으로 이동해야합니다.
"BOM (Bill of Material)"쿼리를 수행 할만큼 강력합니다.
은 Tablefunc이 명령을 실행하여 켤 수 있습니다 :
다음
CREATE EXTENSION tablefunc;
갓 공식 문서에서 해제 연결 필드의 목록입니다.
Parameter: Description
relname: Name of the source relation (table)
keyid_fld: Name of the key field
parent_keyid_fld: Name of the parent-key field
orderby_fld: Name of the field to order siblings by (optional)
start_with: Key value of the row to start at
max_depth: Maximum depth to descend to, or zero for unlimited depth
branch_delim: String to separate keys with in branch output (optional)
정말 docs 페이지를 살펴 봐야합니다. 그것은 잘 쓰여지고 당신에게 익숙한 옵션을 줄 것입니다. (문서 페이지에서 아래쪽으로 스크롤하십시오.)
Postgreql "Connect by" extension 다음은 해당 구조를 함께 배치해야하는 내용입니다. 잠재력의 톤이 있으므로 정의를하지는 않겠지 만 여기에 아이디어를 줄 수있는 기회가 있습니다.
connectby(text relname, text keyid_fld, text parent_keyid_fld
[, text orderby_fld ], text start_with, int max_depth
[, text branch_delim ])
실제 검색어는 다음과 같습니다. Connectby_tree는 테이블의 이름입니다. "AS"로 시작하는 행은 열의 이름을 지정하는 방법입니다. 그것은 약간 거꾸로 보입니다.
SELECT * FROM connectby('connectby_tree', 'keyid', 'parent_keyid', 'pos', 'row2', 0, '~')
AS t(keyid text, parent_keyid text, level int, branch text, pos int);
난 당신이 [RECURSIVE 있음]을 사용할 거라고 생각 (http://www.postgresql.org/docs/9.3/static/queries-with.html) –
http://stackoverflow.com/ q/22626394/330315 –