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