Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

parser: broken select statements #51

Closed
Shivam010 opened this issue Sep 18, 2020 · 8 comments
Closed

parser: broken select statements #51

Shivam010 opened this issue Sep 18, 2020 · 8 comments
Assignees
Labels
needs triage This needs to be investigated or validated

Comments

@Shivam010
Copy link
Collaborator

Describe the bug
I see some similar bugs in https://github.com/xqueries/xdb/blob/master/internal/parser/parser_test.go

"CREATE TABLE myTable AS SELECT *",
"INSERT INTO myTable SELECT *",

I am not sure whether they are intentional or indeed are missed somehow, but I think these statements and others like these should give an error related to an invalid SELECT statement or missing table name.
Even, the select query without any FROM clause and Literal, is passing.

To Reproduce
Run the tests.
Also, try SELECT *, which I think should fail.

Similar issue
Missing table name in Create statement #29

@Shivam010 Shivam010 added bug Something isn't working needs triage This needs to be investigated or validated labels Sep 18, 2020
@tsatke
Copy link
Contributor

tsatke commented Sep 20, 2020

SELECT * is a valid grammar production, and should fail after compilation at execution time, so these are valid parser tests. The parser should not fail attempting to parse them.

https://www.sqlite.org/lang_select.html

So in summary:
your two examples should be

  • parseable
  • compilable
  • not executable
    If they are executable, this is an engine problem, otherwise, I would close this, as the behavior is intended.

@tsatke tsatke removed the bug Something isn't working label Sep 20, 2020
@SUMUKHA-PK
Copy link
Member

Whats the status on this?
Does #52 fix this? @Shivam010

@Shivam010
Copy link
Collaborator Author

Shivam010 commented Sep 22, 2020

As the query is parsable, the parser works fine in this case.
But I had run tests to execute the query and it seems it is executing perfectly. I have certain other examples, that are wrongly executing, like:

  • select *
  • select 1 from myTable

I am working on them with the possible solution.

@tsatke
Copy link
Contributor

tsatke commented Sep 22, 2020

How did you execute them? What result does select * produce?
select 1 from myTable should just produce

column1 (Integer)
1

at least that's what I would expect at this point

@Shivam010
Copy link
Collaborator Author

select * returns

column1 (String)
*

whereas select 1 from myTable returns with error: no column with name 1

@Shivam010
Copy link
Collaborator Author

even select 'str' from myTable returns the same error.
It is due to the fact that they are List type commands and the expected behaviour is written in Value type command.
We have to handle the behaviour for numerical values and quoted strings to be treated as constants and not columns in List

@tsatke
Copy link
Contributor

tsatke commented Sep 22, 2020

select * even makes sense... * is just considered a literal, since there is no column it matches, which is the same behavior as for select 1 or select '1'. I would leave it like that.
select 1 from myTable on the other hand should just work as select 1, given there is no such column.

Closing this in favor of #54

@tsatke tsatke closed this as completed Sep 22, 2020
@tsatke
Copy link
Contributor

tsatke commented Sep 22, 2020

We have to handle the behaviour for numerical values and quoted strings to be treated as constants and not columns in List

#55

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This needs to be investigated or validated
Projects
None yet
Development

No branches or pull requests

3 participants