Ramprasad
Ramprasad

Reputation: 75

In KDB, how to bulk insert into a table containing a column of type String

In a table with a column of type string (not symbol) I am able to insert a row one by one. But bulk insert is not working!

    t:([id:`int$()] str:()) /create table
    `t insert(0, enlist enlist "test") /insert first row. This seems to need two enlist
    `t insert(1, enlist "test1") /insert one more, this time with one enlist
    `t insert (2 3; enlist "test2" enlist "test3") /trying to bulk insert fails
    `t insert flip (2 3; enlist "test2" enlist "test3") /trying to bulk insert with flip also fails

Upvotes: 2

Views: 1363

Answers (1)

Rahul
Rahul

Reputation: 3969

I would prefer semicolon instead of comma in insert command. That makes the syntax more simple which also makes it easy to understand. Because of comma syntax, 2 enlist are required in your first insert.

Syntax you are using for bulk insert is not correct. Its very simple as below:

   q)   t:([id:`int$()] str:())  / create table
   q) `t insert (0;enlist "test")   / insert first row
   q)  `t insert (1 2;("test1";"test2"))  / bulk insert 2 rows

Upvotes: 1

Related Questions