jupysql icon indicating copy to clipboard operation
jupysql copied to clipboard

supporting new versions of pgspecial

Open edublancas opened this issue 2 years ago • 11 comments

background: https://github.com/ploomber/jupysql/issues/347 Looks like pgspecial breaks if using psycopg2, since new versions need psycopg3. So we need to tell the user how to get it working.I'm thinking the workflow should go like this:

  1. User tries to run a meta-command e.g. \d
  2. We show a "missing pgspecial error" but customize it depending on which psycopg2 version they're using (because if they use psycopg2, they need a lower version of pgspecial)

I think this might impact sqlalchemy asl well. unsure if sqlalchemy has support for psycopg3.

edublancas avatar Apr 05 '23 17:04 edublancas

For this task, the basic idea is that we need to edit in this file to check whether pgspecial will break and if breaks, we need to tell the user how should they do, such as need a lower version of pgspecial. code likes:


`python -c "import psycopg2, sqlalchemy; print('Psycopg2 version', psycopg2.__version__); print('Sqlalchemy version', sqlalchemy.__version__)"
psycopg2_version = psycopg2.__version__.split(' ')[0]
if psycopg2_version >= '2.9':
    error_msg = 'Please upgrade psycopg2 to a version that supports psycopg3.'
else:
    error_msg = 'Please install a lower version of pgspecial that supports psycopg2. '
`

is that correct or do i miss something?

tl3119 avatar Jun 07 '23 19:06 tl3119

so this one needs a bit more investigation.

currently, jupysql supports sqlalchemy 1.x and sqlalchemy 2.x. we also support psycopg2

my conclusion from some initial research is that with this combination of versions, we can only support old versions of pgspecial. the objective is to support newer versions of pgspecial, but to support that we might need to do some extra adjustments. so the first task is to figure out what versions of sqlalchemy and psycopg we need to support new versions of pgspecial, then implement support for it. finally, we can determine if it's feasible to support both old and new versions of pgspecial

edublancas avatar Jun 07 '23 20:06 edublancas

For the information I investigate, we need psycopg3 (>=3.0.10) version to support new versions of pgspecial, so we may need to upgrade psycopg version in our code

tl3119 avatar Jun 08 '23 15:06 tl3119

ok, can you see if jupysql works with psycopg3? my guess is that you'd need sqlalchemy 2 (which we support). I think let's first find out about psycopg3 and then we can continue with pgspecial

edublancas avatar Jun 08 '23 16:06 edublancas

I change psycopg2-binary in setup.py to psycopg3 and then activate the virtual environment. After that, I run the command pip install -e ., and all the package install successfully. Does that mean jupysql can work with psycopg3? Or do I need to do other tests to check the condition?

tl3119 avatar Jun 08 '23 22:06 tl3119

yes, you need to connect to a database and run a few queries. you can use this as a reference: https://jupysql.ploomber.io/en/latest/integrations/postgres-connect.html just modify the connection string and ensure it uses psycopg3

edublancas avatar Jun 09 '23 18:06 edublancas

It seems it successfully installed psycopg3 after I activate the virtual environment. image

tl3119 avatar Jun 12 '23 18:06 tl3119

you need to connect to a database and run a few queries.

edublancas avatar Jun 14 '23 00:06 edublancas

you need to connect to a database and run a few queries.

Sure! I connect to a database and run the queries, it can work! image image image

tl3119 avatar Jun 14 '23 14:06 tl3119

ok good, now let's get new versions of pgspecial working !

edublancas avatar Jun 15 '23 18:06 edublancas

I update the new version for pgspecial and test it locally using the same way, connect the database and run the query and it works. I open a PR for this issue: https://github.com/ploomber/jupysql/pull/622

tl3119 avatar Jun 16 '23 00:06 tl3119