How to loop through each key/value pair in a jsonb OBJECT in postgresql stored procedure?
Can an insurance company drop you after receiving a bill and refusing to pay?
My cat mixes up the floors in my building. How can I help him?
Why are the books in the Game of Thrones citadel library shelved spine inwards?
Can I write a book of my D&D game?
Normalization for two bulk RNA-Seq samples to enable reliable fold-change estimation between genes
How long is the D&D Starter Set campaign?
Eww, those bytes are gross
How should I handle players who ignore the session zero agreement?
How can I get my players to come to the game session after agreeing to a date?
How to solve a large system of linear algebra?
Using only 1s, make 29 with the minimum number of digits
How do Chazal know that the descendants of a Mamzer may never marry into the general populace?
How to limit sight distance to 1 km
Why zero tolerance on nudity in space?
Avoiding morning and evening handshakes
Can a person refuse a presidential pardon?
Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?
Why isn't there a non-conducting core wire for high-frequency coil applications
Could a phylactery of a lich be a mirror or does it have to be a box?
Word or phrase for showing great skill at something WITHOUT formal training in it
Dilemma of explaining to interviewer that he is the reason for declining second interview
Do authors have to be politically correct in article-writing?
Would a National Army of mercenaries be a feasible idea?
Why avoid shared user accounts?
How to loop through each key/value pair in a jsonb OBJECT in postgresql stored procedure?
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
sql-server postgresql
New contributor
New contributor
New contributor
asked 34 secs ago
JaneLJaneL
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
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%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.
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.
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%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
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