Closed colinricardo closed 7 years ago
Can you cut the example down to the smallest(ish) amount of code to produce the error?
I think a minimal reproducible example would be:
SELECT c.code
FROM countries c
JOIN economies e
ON c.code = e.code;
with SCT:
sel = check_node('SelectStmt')
from_clause = sel.check_field('from_clause')
cond = from_clause.check_field('cond').has_equal_ast(sql='c.code = e.code', start='expression', exact=False, msg='Is your join condition correct?')
Ex().test_correct(check_result(), [
cond,
test_has_columns(),
test_ncols(),
test_error()
])
Hmm.. I'm not sure what's going on. I tried to replicate but couldn't. It's the last exercise below
https://www.datacamp.com/teach/repositories/905/branches/master
Can you point me to the exercise? I can take a look at it.
https://campus.datacamp.com/courses/joining-data-in-postgresql/15083?ex=4
It seems that doing c.whatever
works as expected, but using any real column from the countries
table seems to break.
Ah, okay. Likely this is a duplicate of https://github.com/datacamp/sqlbackend/issues/82.
The error happens on the backend when there are no rows returned.
should be fixed on prod, see details on https://github.com/datacamp/sqlbackend/issues/82
Suppose we want to check the following code:
Question 1: is the following a reasonable way to do so?
Changing
ON c.code = e.code;
to e.g.ON c.code != e.code
throws an appropriate error about the join condition being wrong.However
ON c.name = e.code
causes a session crash with:list index out of range
.Question 2: What is the cause of this error and how can it be avoided?
cc @machow @ismayc