pom
pom

Reputation: 340

KDB: How do you initialize a column in a table as String

I notice that a column gets only assigned with a String datatype only after a first non-null/empty entry is made.

meta select AsOfDate from t
c         t   f  a
AsOfDate 

After inserting a record:

meta select AsOfDate from t
c         t   f  a
AsOfDate  C

Is there any cleaner way to assign a string datatype to a column?

Upvotes: 1

Views: 1707

Answers (2)

notlightnorchroma
notlightnorchroma

Reputation: 376

Some developers store an initialization/prototype row (row 0) that is never used or accessed. The key values are such that calling code would not fetch it. Or some sort of "soft delete" flag column

Once the table has real rows, you could delete the prototype row, but the logic is messy and it could be costly if you delete that row when there are millions of rows in the table or it is persisted to disk.

I wish the "meta" of a table was sticky so when all rows are deleted, it keeps ALL the types around.

q)tbl:([] a:1; b:1.1; c:1#enlist "abc")
q)meta tbl
c| t f a
-| -----
a| j    
b| f    
c| C    
q)meta 1_tbl
c| t f a
-| -----
a| j    
b| f    
c|

Upvotes: 3

jomahony
jomahony

Reputation: 1692

Unfortunately kdb+ does not allow one to define column types as list of lists during table creation (string is simply a list of lists of characters).

You have correctly noticed that you'll have to ensure that your first entry is of string type.

Upvotes: 2

Related Questions