Postgres SubQuery Limit For Update not respecting Limit The Next CEO of Stack OverflowHow do I limit the number of rows returned by an Oracle query after ordering?How can I do an UPDATE statement with JOIN in SQL?Update a table using JOIN in SQL Server?updating table rows in postgres using subquerypostgres: upgrade a user to be a superuser?How to only run subquery if query has rows?How to improve LIMIT clause in MySQL subquery?Limiting rows from Joined SubqueryMySQL select not equal to limit in subqueryPostgres subquery limits
Why do airplanes bank sharply to the right after air-to-air refueling?
A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See
Is micro rebar a better way to reinforce concrete than rebar?
How to avoid supervisors with prejudiced views?
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Which one is the true statement?
Easy to read palindrome checker
Bartok - Syncopation (1): Meaning of notes in between Grand Staff
How a 64-bit process virtual address space is divided in Linux?
Can MTA send mail via a relay without being told so?
Proper way to express "He disappeared them"
Is wanting to ask what to write an indication that you need to change your story?
Flying from Cape Town to England and return to another province
Reference request: Grassmannian and Plucker coordinates in type B, C, D
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
What connection does MS Office have to Netscape Navigator?
Find non-case sensitive string in a mixed list of elements?
Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?
Should I cite using beginthebibliography or beginfilecontents*
Is there always a complete, orthogonal set of unitary matrices?
Is it possible to replace duplicates of a character with one character using tr
Is it convenient to ask the journal's editor for two additional days to complete a review?
Why did CATV standarize in 75 ohms and everyone else in 50?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Postgres SubQuery Limit For Update not respecting Limit
The Next CEO of Stack OverflowHow do I limit the number of rows returned by an Oracle query after ordering?How can I do an UPDATE statement with JOIN in SQL?Update a table using JOIN in SQL Server?updating table rows in postgres using subquerypostgres: upgrade a user to be a superuser?How to only run subquery if query has rows?How to improve LIMIT clause in MySQL subquery?Limiting rows from Joined SubqueryMySQL select not equal to limit in subqueryPostgres subquery limits
I recently upgraded my postgres db from 9.5.4 to 10.7 and noticed some odd behavior with an existing query.
The trimmed down version looks like this:
update
mytable
set
job_id = 6
where
id in (
select * from
(
select id from
mytable
where job_id is null
limit 2
) x for update)
and job_id is null
I would expect the number of rows to be updated to equal 2, but instead it is updating all the records that match the subquery without the limit. If I remove the for update statement, or the matching job_id is null statement, the records updated does equal 2 as expected. Before we updated this query would update the correct number of rows.
Did some behavior in 10.x change?
postgresql sql-update subquery limit select-for-update
add a comment |
I recently upgraded my postgres db from 9.5.4 to 10.7 and noticed some odd behavior with an existing query.
The trimmed down version looks like this:
update
mytable
set
job_id = 6
where
id in (
select * from
(
select id from
mytable
where job_id is null
limit 2
) x for update)
and job_id is null
I would expect the number of rows to be updated to equal 2, but instead it is updating all the records that match the subquery without the limit. If I remove the for update statement, or the matching job_id is null statement, the records updated does equal 2 as expected. Before we updated this query would update the correct number of rows.
Did some behavior in 10.x change?
postgresql sql-update subquery limit select-for-update
add a comment |
I recently upgraded my postgres db from 9.5.4 to 10.7 and noticed some odd behavior with an existing query.
The trimmed down version looks like this:
update
mytable
set
job_id = 6
where
id in (
select * from
(
select id from
mytable
where job_id is null
limit 2
) x for update)
and job_id is null
I would expect the number of rows to be updated to equal 2, but instead it is updating all the records that match the subquery without the limit. If I remove the for update statement, or the matching job_id is null statement, the records updated does equal 2 as expected. Before we updated this query would update the correct number of rows.
Did some behavior in 10.x change?
postgresql sql-update subquery limit select-for-update
I recently upgraded my postgres db from 9.5.4 to 10.7 and noticed some odd behavior with an existing query.
The trimmed down version looks like this:
update
mytable
set
job_id = 6
where
id in (
select * from
(
select id from
mytable
where job_id is null
limit 2
) x for update)
and job_id is null
I would expect the number of rows to be updated to equal 2, but instead it is updating all the records that match the subquery without the limit. If I remove the for update statement, or the matching job_id is null statement, the records updated does equal 2 as expected. Before we updated this query would update the correct number of rows.
Did some behavior in 10.x change?
postgresql sql-update subquery limit select-for-update
postgresql sql-update subquery limit select-for-update
asked Mar 7 at 16:43
Ian BurnsIan Burns
111
111
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048882%2fpostgres-subquery-limit-for-update-not-respecting-limit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048882%2fpostgres-subquery-limit-for-update-not-respecting-limit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown