How to loop through each key/value pair in a jsonb OBJECT in postgresql stored procedure?

If I deleted a game I lost the disc for, can I reinstall it digitally?

Porting Linux to another platform requirements

awk + sum all numbers

Why zero tolerance on nudity in space?

Find some digits of factorial 17

Early credit roll before the end of the film

Strange Sign on Lab Door

Word or phrase for showing great skill at something WITHOUT formal training in it

Can making a creature unable to attack after it has been assigned as an attacker remove it from combat?

How long is the D&D Starter Set campaign?

Intern applicant asking for compensation equivalent to that of permanent employee

CREATE ASSEMBLY System.DirectoryServices.AccountManagement.dll without enabling TRUSTWORTHY

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Why is mind meld hard for T'pol in Star Trek: Enterprise?

Eww, those bytes are gross

How should I handle players who ignore the session zero agreement?

How would an AI self awareness kill switch work?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?

Caruana vs Carlsen game 10 (WCC) why not 18...Nxb6?

Publishing research using outdated methods

Can I become debt free or should I file bankruptcy ? How to manage my debt and finances?

Normalization for two bulk RNA-Seq samples to enable reliable fold-change estimation between genes

Are there any modern advantages of a fire piston?

How much mayhem could I cause as a sentient fish?



How to loop through each key/value pair in a jsonb OBJECT in postgresql stored procedure?














0















I am trying to create a function in postgres that can loop through each key/value pair in a given jsonb object.



create or replace function myFunction
(input jsonb)
returns jsonb as $$
BEGIN

// foreach(key in input)
// do some math operation on its corresponding value

returns input;

END; $$


The argument input is expected to be a jsonb OBJECT, such as {"a":1, "b":2, "c":3}.



So what I want to do, is to loop through each "key":value pair in the object. As you can tell from my comment, I used to write backend code with more general-purpose programming languages like c, java, etc. So I am not good at sql. I have tried to search online, but they talk about how to loop through jsonb array instead of object. So really stuck here.









share







New contributor




JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I am trying to create a function in postgres that can loop through each key/value pair in a given jsonb object.



    create or replace function myFunction
    (input jsonb)
    returns jsonb as $$
    BEGIN

    // foreach(key in input)
    // do some math operation on its corresponding value

    returns input;

    END; $$


    The argument input is expected to be a jsonb OBJECT, such as {"a":1, "b":2, "c":3}.



    So what I want to do, is to loop through each "key":value pair in the object. As you can tell from my comment, I used to write backend code with more general-purpose programming languages like c, java, etc. So I am not good at sql. I have tried to search online, but they talk about how to loop through jsonb array instead of object. So really stuck here.









    share







    New contributor




    JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am trying to create a function in postgres that can loop through each key/value pair in a given jsonb object.



      create or replace function myFunction
      (input jsonb)
      returns jsonb as $$
      BEGIN

      // foreach(key in input)
      // do some math operation on its corresponding value

      returns input;

      END; $$


      The argument input is expected to be a jsonb OBJECT, such as {"a":1, "b":2, "c":3}.



      So what I want to do, is to loop through each "key":value pair in the object. As you can tell from my comment, I used to write backend code with more general-purpose programming languages like c, java, etc. So I am not good at sql. I have tried to search online, but they talk about how to loop through jsonb array instead of object. So really stuck here.









      share







      New contributor




      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am trying to create a function in postgres that can loop through each key/value pair in a given jsonb object.



      create or replace function myFunction
      (input jsonb)
      returns jsonb as $$
      BEGIN

      // foreach(key in input)
      // do some math operation on its corresponding value

      returns input;

      END; $$


      The argument input is expected to be a jsonb OBJECT, such as {"a":1, "b":2, "c":3}.



      So what I want to do, is to loop through each "key":value pair in the object. As you can tell from my comment, I used to write backend code with more general-purpose programming languages like c, java, etc. So I am not good at sql. I have tried to search online, but they talk about how to loop through jsonb array instead of object. So really stuck here.







      sql-server postgresql





      share







      New contributor




      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 49 secs ago









      JaneLJaneL

      1




      1




      New contributor




      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      JaneL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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
          });


          }
          });






          JaneL is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f231016%2fhow-to-loop-through-each-key-value-pair-in-a-jsonb-object-in-postgresql-stored-p%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








          JaneL is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          JaneL is a new contributor. Be nice, and check out our Code of Conduct.













          JaneL is a new contributor. Be nice, and check out our Code of Conduct.












          JaneL is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • 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%2fdba.stackexchange.com%2fquestions%2f231016%2fhow-to-loop-through-each-key-value-pair-in-a-jsonb-object-in-postgresql-stored-p%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

          Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...