Skip to content

Certain SQL statements (NO KEY, RECURSIVE) aren't parsed correctly #494

@reteps

Description

@reteps

Bug report

SELECT
  1
FROM
  assessments AS a
WHERE
  a.id = $assessment_id
FOR NO KEY UPDATE;
apps/prairielearn/src/lib/assessment.sql:544:12 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Invalid statement: syntax error at or near ";"

    542 │ WHERE
    543 │   a.id = $assessment_id
  > 544 │ FOR NO KEY UPDATE;
        │            ^^^^^^^
    545 │
    546 │ -- BLOCK select_assessment_needs_statistics_update
WITH RECURSIVE
  template_questions AS (
    -- non-recursive term that finds the ID of the template question (if any) for question_id
    SELECT
      tq.id,
      tq.qid,
      tq.course_id,
      tq.template_directory
    FROM
      questions AS q
      JOIN questions AS tq ON (
        tq.qid = q.template_directory
        AND tq.course_id = q.course_id
      )
    WHERE
      q.id = $question_id
      AND tq.deleted_at IS NULL
      -- required UNION for a recursive WITH statement
    UNION
    -- recursive term that references template_questions again
    SELECT
      tq.id,
      tq.qid,
      tq.course_id,
      tq.template_directory
    FROM
      template_questions AS q
      JOIN questions AS tq ON (
        tq.qid = q.template_directory
        AND tq.course_id = q.course_id
      )
    WHERE
      tq.deleted_at IS NULL
  )
SELECT
  id
FROM
  template_questions
LIMIT
  100;
apps/prairielearn/src/lib/chunks.sql:73:6 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✖ Expected IDENT

    72 │ -- BLOCK select_template_question_ids
  > 73 │ WITH RECURSIVE
       │      ^^^^^^^^^
    74 │   template_questions AS (
    75 │     -- non-recursive term that finds the ID of the template question (if any) for question_id

To Reproduce

Reproduction is identical to #482

System information

  • v0.12.0 (latest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions