Holy chao. The CTE works.
This commit is contained in:
parent
e429eaf93c
commit
1b36183edb
|
@ -13,10 +13,10 @@
|
||||||
-- *in nesting order* to the client.
|
-- *in nesting order* to the client.
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
|
id,
|
||||||
|
uuid,
|
||||||
parent_id,
|
parent_id,
|
||||||
parent_uuid,
|
parent_uuid,
|
||||||
note_id,
|
|
||||||
note_uuid,
|
|
||||||
content,
|
content,
|
||||||
position,
|
position,
|
||||||
notetype,
|
notetype,
|
||||||
|
@ -28,10 +28,10 @@ SELECT
|
||||||
FROM (
|
FROM (
|
||||||
|
|
||||||
WITH RECURSIVE notetree(
|
WITH RECURSIVE notetree(
|
||||||
parent_id,
|
|
||||||
parent_uuid,
|
|
||||||
id,
|
id,
|
||||||
uuid,
|
uuid,
|
||||||
|
parent_id,
|
||||||
|
parent_uuid,
|
||||||
content,
|
content,
|
||||||
position,
|
position,
|
||||||
notetype,
|
notetype,
|
||||||
|
@ -42,11 +42,11 @@ FROM (
|
||||||
cycle) AS
|
cycle) AS
|
||||||
|
|
||||||
-- ROOT expression
|
-- ROOT expression
|
||||||
SELECT
|
(SELECT
|
||||||
notes.id,
|
|
||||||
notes.uuid,
|
|
||||||
notes.id,
|
notes.id,
|
||||||
notes.uuid,
|
notes.uuid,
|
||||||
|
notes.id AS parent_id,
|
||||||
|
notes.uuid AS parent_uuid,
|
||||||
notes.content,
|
notes.content,
|
||||||
0, -- Root notes are always in position 0
|
0, -- Root notes are always in position 0
|
||||||
notes.notetype,
|
notes.notetype,
|
||||||
|
@ -60,10 +60,10 @@ FROM (
|
||||||
|
|
||||||
-- RECURSIVE expression
|
-- RECURSIVE expression
|
||||||
UNION SELECT
|
UNION SELECT
|
||||||
notetree.id,
|
|
||||||
notetree.uuid,
|
|
||||||
notes.id,
|
notes.id,
|
||||||
notes.uuid,
|
notes.uuid,
|
||||||
|
notetree.id AS parent_id,
|
||||||
|
notetree.uuid AS parent_uuid,
|
||||||
notes.content,
|
notes.content,
|
||||||
note_relationships.position,
|
note_relationships.position,
|
||||||
notes.notetype,
|
notes.notetype,
|
||||||
|
@ -81,5 +81,6 @@ FROM (
|
||||||
-- be; we're supposed to prevent those. But you never know.
|
-- be; we're supposed to prevent those. But you never know.
|
||||||
WHERE
|
WHERE
|
||||||
notetree.cycle NOT LIKE '%,'||notes.id||',%'
|
notetree.cycle NOT LIKE '%,'||notes.id||',%'
|
||||||
ORDER BY note_relationships.position);
|
ORDER BY note_relationships.position)
|
||||||
|
SELECT * from notetree);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue