`first()` turns an `update` query into a `select`
See original GitHub issue> knex('pool_enterprise.test').update({'state': 'awesome'}).first().toSQL()
{ method: 'first',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ 1 ],
__knexQueryUid: '3698eb45-5165-46af-aa43-9376e048cb27',
sql: 'select * from "pool_enterprise"."test" limit ?' }
Probably should just throw an error? I mean you can do an UPDATE RETURNING
but I don’t seen LIMIT
clause allowed in the postgres docs
Tested on postgres.
How it happened is I had a limit supposed to be on a subquery but I got the parens wrong. Was a bit hard to debug.
Knex version:
knex@^0.12.9:
version "0.12.9"
resolved "https://registry.yarnpkg.com/knex/-/knex-0.12.9.tgz#aa852138c09ed46181e890fd698270bbe7761124"
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
first() turns an update query into a select #2061 - GitHub
Hm, I kinda assumed update().first() would return a single updated row, instead of an array. Maybe a .single() method would be useful for...
Read more >How to UPDATE from a SELECT statement in SQL Server
UPDATE queries can change all tables' rows, or we can limit the update statement affects for certain rows with the help of the...
Read more >Create and run an update query - Microsoft Support
Open the database that contains the records you want to update. On the Create tab, in the Queries group, click Query Design. Click...
Read more >Use SELECT inside an UPDATE query - Stack Overflow
I wanted to find a string in one column and put that value in another column in the same table. The select statement...
Read more >SELECT FOR UPDATE | CockroachDB Docs
The SELECT FOR UPDATE statement is used to order transactions by controlling concurrent access to one or more rows of a table. It...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the report. Throwing error sounds good.
Also probably knex should throw an error in every case where calling new builder method changes some update -> plain select.
With
.returning
not being supported by all dialects it might not be good to give.first()
two different meanings between dialects.I would opt for just throwing an error that update was changed to select.