Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer bug when using CTEs in stored procedures #4480

Closed
max-hoffman opened this issue Apr 5, 2021 · 2 comments · Fixed by dolthub/go-mysql-server#1485
Closed

Analyzer bug when using CTEs in stored procedures #4480

max-hoffman opened this issue Apr 5, 2021 · 2 comments · Fixed by dolthub/go-mysql-server#1485
Labels
bug Something isn't working sql Issue with SQL

Comments

@max-hoffman
Copy link
Contributor

Version:

> dolt version
dolt version 0.24.4

Working query:

> dolt sql -q "
with t as (
  select
    case
      when p1.pred = p2.actual then 1
      else 0
    end as correct,
    p1.actual
    from predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p1
    join predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p2
    on p1.row_id = p2.row_id
)
select
  sum(correct)/count(*),
  count(*) as row_number
  from t;
+-----------------------+------------+
| sum(correct)/count(*) | row_number |
+-----------------------+------------+
| 0.1022                | 10000      |
+-----------------------+------------+

Procedure failure:

> dolt sql -q "
CREATE PROCEDURE computeSummary(c VARCHAR(200))
BEGIN
with t as (
  select
    case
      when p1.pred = p2.actual then 1
      else 0
    end as correct,
    p1.actual
    from predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p1
    join predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p2
    on p1.row_id = p2.row_id
)
select
  sum(correct)/count(*),
  count(*) as row_number
  from t;
END;"
table not found: t

Main error:

table not found: t

Analyzer not resolving CTE table before procedure validation?

@zachmu zachmu transferred this issue from dolthub/go-mysql-server Oct 6, 2022
@timsehn timsehn added bug Something isn't working sql Issue with SQL labels Oct 6, 2022
@timsehn
Copy link
Sponsor Contributor

timsehn commented Dec 1, 2022

This now fails with a different error.

$ dolt sql -q "
CREATE PROCEDURE computeSummary(c VARCHAR(200))
BEGIN
with t as (
  select
    case
      when p1.pred = p2.actual then 1
      else 0
    end as correct,
    p1.actual
    from predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p1
    join predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p2
    on p1.row_id = p2.row_id
)
select
  sum(correct)/count(*),
  count(*) as row_number
  from t;
END;"
Error parsing SQL
syntax error at position 388 near 'row_number'

CREATE PROCEDURE computeSummary(c VARCHAR(200))
BEGIN
with t as (
  select
    case
      when p1.pred = p2.actual then 1
      else 0
    end as correct,
    p1.actual
    from predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p1
    join predictions as of 'd1rl89u7q511n3tp5q6o5etomvg1mrli' p2
    on p1.row_id = p2.row_id
)
select
  sum(correct)/count(*),
  count(*) as row_number
  from t
^
syntax error at position 388 near 'row_number'
$

@timsehn timsehn changed the title CTE w/ stored procedures Analyzer bug when using CTEs in stored procedures Dec 1, 2022
@jycor
Copy link
Contributor

jycor commented Dec 20, 2022

The syntax error is caused by recent changes dealing with reserved keywords. This new behavior is expected since row_number is a reserved keyword. Wrapping the row_number in backquotes gets us back the original error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql Issue with SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants