DolphinDB currently does not support storing dictionary variables in a table, but you can use the function toStdJson
to convert a dictionary into a STRING for storage. The strings can be converted back into dictionaries with parseExpr().eval()
.
config = dict(STRING, ANY)
config[`name] = `dmc
config[`desc] = "minute factor"
config[`upper] = [`oles, `macd]
config[`ParamKeys] = [`win,`high,`times,`range]
config[`ParamValues] = [3,10,20,[`abc,`adc]]
// convert a dictionary to string
config_string = toStdJson(config)
// convert a string to dictionary
config_dict = parseExpr(config_string).eval()
Note: In DolphinDB, the size limit for a single string is 64KB. If your parameter dictionary is large, you can split out the parameters with fixed data type and size to store them in separate columns.
For parameters whose values are string arrays, such as variable names containing only letters, numbers and underscores, consider concatenating the strings into a long string. Add a special character between the concatenated strings so you can split()
them apart again later.
config[`ParamKeys]=[`win,`high,`times,`range]
// convert a string array to a long string
longString = concat(config[`ParamKeys], ",")
// split a string into an array of strings
stringArray = split(longString , ",")