如何更改KDb+;中的数据类型;?
我在KDb+中创建了如下表:如何更改KDb+;中的数据类型;?,kdb,alter-table,Kdb,Alter Table,我在KDb+中创建了如下表: test:([doc_id:`symbol$()];doc_displayid:`symbol$();doc_created_date:`date$();doc_aacess_date:`timestamp$();is_native_exist:`boolean$();file_size:`real$()) 现在我想将列doc\u id的数据类型从symbol更改为int 如何更改测试表和更改数据类型?在将列转换为int之前,您需要将列转换为字符串: q)upda
test:([doc_id:`symbol$()];doc_displayid:`symbol$();doc_created_date:`date$();doc_aacess_date:`timestamp$();is_native_exist:`boolean$();file_size:`real$())
现在我想将列doc\u id
的数据类型从symbol
更改为int
如何更改测试表和更改数据类型?在将列转换为int之前,您需要将列转换为字符串:
q)update "I"$string doc_id from test
doc_id| doc_displayid doc_created_date doc_aacess_date is_native_exist file_s..
------| ---------------------------------------------------------------------..
您可以使用meta
验证新类型:
q)meta update "I"$string doc_id from test
c | t f a
----------------| -----
doc_id | i
doc_displayid | s
doc_created_date| d
doc_aacess_date | p
is_native_exist | b
file_size | e
需要先将列转换为字符串,然后才能将其转换为int:
q)update "I"$string doc_id from test
doc_id| doc_displayid doc_created_date doc_aacess_date is_native_exist file_s..
------| ---------------------------------------------------------------------..
您可以使用meta
验证新类型:
q)meta update "I"$string doc_id from test
c | t f a
----------------| -----
doc_id | i
doc_displayid | s
doc_created_date| d
doc_aacess_date | p
is_native_exist | b
file_size | e
为什么我需要将其转换为字符串?我已检查是否不需要在转换为整数之前转换为字符串。谢谢@thomas Smyth如果您尝试直接从符号转换为int,您将发现它会抛出并出错(例如,
“I”$`123`456
)。转换为字符串基本上是两种类型之间的中间人。正如为什么必须将其转换为字符串一样:kdb中的符号是内部字符串,即所有字符串值的唯一副本存储在全局字典中,而符号只是对该字典的引用。因此,当您编写“I”$`123
时,您实际尝试转换的是一个引用(将其视为试图更改框上的标签,而不是框中的内容!)当您编写“I”$string`123
时,首先获得引用点的值,然后转换该值(更改框中的内容)希望这有助于我为什么需要将其转换为字符串?在转换为整数之前,我已检查是否不需要转换为字符串。谢谢@thomas Smyth如果您尝试直接从符号转换为int,您将发现它会抛出并出错(例如,“I”$`123`456
)。转换为字符串基本上是两种类型之间的中间人。正如为什么必须将其转换为字符串一样:kdb中的符号是内部字符串,即所有字符串值的唯一副本存储在全局字典中,而符号只是对该字典的引用。因此,当您编写“I”$`123
时,您实际上试图转换的是一个引用(将其视为试图更改框上的标签,而不是框中的内容!)当您编写“I”$string`123
时,您首先获得引用点的值,然后转换该值(更改框中的内容),希望这会有所帮助