Reputation: 1157
I have created one table named as test
in KDB using following statement
test:([doc_id:`int$()];doc_displayid:`symbol$();doc_created_date:`date$();doc_aacess_date:`timestamp$();is_native_exist:`boolean$();file_size:`real$())
Now I want to insert a record in this
I've tried many ways like
- insert['test; (1;`D_30;.z.d;.z.P;T;8.5)]
- insert['test ([];`D_30;2018.8.8;2018.8.9T12:00:00.123;T;8.5)]
- insert['test (1;`D_30;.z.d;2018.8.9T12:00:00.123;T;8.5)]
- insert['test (1;`D_30;.z.d;2018.8.9T12:00:00.123;T;8.5)]
- 'test insert (1;`D_30;2018.8.8;2018.7.8T12:00:00.123;T;8.5)
But it doesn't work.
So please help me to solve this problem.
Thanks in advance.
Upvotes: 2
Views: 4088
Reputation: 3229
There are multiple issues with your insert
statements, please check out the KDB datatypes wiki for examples
symbol should be defined with `
(uptick) i.e. `test
, should not be 'test
doc_id is defined as int
, so you need to pass an explicit i
.e.g. 1i
, 2i
There is no T
boolean variable defined.
Real should be defined with an explicit e
at the end. (8.5e)
timestamp is defined as dateDtimespan
(D
)
You can use either insert
or upsert
. upsert
allows you to overwrite the record for already inserted record, however, the insert
will ensure that you always enter a unique key, otherwise, it will throw an error.
upsert[`test; (1i;`D_30;.z.d;.z.P;0b;8.5e)]
insert[`test ;(2i;`D_30;2018.08.08;2018.08.09D12:00:00.123123123;0b;8.5e)]
doc_id| doc_displayid doc_created_date doc_aacess_date is_native_exist file_size
------| --------------------------------------------------------------------------------------
1 | D_30 2018.08.21 2018.08.21D07:33:40.630975000 0 8.5
2 | D_30 2018.08.08 2018.08.09D12:00:00.123123123 0 8.5
Upvotes: 2
Reputation: 1663
Check the type
of your input variables before insert
in your test table.
Basically:
1
is of type long, not int;2018.07.08T12:00:00.123
is of type datetime, not timestamp;T
does not exist, for boolean you should write 1b
for true;8.5
is of type float, not real.When converting the above to the appropriate format, the insert
works provided that you use backtick `test
not 'test
:
`test insert (1i;`D_30;2018.08.08;"p"$2018.07.08T12:00:00.123;1b;8.5e)
doc_id| doc_displayid doc_created_date doc_aacess_date is_native_exist file_size
------| --------------------------------------------------------------------------------------
1 | D_30 2018.08.08 2018.07.08D12:00:00.123000000 1 8.5
Upvotes: 5