Change values in hdb in KDB
I would like to change a certain value in one column in hdb to another value. I tried using dbmaint package. However I got some type error.
This is the code I have
fncol[DB;TBL;`col;x:ssr[string x;"100";"i"$"0"]];
I am trying to change the value 100 to 0 in this column to all dates in hdb.
kdb
add a comment |
I would like to change a certain value in one column in hdb to another value. I tried using dbmaint package. However I got some type error.
This is the code I have
fncol[DB;TBL;`col;x:ssr[string x;"100";"i"$"0"]];
I am trying to change the value 100 to 0 in this column to all dates in hdb.
kdb
add a comment |
I would like to change a certain value in one column in hdb to another value. I tried using dbmaint package. However I got some type error.
This is the code I have
fncol[DB;TBL;`col;x:ssr[string x;"100";"i"$"0"]];
I am trying to change the value 100 to 0 in this column to all dates in hdb.
kdb
I would like to change a certain value in one column in hdb to another value. I tried using dbmaint package. However I got some type error.
This is the code I have
fncol[DB;TBL;`col;x:ssr[string x;"100";"i"$"0"]];
I am trying to change the value 100 to 0 in this column to all dates in hdb.
kdb
kdb
edited Dec 7 '18 at 20:25
halfer
14.5k758111
14.5k758111
asked Nov 13 '18 at 21:29
TerryTerry
1147
1147
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
the reason you are getting a type error is because you attempting to a nested list(list of strings) into the ssr function.
I believe a vector conditional like ?[x=100;0;x]
would be much better suited to your needs. This function evaluates an if statement element wise on x, returning 0 where true and the original value where false.
add a comment |
fncol[`:.;`tab;`a;@[x;where x=100;:;0]]
Your lambda function can utilise amend in this case:
https://code.kx.com/q/ref/lists/#amend
I assume it is an integer column.
The above changes the value to 0 at indices where the current value is 100.
I would stress testing this thoroughly before applying to an important database.
add a comment |
In your function it looks like you are trying to replace a string values of 100 with integer values of 0. You will find this will be difficult because if your starting list is a list of strings, kdb will not let you just change some of the values to a different type.
q)l:("a";"b";"c")
q)l[0]:1
'type
[0] l[0]:1
^
q)l[0]:"d"
q)l
"dbc"
Also "i"$"0"
will convert the string to an integer type, whereas "I"$"0"
will parse the text inside "0" into an integer value. In reality this means that "i"$"0"
will become 48i as "0" is 48 in ASCII instead of 0.
If after you get the type error and get thrown into debug mode (indicated by multiple brackets at the q prompt) you can use functions .z.ex
and .z.ey
to see the failing function and arguments which may make it easier to debug
add a comment |
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%2f53289782%2fchange-values-in-hdb-in-kdb%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
the reason you are getting a type error is because you attempting to a nested list(list of strings) into the ssr function.
I believe a vector conditional like ?[x=100;0;x]
would be much better suited to your needs. This function evaluates an if statement element wise on x, returning 0 where true and the original value where false.
add a comment |
the reason you are getting a type error is because you attempting to a nested list(list of strings) into the ssr function.
I believe a vector conditional like ?[x=100;0;x]
would be much better suited to your needs. This function evaluates an if statement element wise on x, returning 0 where true and the original value where false.
add a comment |
the reason you are getting a type error is because you attempting to a nested list(list of strings) into the ssr function.
I believe a vector conditional like ?[x=100;0;x]
would be much better suited to your needs. This function evaluates an if statement element wise on x, returning 0 where true and the original value where false.
the reason you are getting a type error is because you attempting to a nested list(list of strings) into the ssr function.
I believe a vector conditional like ?[x=100;0;x]
would be much better suited to your needs. This function evaluates an if statement element wise on x, returning 0 where true and the original value where false.
answered Nov 13 '18 at 21:53
George SaundersGeorge Saunders
3244
3244
add a comment |
add a comment |
fncol[`:.;`tab;`a;@[x;where x=100;:;0]]
Your lambda function can utilise amend in this case:
https://code.kx.com/q/ref/lists/#amend
I assume it is an integer column.
The above changes the value to 0 at indices where the current value is 100.
I would stress testing this thoroughly before applying to an important database.
add a comment |
fncol[`:.;`tab;`a;@[x;where x=100;:;0]]
Your lambda function can utilise amend in this case:
https://code.kx.com/q/ref/lists/#amend
I assume it is an integer column.
The above changes the value to 0 at indices where the current value is 100.
I would stress testing this thoroughly before applying to an important database.
add a comment |
fncol[`:.;`tab;`a;@[x;where x=100;:;0]]
Your lambda function can utilise amend in this case:
https://code.kx.com/q/ref/lists/#amend
I assume it is an integer column.
The above changes the value to 0 at indices where the current value is 100.
I would stress testing this thoroughly before applying to an important database.
fncol[`:.;`tab;`a;@[x;where x=100;:;0]]
Your lambda function can utilise amend in this case:
https://code.kx.com/q/ref/lists/#amend
I assume it is an integer column.
The above changes the value to 0 at indices where the current value is 100.
I would stress testing this thoroughly before applying to an important database.
answered Nov 13 '18 at 21:53
jomahonyjomahony
1,51228
1,51228
add a comment |
add a comment |
In your function it looks like you are trying to replace a string values of 100 with integer values of 0. You will find this will be difficult because if your starting list is a list of strings, kdb will not let you just change some of the values to a different type.
q)l:("a";"b";"c")
q)l[0]:1
'type
[0] l[0]:1
^
q)l[0]:"d"
q)l
"dbc"
Also "i"$"0"
will convert the string to an integer type, whereas "I"$"0"
will parse the text inside "0" into an integer value. In reality this means that "i"$"0"
will become 48i as "0" is 48 in ASCII instead of 0.
If after you get the type error and get thrown into debug mode (indicated by multiple brackets at the q prompt) you can use functions .z.ex
and .z.ey
to see the failing function and arguments which may make it easier to debug
add a comment |
In your function it looks like you are trying to replace a string values of 100 with integer values of 0. You will find this will be difficult because if your starting list is a list of strings, kdb will not let you just change some of the values to a different type.
q)l:("a";"b";"c")
q)l[0]:1
'type
[0] l[0]:1
^
q)l[0]:"d"
q)l
"dbc"
Also "i"$"0"
will convert the string to an integer type, whereas "I"$"0"
will parse the text inside "0" into an integer value. In reality this means that "i"$"0"
will become 48i as "0" is 48 in ASCII instead of 0.
If after you get the type error and get thrown into debug mode (indicated by multiple brackets at the q prompt) you can use functions .z.ex
and .z.ey
to see the failing function and arguments which may make it easier to debug
add a comment |
In your function it looks like you are trying to replace a string values of 100 with integer values of 0. You will find this will be difficult because if your starting list is a list of strings, kdb will not let you just change some of the values to a different type.
q)l:("a";"b";"c")
q)l[0]:1
'type
[0] l[0]:1
^
q)l[0]:"d"
q)l
"dbc"
Also "i"$"0"
will convert the string to an integer type, whereas "I"$"0"
will parse the text inside "0" into an integer value. In reality this means that "i"$"0"
will become 48i as "0" is 48 in ASCII instead of 0.
If after you get the type error and get thrown into debug mode (indicated by multiple brackets at the q prompt) you can use functions .z.ex
and .z.ey
to see the failing function and arguments which may make it easier to debug
In your function it looks like you are trying to replace a string values of 100 with integer values of 0. You will find this will be difficult because if your starting list is a list of strings, kdb will not let you just change some of the values to a different type.
q)l:("a";"b";"c")
q)l[0]:1
'type
[0] l[0]:1
^
q)l[0]:"d"
q)l
"dbc"
Also "i"$"0"
will convert the string to an integer type, whereas "I"$"0"
will parse the text inside "0" into an integer value. In reality this means that "i"$"0"
will become 48i as "0" is 48 in ASCII instead of 0.
If after you get the type error and get thrown into debug mode (indicated by multiple brackets at the q prompt) you can use functions .z.ex
and .z.ey
to see the failing function and arguments which may make it easier to debug
answered Nov 13 '18 at 22:11
Mark KellyMark Kelly
1,494214
1,494214
add a comment |
add a comment |
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%2f53289782%2fchange-values-in-hdb-in-kdb%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