Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

kdb/Q How to update single row in table?

I’m trying to find out how I can update a single value in a single, specified row in my table.

What I need is to go from this:

table – before

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Index Value
0 a
1 b
2 c

to this, specifically targeting row with Index at 2:

table – after

Index Value
0 a
1 c
2 c

I think something like this is a start: table: update Value:?[Value="b";"c";Value] from table[rowIndex], but this only updates and returns the one row, I’m trying to find a way to keep the table as is and ONLY alter the value in the given row.

>Solution :

You can use a where clause to only update where the condition is met, as long as there is only one row that meets the condition:

table: update Value:"c" from table where Value="b"

If there is more than one row meeting the condition you may want to filter using rowIndex:

table: update Value:?[Value="b";"c";Value] from table where i=rowIndex

OR you might be able to skip the conditional:

table: update Value:"c" from table where i=rowIndex
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading