Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like the presentation of the guide. I wish something like this had been available when I started.

The "Filtering Data" example at the very bottom of this page [1] could be improved a bit. It's using >= AND <= for finding records between certain dates when BETWEEN is generally better for this. Since the guide is aimed at "beginners and experienced users", maybe a different example could be used or the BETWEEN version could be added below it as an example of cases where there's a more efficient way to filter data?

[1] http://www.postgresguide.com/sql/select.html#filtering-data



You gotta be careful when using BETWEEN.

BETWEEN does

    a >= x AND a <= y  
Usually, you want

    a >= x AND a < y
http://www.postgresql.org/docs/9.3/static/functions-comparis...


This is why I love the Postgres range types so much (http://www.postgresql.org/docs/9.4/static/rangetypes.html). With those, you get to chose based on the value whether your ranges include the boundaries or not. Even better: you get to chose for both start and end.


I recently replaced all my a >= x AND a < y with BETWEEN, and then I realised I got burned by what you describe :-) It's been on the Trello to-do to fix it for weeks...


Good point!

Edit: my parent post is wrong, the guide is using <, not <=, but I can't edit it now.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: