Skip to content

Append ARRAY with Data Chunk #204

Answered by jraymakers
nshiab asked this question in Q&A
Discussion options

You must be logged in to vote

To add a third column of type FLOAT[3] (i.e. ARRAY of FLOAT, length 3):

const chunk = DuckDBDataChunk.create([INTEGER, VARCHAR, ARRAY(FLOAT, 3)]);
chunk.setColumns([
  [42, 123, 17],
  ['duck', 'mallad', 'goose'],
  [ arrayValue([1.23, 2.45, 3.45]), arrayValue([1.23, 2.45, 3.45]), arrayValue([1.23, 2.45, 3.45]) ]
]);

Note that you need to wrap the JS arrays with arrayValue. This is because DuckDB supports multiple array-like data types. ARRAY values are for fixed-length, while LIST values are variable-length. To add a third column of type FLOAT[] (i.e. LIST of FLOAT, variable length), you'd do:

const chunk = DuckDBDataChunk.create([INTEGER, VARCHAR, LIST(FLOAT)]);
chunk.setColumns([
  [42, 

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@jraymakers
Comment options

Answer selected by nshiab
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants