Fork me on GitHub
#sql
<
2019-10-06
>
David Pham15:10:03

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

kulminaator15:10:11

"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

kulminaator15:10:09

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

kulminaator15:10:43

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

seancorfield16:10:47

@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.