Change values in hdb in KDB










1















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.










share|improve this question




























    1















    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.










    share|improve this question


























      1












      1








      1








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 7 '18 at 20:25









      halfer

      14.5k758111




      14.5k758111










      asked Nov 13 '18 at 21:29









      TerryTerry

      1147




      1147






















          3 Answers
          3






          active

          oldest

          votes


















          1














          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.






          share|improve this answer






























            2














            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.






            share|improve this answer






























              2














              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






              share|improve this answer






















                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%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









                1














                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.






                share|improve this answer



























                  1














                  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.






                  share|improve this answer

























                    1












                    1








                    1







                    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.






                    share|improve this answer













                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 13 '18 at 21:53









                    George SaundersGeorge Saunders

                    3244




                    3244























                        2














                        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.






                        share|improve this answer



























                          2














                          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.






                          share|improve this answer

























                            2












                            2








                            2







                            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.






                            share|improve this answer













                            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.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 '18 at 21:53









                            jomahonyjomahony

                            1,51228




                            1,51228





















                                2














                                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






                                share|improve this answer



























                                  2














                                  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






                                  share|improve this answer

























                                    2












                                    2








                                    2







                                    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






                                    share|improve this answer













                                    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







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 13 '18 at 22:11









                                    Mark KellyMark Kelly

                                    1,494214




                                    1,494214



























                                        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%2f53289782%2fchange-values-in-hdb-in-kdb%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







                                        這個網誌中的熱門文章

                                        How to read a connectionString WITH PROVIDER in .NET Core?

                                        Node.js Script on GitHub Pages or Amazon S3

                                        Museum of Modern and Contemporary Art of Trento and Rovereto