On Friday, March 7, 2014 3:43:24 PM UTC-8, Joel VanderWerf wrote:
>
>
> I'm using sqlite and apparently it wasn't compiled with the 
> SQLITE_ENABLE_UPDATE_DELETE_LIMIT, so I can't do something like 
>
> delete from table where ... order by ... limit 1; 
>
> This works: subquery for the unique id and then delete that: 
>
> table = DB['tablename'] 
>

I think you mean DB[:tablename] :)
 

> table.where(id: table.select(:id).where(...).limit(1)).delete 
>
> Is there any sequel trick to delete at most one row that I'm missing? 
>

On the databases that support it (currently only MySQL):

DB[:table].order(:a).limit(1).delete
# DELETE FROM table ORDER BY a LIMIT 1"

For anything remotely portable, your subquery approach is probably best.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to