# Loading a duckdb database

**URL:** <https://talk.observablehq.com/t/loading-a-duckdb-database/8977>\
**Category:** Help\
**Created:** [March 21, 2024, 11:14pm UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977 "2024-03-21T23:14:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 21, 2024, 11:14pm UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/1 "2024-03-21T23:14:19Z")

</div>

Hello,  
I noticed that I can create DuckDB using FileAttachments loading data from json, tsv etc but not directly from a duckdb database? Is this possible?

Thanks much  
Saptarshi

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [March 21, 2024, 11:47pm UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/2 "2024-03-21T23:47:32Z")

</div>

Since v1.4.0, yes

> **[Release v1.4.0 · observablehq/framework](https://github.com/observablehq/framework/releases/tag/v1.4.0)**
>
> Improved SQL and DuckDB 🦆
> SQL code blocks and DuckDBClient now support querying remotely-hosted data. This is especially useful for live, rapidly-changing data that you do not want to “bake-in” to ...

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 22, 2024, 12:30am UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/3 "2024-03-22T00:30:32Z")

</div>

Thanks! The reason I ask is because I have a costly process that produces two csv which I thought could keep in two tables in a duckdb table. I would stream this out to standard output

In the markdown I would use FileAttachment that reads “mydata.dudkdb.py” and produce a DuckDb database connection in the observable framework side of things

Is this the right way of thinking of the changes?

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 23, 2024, 6:35am UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/4 "2024-03-23T06:35:02Z")

</div>

It appears to elude me. In the markdown I have

```auto
const db = new DuckDBClient(FileAttachment("./data/download_data.duckdb"))

```

and the corresponding python `download_data.duckdb.py` code ends with

```auto
    conn = duckdb.connect(database=tempfile)   
    conn.execute("CREATE TABLE t1 AS SELECT * FROM dcsv")
    conn.execute("CREATE TABLE t2 AS SELECT * FROM dproj") 
    conn.close()
    with open(tempfile, 'rb') as file:
        sys.stdout.buffer.write(file.read())

```

This works, but it looks I have an empty client.

 ![Screenshot 2024-03-22 at 11.39.55 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/0/017e0997f5c3212cdff56ce896cd687e8d3c13bd.png)

When I try submitting a query, I get `RuntimeError: this._db.connect is not a function. (In 'this._db.connect()', 'this._db.connect' is undefined)`  
thanks much  
Saptarshi

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 23, 2024, 6:56am UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/5 "2024-03-23T06:56:10Z")

</div>

Looks like the documentation has the answer

_You can also [attach](https://duckdb.org/docs/sql/statements/attach) a complete database saved as DuckDB file, typically using the `.db` file extension (or `.ddb` or `.duckdb`). In this case, the associated name (below `base`) is a schema name rather than a table name._

```auto
const db2 = await DuckDBClient.of({base: FileAttachment("quakes.db")});

```

([DuckDB | Observable Framework](https://observablehq.com/framework/lib/duckdb))  
thank you again.

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 23, 2024, 7:05am UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/6 "2024-03-23T07:05:36Z")

</div>

Lastly,(sorry for the noise!), I have used duckdb 0.10 python API and confirmed the database I created can be opened by duckdb CLI client. But in Observable framework, I see

```auto
RuntimeError: INTERNAL Error: Unsupported compression function type

```

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [March 23, 2024, 12:59pm UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/7 "2024-03-23T12:59:13Z")

</div>

The DuckDB format has been changing with every version. They’ve [promised](https://duckdb.org/2024/02/13/announcing-duckdb-0100.html) to have backward compatibility starting with 0.10.0, but Framework is still using 0.9.3 or something (it’s easy to get lost in this maze of version numbers). So for now I’d recommend to … wait a few weeks.

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 23, 2024, 5:07pm UTC](https://talk.observablehq.com/t/loading-a-duckdb-database/8977/8 "2024-03-23T17:07:09Z")

</div>

Thanks much! Currently experimenting so can wait.
