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

Error result when text content is C1,C2.... #294

Open
weishengkui opened this issue Feb 2, 2022 · 3 comments
Open

Error result when text content is C1,C2.... #294

weishengkui opened this issue Feb 2, 2022 · 3 comments

Comments

@weishengkui
Copy link

CONTENT:

worthless       C1      adjective
worthwhile      B2      adjective
worthy  C1      adjective
would   B1      modal verb

q -t 'select count(distinct(c1)) from CEFR.txt where c2 = "C1"'
result:
0

@harelba
Copy link
Owner

harelba commented Feb 2, 2022

wow, that's an interesting bug... thanks for reporting it. I'll take a deeper look

@harelba
Copy link
Owner

harelba commented Feb 7, 2022

Hi, sorry for the late reply.

The reason that the query returns 0 as the result is due to the fact that the string literal C1 is double-quoted and not single-quoted. In sqlite (the underlying engine/syntax of q), double-quoted strings are treated as identifiers (e.g. column names in this case), and not as string literals, which means that the original example query essentially compared between the value of column c2 to the value of column c1, returning an empty set.

Running the same query with single-quotes returns the correct results.

$ q -t "select count(distinct(c1)) from CEFR.txt where c2 = 'C1'"
2

I've changed the wrapping of the entire query to double-quotes as well in this query, to prevent the need escape the single-quotes.

Hope that helps
Harel

@harelba
Copy link
Owner

harelba commented Feb 22, 2022

@weishengkui - Can you update whether or not this fixed your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants