4

In emacs (in whatever mode you recommend for accessing a Postgres database)

is it possible to type

select * from foo_<tab>

and somehow get autocomplete/help as to what tables are available in the database
( tables that start with foo_ )

I would also like (yasnippet?) help writing long sql. eg.

select name from users where email='abc@def.com' order by name limit 200;

I guess I will have to learn yasnippet for that.

2
  • Not really a task for yasnippet. You'd need to write an auto-complete or company plugin. However, doing smart completion would be a challenging task, since you also need to understand (programmatically) the SQL statement, and figure out whether it is a place where table name is allowed (or maybe a table field name), and then figure out if field name must be qualified with table name, is the table accessible to the user who will be running the query, is it aliased etc.
    – wvxvw
    Mar 28, 2018 at 14:05
  • 1
    Low-tech solution: If you simply run \d in the SQLi buffer running psql, so that postgres outputs all the table names, then dabbrev-expand would be able to see and complete them.
    – phils
    Jan 14, 2019 at 20:15

1 Answer 1

2

From their documentation, Emacs DBI (edbi) seems to support PostgreSQL and auto-completion (e.g. with company-edbi). The auto completion covers table names in its query editor.

See also my related question on DBA exchange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.