simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
370 stars 29 forks source link

postgresql - search_path #31

Closed KaeruCT closed 3 years ago

KaeruCT commented 3 years ago

I ran this:

db-to-sqlite "postgresql://user:pwd@192.168.0.150/dbname" sqlite.db --progress --table=artist

I kept getting this error.

Traceback (most recent call last):
  File "/home/andres/.local/bin/db-to-sqlite", line 8, in <module>
    sys.exit(cli())
  File "/home/andres/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/andres/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/andres/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/andres/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/andres/.local/lib/python3.8/site-packages/db_to_sqlite/cli.py", line 75, in cli
    pks = inspector.get_pk_constraint(table)["constrained_columns"]
  File "/home/andres/.local/lib/python3.8/site-packages/sqlalchemy/engine/reflection.py", line 528, in get_pk_constraint
    return self.dialect.get_pk_constraint(
  File "<string>", line 2, in get_pk_constraint
  File "/home/andres/.local/lib/python3.8/site-packages/sqlalchemy/engine/reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "/home/andres/.local/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/base.py", line 3863, in get_pk_constraint
    table_oid = self.get_table_oid(
  File "<string>", line 2, in get_table_oid
  File "/home/andres/.local/lib/python3.8/site-packages/sqlalchemy/engine/reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "/home/andres/.local/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/base.py", line 3465, in get_table_oid
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: artist

It also happened if I added the full name of the table:

db-to-sqlite "postgresql://user:pwd@192.168.0.150/dbname" sqlite.db --progress --table=my_postgres_schema.artist

Then I added this after creating the db_conn variable, and it worked: db_conn.execute('SET search_path TO <my_postgres_schema>')

Is there a way to get this to work without modifying the program, or am I doing something wrong?

simonw commented 3 years ago

Good news: #29 addresses this.