DWIM mode for psql

Started by Thomas Munroover 7 years ago6 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t40370
psql -h localhost -U postgres

Built from patchset v1 (message #1), September 20, 2026 at 08:30 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t40370_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t40370_1 && git checkout t40370_1

Patchset v1 (message #1) is on t40370_1

Jump to latest
#1Thomas Munro
thomas.munro@gmail.com

Hello,

Building on the excellent work begun by commit e529cd4ffa60, I would
like to propose a do-what-I-mean mode for psql. Please find a POC
patch attached. It works like this:

postgres=# select datnaam from pg_database where ooid = 12917;
ERROR: column "datnaam" does not exist
LINE 1: select datnaam from pg_database where ooid = 12917;
^
HINT: Perhaps you meant to reference the column "pg_database.datname".
postgres=# YES
datname
----------
postgres
(1 row)

As you can see, by "shouting" a new keyword at the computer, it will
take its own hint and run the corrected query. To avoid having to do
this in two steps, you can also shout the whole query for the same
effect:

postgres=# SELECT DATNAAM FROM PG_DATABASE WHERE OOID = 12917;
datname
----------
postgres
(1 row)

The next version will be able to fix permissions problems and override
errors automatically as follows, though that is proving trickier to
get working. Example:

postgres=# SUDO DROP TABLE PG_DATABASS;
NO CARRIER

--
Thomas Munro
https://enterprisedb.com

Attachments:

t40370_1
0001-Add-do-what-I-mean-mode-to-psql.patchapplication/octet-stream; name=0001-Add-do-what-I-mean-mode-to-psql.patchDownload+51-1
#2Andres Freund
andres@anarazel.de
In reply to: Thomas Munro (#1)
Re: DWIM mode for psql

On 2019-04-01 09:52:34 +1300, Thomas Munro wrote:

+/*
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.

Indentation bug. You really need to work a bit more careful.

#3Corey Huinker
corey.huinker@gmail.com
In reply to: Andres Freund (#2)
Re: DWIM mode for psql

On Sun, Mar 31, 2019 at 5:04 PM Andres Freund <andres@anarazel.de> wrote:

On 2019-04-01 09:52:34 +1300, Thomas Munro wrote:

+/*
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.

Indentation bug. You really need to work a bit more careful.

The patch applies cleanly, and passes "make check", but it generated an
executable called "mongodb".
Should I have run "make maintainer-clean" first?

#4Andreas Karlsson
andreas.karlsson@percona.com
In reply to: Thomas Munro (#1)
Re: DWIM mode for psql

On 3/31/19 10:52 PM, Thomas Munro wrote:> Building on the excellent work
begun by commit e529cd4ffa60, I would

like to propose a do-what-I-mean mode for psql. Please find a POC
patch attached. It works like this:

postgres=# select datnaam from pg_database where ooid = 12917;
ERROR: column "datnaam" does not exist
LINE 1: select datnaam from pg_database where ooid = 12917;
^
HINT: Perhaps you meant to reference the column "pg_database.datname".
postgres=# YES
datname
----------
postgres
(1 row)

I think it is potentially confusing that YES and NO does not look like
other psql commands. Let's pick something which is more in line with
existing commands like \y and \n.

Andreas

#5Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Thomas Munro (#1)
Re: DWIM mode for psql

Hi Thomas,

Thanks for working on this.

On Mon, Apr 1, 2019 at 5:53 Thomas Munro <thomas.munro@gmail.com> wrote:

Hello,

Building on the excellent work begun by commit e529cd4ffa60, I would
like to propose a do-what-I-mean mode for psql. Please find a POC
patch attached. It works like this:

postgres=# select datnaam from pg_database where ooid = 12917;
ERROR: column "datnaam" does not exist
LINE 1: select datnaam from pg_database where ooid = 12917;
^
HINT: Perhaps you meant to reference the column "pg_database.datname".
postgres=# YES
datname
----------
postgres
(1 row)

As you can see, by "shouting" a new keyword at the computer, it will
take its own hint and run the corrected query. To avoid having to do
this in two steps, you can also shout the whole query for the same
effect:

postgres=# SELECT DATNAAM FROM PG_DATABASE WHERE OOID = 12917;
datname
----------
postgres
(1 row)

Neat.

The next version will be able to fix permissions problems and override

errors automatically as follows, though that is proving trickier to
get working. Example:

postgres=# SUDO DROP TABLE PG_DATABASS;
NO CARRIER

Have you tried rebooting the machine?

Thanks,
Amit

Show quoted text
#6legrand legrand
legrand_legrand@hotmail.com
In reply to: Andreas Karlsson (#4)
Re: DWIM mode for psql

Andreas Karlsson wrote

On 3/31/19 10:52 PM, Thomas Munro wrote:> Building on the excellent work
begun by commit e529cd4ffa60, I would

like to propose a do-what-I-mean mode for psql. Please find a POC
patch attached. It works like this:

postgres=# select datnaam from pg_database where ooid = 12917;
ERROR: column "datnaam" does not exist
LINE 1: select datnaam from pg_database where ooid = 12917;
^
HINT: Perhaps you meant to reference the column "pg_database.datname".
postgres=# YES
datname
----------
postgres
(1 row)

I think it is potentially confusing that YES and NO does not look like
other psql commands. Let's pick something which is more in line with
existing commands like \y and \n.

Andreas

+1
Regards

-)))°>

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-hackers-f1928748.html