Public
Edited
Mar 3, 2023
1 star
Insert cell
Insert cell
db = {
const c = await DuckDBClient.of({});
await c.query(`CREATE TABLE dt(u STRING, x BIGINT, y FLOAT, z INTEGER)`);
await c.query(
`INSERT INTO dt VALUES ('a', 1, 5, 1), ('b', 2, 6, 2), ('c', 3, 7, 3), ('d', 4, 8, 4);`
);
return c;
}
Insert cell
db
SELECT * FROM dt
Insert cell
a.map((d) => d.x) // bigint
Insert cell
db
SELECT *, x::int x FROM dt
Insert cell
b.map((d) => d.x) // number!
// 🌶 SELECT *, x::int x select x twice, first as part of * and as a BigInt, then on its own. It seems that the first has precedence, which explains the outcome.
Insert cell
db
SELECT x::int x, * FROM dt
Insert cell
c.map((d) => d.x) // int
Insert cell
Insert cell
db.query("SELECT x::INT AS x FROM dt").then((res) => res.map((d) => d.x))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more