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










2















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?










share|improve this question


























    2















    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?










    share|improve this question
























      2












      2








      2








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 16:43









      Ian BurnsIan Burns

      111




      111






















          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
          );



          );













          draft saved

          draft discarded


















          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















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович