Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-19 Thread Joshua Wise
> On Mar 18, 2019, at 5:21 AM, Keith Medcalf wrote: > > UPDATE tree > SET position = (SELECT position FROM _children WHERE id = tree.id) -- > Multiply by x to number by x > WHERE id IN (SELECT id FROM _children); > DELETE FROM _children; > END; I don’t see the window function causing

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-18 Thread Wout Mertens
On Mon, Mar 18, 2019 at 10:21 AM Keith Medcalf wrote: > requires a "gentlemen's agreement" to only put positive values in the > position column (meaning the database cannot enforce this, you need to do > it at the application level) > Can't this be done with a before insert trigger? sqlite>

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-18 Thread Keith Medcalf
icipated traffic volume. >-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Joshua Thomas Wise >Sent: Monday, 18 March, 2019 01:09 >To: SQLite mailing list >Subject: Re: [sqlite] Recursive CTE on tree with

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-18 Thread Joshua Thomas Wise
Another way of implementing ordered siblings is to use a floating point “position” column instead of maintaining links to siblings via foreign keys. The advantage of a “position” column is that the data model maintains consistency automatically—you don’t need to painstakingly make sure all

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-12 Thread James K. Lowden
On Mon, 11 Mar 2019 10:39:06 +0100 Jean-Luc Hainaut wrote: > Your implementation of trees is that of network databases at the > pointer-based physical level but definitely not relational. Try this: > > create table TREE( >ID integer not null primary key, >Parent integer references

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-11 Thread Keith Medcalf
On Monday, 11 March, 2019 09:42, heribert wrote: >it works perfect - but i do not understand why. See https://sqlite.org/lang_with.html for a description of recursive queries ... >The 'inital-select' results with the head node - only one result set. >SELECT * > FROM Tree > WHERE

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-11 Thread heribert
Thx clemens, it works perfect - but i do not understand why. The 'inital-select' results with the head node - only one result set. SELECT * FROM Tree WHERE ParentIDX = (SELECT ParentIDX FROM Tree WHERE ID = 3) AND PrevIDX IS NULL Points

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-11 Thread Clemens Ladisch
heribert wrote: > I've a tree with doubly linked items. I want to get all siblings of a tree > node. If you want them in order, you have to walk through the linked list: WITH SiblingsOf3 AS ( SELECT * FROM Tree WHERE ParentIDX = (SELECT ParentIDX FROM Tree

Re: [sqlite] Recursive CTE on tree with doubly linked items

2019-03-11 Thread Jean-Luc Hainaut
Your implementation of trees is that of network databases at the pointer-based physical level but definitely not relational. Try this: create table TREE( ID integer not null primary key, Parent integer references TREE on delete ... on update cascade); -- Notice the absence of "not null"

[sqlite] Recursive CTE on tree with doubly linked items

2019-03-11 Thread heribert
I've a tree with doubly linked items. I want to get all siblings of a tree node (e.g. ID=2 or harder to implement ID=3). I tried to solve this problem with CTE of SQLite by myself - but I can not find the solution. I looked for any exemplary solution - but do not find some. DROP TABLE IF