Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL cell casts timestamps as dates #610

Open
nachocab opened this issue Dec 8, 2023 · 1 comment
Open

SQL cell casts timestamps as dates #610

nachocab opened this issue Dec 8, 2023 · 1 comment
Labels
Bug Something isn't working

Comments

@nachocab
Copy link

nachocab commented Dec 8, 2023

I was hoping there was a way to query an array of objects without losing the time. Here's an example notebook.

CleanShot 2023-12-08 at 17 41 52@2x

@mootari
Copy link
Member

mootari commented Dec 8, 2023

Yep, that's an open bug in DuckDB: duckdb/duckdb-wasm#1231

The workaround is to ingest dates as ISO date strings, then change the column type:

{
  const data = [
    {create_time: new Date()}
  ];
  
  const client = await DuckDBClient.of({
    // Ingest dates as ISO strings
    my_data: data.map(d => ({
      ...d,
      create_time: d.create_time.toISOString()
    }))
  });
  
  // Changes the column type from Utf8 to Date64
  await client.sql`ALTER TABLE my_data ALTER COLUMN create_time SET DATA TYPE DATETIME`;

  // Should read "Date64<MILLISECOND>"
  const columnType = (await client.query("SELECT create_time FROM my_data")).schema[0].databaseType;
  
  return client;
}

@mootari mootari added the Bug Something isn't working label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants