-1

So I have the following recursive

WITH RECURSIVE length(len, id, ord) AS (
    SELECT 0, t.id, 1
    FROM temp t
    UNION
    SELECT len + compute(

        SELECT w2.nodeid
        FROM waypoint w2
        WHERE w2.ordinal = ord AND w2.wayid =t.id,

        SELECT w2.nodeid
        FROM waypoint w2
        WHERE w2.ordinal = ord + 1 AND w2.wayid =t.id

    ), t.id, w1.ordinal
    FROM waypoint w1, length, temp t
    WHERE w1.wayid = t.id AND w1.ordinal = ord + 1
),
SELECT *
FROM length

The issue is that I keep getting this error

sqlite3.OperationalError: near "SELECT": syntax error

compute is just a user defined sqlite function that takes two node ids to compute the distance between them.

3
  • 1
    Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSI JOIN syntax in the ANSI-92 SQL Standard (almost 30 years ago) and its use is discouraged
    – marc_s
    Commented Nov 15, 2021 at 6:56
  • Remove comma between WITH end and the SELECT. Etc.
    – jarlh
    Commented Nov 15, 2021 at 7:24
  • Tip of today: Build your query up step by step. Then you'll notice when you introduce an error. The above query has at least 5 several syntax errors.
    – jarlh
    Commented Nov 15, 2021 at 7:26

1 Answer 1

0

You have a syntax error in FROM waypoint w1, length, , temp t two commas apeaer near each other.

Try this:

WITH RECURSIVE length(len, id, ord) AS (
    SELECT 0 as len, t.id, 1 as ord
    FROM temp t
    UNION
    SELECT (len + compute(

        SELECT w2.nodeid
        FROM waypoint w2
        WHERE w2.ordinal = ord AND w2.wayid =t.id,

        SELECT w2.nodeid
        FROM waypoint w2
        WHERE w2.ordinal = ord + 1 AND w2.wayid =t.id

    ) )as len, t.id, w1.ordinal as ord
    FROM waypoint w1, length, temp t
    WHERE w1.wayid = t.id AND w1.ordinal = ord + 1
),
SELECT *
FROM length
4
  • It was a typo when I was pasting it, I tried with this and still no luck
    – saji
    Commented Nov 15, 2021 at 5:24
  • Maybe because of the needing alias. I update the answer try it again @saji Commented Nov 15, 2021 at 5:35
  • Still syntax error(s).
    – jarlh
    Commented Nov 15, 2021 at 7:55
  • if you can, share sample data and query in sqliteonline.com, Then I can have a better review @saji Commented Nov 15, 2021 at 8:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.