Fork me on GitHub
David Pham15:10:03

Noob question: are queries with limit 1 as fast as queries with query one?


"query one" ?

Nate Sutton15:10:28

the limit 1 happens in the database and is generally the better option since the db doesn't need to materialize the entire result set


e.g. in postgresql limit 1 stops the query right when it finds the first result


i use the "limit x" often to quickly determine presence of certain types of data

Nate Sutton16:10:24

it does need to do more materialization if you use things like ordering or grouping though


@neo2551 if you're asking about execute! vs execute-one!, as the documentation says the latter is for SQL operations that you know will produce only one "row" such as update/delete and simple insert. It's purely a convenience so you don't have to unwrap a vector that only has one element.