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

OFFSET should be allowed to be 0 #1937

Merged
merged 3 commits into from
Mar 13, 2015
Merged

OFFSET should be allowed to be 0 #1937

merged 3 commits into from
Mar 13, 2015

Conversation

corylanou
Copy link
Contributor

Fixes #1924

@pauldix
Copy link
Member

pauldix commented Mar 13, 2015

Looks good, although it seems odd that parseOptionalTokenAndInt was set up to not allow zeros. No?

@corylanou
Copy link
Contributor Author

Yeah, I wasn't brave enough to just let it... I could try and see what it breaks :-)

@corylanou
Copy link
Contributor Author

@pauldix your hunch was correct... zero was totally ok!

@@ -1435,8 +1435,8 @@ func (p *Parser) parseOptionalTokenAndInt(t Token) (int, error) {
// Parse number.
n, _ := strconv.ParseInt(lit, 10, 64)

if n < 1 {
msg := fmt.Sprintf("%s must be > 0", t.String())
if n < 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to validate this as all? Wouldn't it be better to just look at the error from ParseInt? I'm guessing that's why it wasn't allowing zero before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you get an error like this?

> show series limit -1
ERR: error parsing query: LIMIT must be > 0 at line 1, char 19

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a deliberate design decision we came to a while back (search Slack).

If my recollection is correct we decided that LIMIT 0 didn't make much sense, since it should be interpreted literally as "give me no records". SQLite, MySQL (and I believe Postgres) all return 0 records if you ask for LIMIT 0. Since there was still arguments about this we simply prohibited LIMIT 0 in code. Obviously OFFSET 0 is a different issue, but OFFSET did not exist at the time of the discussions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking because it was parseOptionalTokenAndInt, not necessarily LIMIT. But sure, this makes sense. Merging it!

pauldix added a commit that referenced this pull request Mar 13, 2015
OFFSET should be allowed to be 0
@pauldix pauldix merged commit 87cdb75 into master Mar 13, 2015
@corylanou corylanou deleted the offset-zero branch April 23, 2015 14:54
mark-rushakoff pushed a commit that referenced this pull request Jan 11, 2019
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

Successfully merging this pull request may close these issues.

OFFSET should be allowed to be 0
3 participants