Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jameshowison opened this issue Feb 4, 2022 · 3 comments
Open
Labels
enhancement New feature or request PostgreSQL

Comments

@jameshowison
Copy link

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
Copy link
Member

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:

  • The jupyter protocol calls this kind of operation "magics" and they start with a % sign instead
  • There's a fair number of examples on how to implement these using sqlite on the xeus-sqlite repo, see and it's not too hard to implement the exact same logic here
  • For postgres or any other flavor of SQL the person implement these magics would have to look into SOCI api and call and use the methods correctly, attributing them to each one of the magics they'd create while parsing the user input

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

@jameshowison
Copy link
Author

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
Copy link
Member

marimeireles commented Feb 21, 2022

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! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PostgreSQL
Projects
None yet
Development

No branches or pull requests

2 participants