DuckDB weirdness with sum()

My question concerns the behavior seen in the following code (inserted in a Framework markdown file):

```sql id=[test]
create table tbl (a varchar, b integer);
insert into tbl (a, b) values ('a', 31);
insert into tbl (a, b) values ('aa', 42);
select sum(b) as x from tbl;

(I backslash-escaped some triple-backquotes to not break the formatting).

For some reason test.x displays as Yt(4) [292, 0, 0, 0] (some array-like object?), so the output of ${test.x} gets three extra zeros appended.

This does not happen with other aggregate functions.


This is because by default sum() switches to DuckDB’s version of a bignum (they seem to call it HUGEINT). You can fix that by changing your last line to

select sum(b)::integer as x from tbl;

I’m not entirely sure how [292, 0, 0, 0] ends up representing 73 though :man_shrugging:.

PS: On the forum you can replace the triple-backticks with triple-tildes (~) so that you can paste Framework code in unmodified.

Thanks for the explanation.

The 292 was some copy/paste mistake of mine, idk where it came from.