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.

american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40
  • 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 '18 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 '19 at 20:15

1 Answers1

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.

tinlyx
  • 1,276
  • 1
  • 12
  • 27