Re: psql command aliases support

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: <pgsql-patches(at)postgresql(dot)org>, "Bernd Helmle" <mailings(at)oopsware(dot)de>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: psql command aliases support
Date: 2008-04-03 13:36:59
Message-ID: 87myobgiv8.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

"Peter Eisentraut" <peter_e(at)gmx(dot)net> writes:

> This is a valid concern, but it is orthogonal to the alias feature. You have
> the same problem already if you mistype
>
> \oo instead of \o
> \ofoo instead of \obar

Not really. In these cases you know what \o is going to do, you've just typo'd
the filename. The case I was saying was a "conflict" was because you were
using an entirely different feature and might not never have even met \o.

> \o instead of \p
> \oset instead of \pset

Sure, if you typo \o instead of select * from pg_class you might be surprised
too. You can't protect against typing an entirely different command than
intended. At least you can then go look up what \o does and figure out what
happened.

If you type \ofoo instead of \obar I think there's a big difference between
having it accidentally do what you wanted it to do but to the wrong file and
having it do something entirely unrelated to what you intended and end up
overwriting a file instead of run a simple select.

> or even more amusingly
>
> \o foo instead of \i foo -- check your keyboard layout

The point is here you've typed a different command entirely. Unsurprisingly
it's going to do something different.

\old means something *today*. In the proposed syntax by creating the alias
you're changing what it means. You're not changing other \ofoo arguments
though which is where the possibility for confusion arises.

Consider instead if Debian decided to include a convenient \deb alias for a
select query against the package repository. Now if I happen to have an "eb"
table I will be surprised when \deb doesn't work.

And lengthening the alias doesn't really help (aside from defeating the
purpose of having aliases). If they define \debian they would still be
interfering if I should have a table named "ebian".

As rule of thumb, I think if you try to execute an alias which doesn't exist,
you should get an "alias does not exist" command. You should not get an
"Invalid command" nor "Did not find relation" and certainly not some random
command you've never met before being run reading or overwriting random files.

I repeat my suggestion of having a \query command so you could do:

\setquery deb select * from debian_packages where packagename like :1
\setquery bbdb select * from bbdb where name like :1

\query deb postgres
\query bbdb peter

to run a saved query. I'm not attached to "setquery" though.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's RemoteDBA services!

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2008-04-03 14:09:45 Re: psql command aliases support
Previous Message Heikki Linnakangas 2008-04-03 13:22:34 Re: [BUGS] BUG #4070: Join more then ~15 tables let postgreSQL produces wrong data