From 1b36183edbd50e9bc2dab28e28ea7a731f1381ec Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Fri, 9 Oct 2020 14:01:47 -0700 Subject: [PATCH] Holy chao. The CTE works. --- .../sql/select_note_collection_from_root.sql | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/server/nm-store/src/sql/select_note_collection_from_root.sql b/server/nm-store/src/sql/select_note_collection_from_root.sql index 9625e64..e055f58 100644 --- a/server/nm-store/src/sql/select_note_collection_from_root.sql +++ b/server/nm-store/src/sql/select_note_collection_from_root.sql @@ -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);