{"by":"frectonz","descendants":110,"id":42182146,"kids":[42183625,42183560,42183246,42184372,42183335,42184606,42186653,42281349,42183685,42192888,42185178,42183353,42184656,42186385,42185971,42186297,42183907,42184052,42186417,42183817,42185516,42191714,42184254,42187585,42191252,42186715,42184370,42198877,42187550,42183327,42184000],"score":180,"text":"pglite-fusion is a PostgreSQL extension that allows you to embed SQLite databases into your PostgreSQL tables by enabling the creation of columns with the `SQLITE` type. This means every row in the table can have an embedded SQLite database.<p>In addition to the PostgreSQL `SQLITE` type, pglite-fusion provides the `query_sqlite`` function for querying SQLite databases and the `execute_sqlite` function for updating them. Additional functions are listed in the project’s README.<p>The pglite-fusion extension is written in Rust using the pgrx framework [1].<p>----<p>Implementation Details<p>The PostgreSQL `SQLITE` type is stored as a CBOR-encoded `Vec&lt;u8&gt;`. When a query is made, this `Vec&lt;u8&gt;` is written to a random file in the `&#x2F;tmp` directory. SQLite then loads the file, performs the query, and returns the result as a table containing a single row with an array of JSON-encoded values.<p>The `execute_sqlite` function follows a similar process. However, instead of returning query results, it returns the contents of the SQLite file (stored in `&#x2F;tmp`) as a new `SQLITE` instance.<p>[1] <a href=\"https:&#x2F;&#x2F;github.com&#x2F;pgcentralfoundation&#x2F;pgrx\">https:&#x2F;&#x2F;github.com&#x2F;pgcentralfoundation&#x2F;pgrx</a>","time":1732014152,"title":"Show HN: Embed an SQLite database in your PostgreSQL table","type":"story","url":"https://github.com/frectonz/pglite-fusion"}