Add Null date 0Nd to date column for empty cells in kdb

Viewed 126

trying to update empty cells with null date i.e 0Nd for Date column data: update date:0Nd^date from data where product not like "Debet:Loan";

Note: column type is date

Class product date
First Debet:Instru:*
First Debet:Instru:*
First Debet:Loan 2020.10.12
First Debet:Loan 2020.10.12

after change the table should look like

Class product date
First Debet:Instru:* 0Nd
First Debet:Instru:* 0Nd
First Debet:Loan 2020.10.12
First Debet:Loan 2020.10.12
1 Answers

I think the confusion here lies in the fact that the console will display a cell as empty if it is null AND the datatype of the column (a list) is not mixed.

For example:

q)0Nd~first 0N 2021.01.01d
1b

the null here is actually of type 0Nd as the list is of type date. You can think of this as similar to the way the console will display a list of floats that are whole numbers - the f in this case is assumed or "inherited" by the last element in the list >

q)`float$1 2 3 4
1 2 3 4f

If you truly want to have 0Nd DISPLAYED in your table you would have to make the column a mixed list - thus forcing the console to show you the exact type of Null as you cannot assume it based on the type of the column:

q)([]a: 1 2 3;date:(0Nd;10;2021.01.01d))
a date
------------
1 0Nd
2 10
3 2021.01.01

Please dont do this - the null in a column which displays as an empty cell is 0Nd even though it is not explicitly shown in the console or might appear as 0N in a list of dates e.g 0N 2021.01.01 2022.01.01

q)t:([]a: 1 2 3;date:(0Nd;2021.10.10;2021.01.01d))
q)t
a date
------------
1
2 2021.10.10
3 2021.01.01
q)exec date from t
0N 2021.10.10 2021.01.01
q)first exec date from t
0Nd

Thanks

Related