jupyter-xeus / xeus-sql

Jupyter kernel for SQL databases
https://xeus-sql.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
158 stars 21 forks source link

Possible to execute the 'slash' commands on postgres? \d \dt \list #57

Open jameshowison opened 2 years ago

jameshowison commented 2 years ago

Postgres uses commands starting with a \ char, but these don't seem to execute in xues-sql. e.g.,

\list

which should show all databases the user can see on the server, but it gives this error:

Error: Cannot execute query. Fatal error. ERROR:  syntax error at or near "\"
LINE 1: \list
        ^
 while executing "\list".

Same for the commonly used \d and \dt.

marimeireles commented 2 years ago

Hi @jameshowison, thanks for opening the issue. Currently xeus-sql doesn't have a roadmap for implementing something like this.

But in case you or anyone would like to tackle this issue, here are some tips:

If you need any help, feel free to open issues here or contact me on a synchronous way.

jameshowison commented 2 years ago

Thanks for the guidance. I don't think I can implement that, but I am trying to bring it someone's attention who might be able to.

Just for additional insight, one of the reasons that this is crucial is that one cannot switch databases in xeus-sql, one has to know to reconnect to change databases. That's because that requires the \c command: https://stackoverflow.com/questions/3949876/how-to-switch-databases-in-psql

The consequence of this is that currently in xeus-sql if you connect and use CREATE DATABASE some_db then issue a CREATE TABLE some_table command, the table is actually created in the default database and not in the new database. In my case the default database was created named after the database user. I could only find this out using the commandline client and pgadmin.

So one would have to do:

%LOAD postgresql host=localhost
CREATE DATABASE some_db;

then reconnect to change to that database.

%LOAD postgresql host=localhost dbname=some_db

then create the tables:

CREATE TABLE some_table

I guess once one knows this it's not too bad :)

marimeireles commented 2 years ago

If SOCI doesn't offer this kind of stuff we can encapsulate this nicely by calling %LOAD postgresql host=localhost dbname=some_db in our API and some_db is the %\c argument. Thanks for the insights for this one @jameshowison! :)