electric-sql / pglite

Lightweight Postgres packaged as WASM into a TypeScript library for the browser, Node.js, Bun and Deno
https://electric-sql.com
Apache License 2.0
4.77k stars 81 forks source link

Missing "pg_catalog.pg_tables" and "information_schema.tables" #8

Closed simonw closed 3 months ago

simonw commented 4 months ago

I tried running this SQL query:

select * from pg_catalog.pg_tables

But I got this error:

RuntimeError: relation "pg_catalog.pg_tables" does not exist at character 15

Is there a way to do this at the moment? If not, could there be?

kiwicopple commented 4 months ago

Interesting - most of the catalog tables are there, but not this one (src )

Could be due to the way the underlying fork handles the storage?

Full list of catalog image
simonw commented 4 months ago

Huh, yeah - this works for me

select * from pg_catalog.pg_type
simonw commented 4 months ago

This query works for me to list tables:

select relname from pg_class
join pg_namespace on pg_namespace.oid = pg_class.relnamespace
where pg_class.relkind = 'r'
and relname not like 'pg_%'
simonw commented 4 months ago

I've been playing around with this in an Observable Framework notebook here: https://simonw.github.io/observable-framework-experiments/postgresql

Source code here: https://github.com/simonw/observable-framework-experiments/blob/main/docs/postgresql.md?plain=1

samwillis commented 4 months ago

I believe this is due to the simplified initdb.ts that replaces the conventional initdb command that comes with Postgres. It's not fully creating all the catalog tables.

We should look at compiling initdb to wasm, although it runs postgres --boot which we would need to do separately which creates a little complexity.

kzlar commented 3 months ago

fyi also seeing this with await new PGlite("./pgdata").query('select * from pg_catalog.pg_roles'); Would be really awesome if pglite could work with postgraphile. I have a PoC repo I can share for testing if you're interested.

samwillis commented 3 months ago

The missing "pg_catalog.pg_tables" and "information_schema.tables" (among others) are fixed in #41 and we plan to do a release early next week after a few finals checks.

If anyone wants to take it for a spin, there is dev build linked in PR #48 which is the tip of a stack of PRs.