Обсуждение: DWIM mode for psql

Поиск
Список
Период
Сортировка

DWIM mode for psql

От
Thomas Munro
Дата:
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

Вложения

Re: DWIM mode for psql

От
Andres Freund
Дата:
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.



Re: DWIM mode for psql

От
Corey Huinker
Дата:
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?

 

Re: DWIM mode for psql

От
Andreas Karlsson
Дата:
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



Re: DWIM mode for psql

От
Amit Langote
Дата:
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

Re: DWIM mode for psql

От
legrand legrand
Дата:
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