I want to update first n rows using db_update(). Is it possible?

I know we can use db_query(). something like

UPDATE <table_name> SET <field_name> = <value> LIMIT <num_rows>

I want to know whether this is possible using db_update()


It doesn't look like it's possible I'm afraid.

db_update() uses the UpdateQuery class, which doesn't support the range() method that a SelectQuery does.

You could probably subclass UpdateQuery and add that behaviour, but for the amount of work that would take you might be better off just using a raw SQL statement with db_query() like you've suggested.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.