Re: Separate psql commands from arguments

From: Decibel! <decibel(at)decibel(dot)org>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>, "Brendan Jurd" <direvus(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Bernd Helmle" <mailings(at)oopsware(dot)de>
Subject: Re: Separate psql commands from arguments
Date: 2008-04-11 18:53:11
Message-ID: F5EF93B3-1447-420D-B4E5-26BD99E3BAE6@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Apr 10, 2008, at 4:48 PM, Gregory Stark wrote:
> Well I feel like storing a query and resending it later is something
> predictable which will work reliably. Storing a psql input line and
> reinterpreting it later is surely going to cause weird things to
> happen.
>
> Just for some examples off the top of my head, what happens if I
> define an
> alias "\foo" which consists of "\foo" and call it? What happens if
> I have
> mutually recursive aliases? What happens if I define "\foo" to run
> \ followed
> by its first argument, and I pass it "foo"? What happens if I pass
> it "unalias
> foo"?

As Bernd said, I see this as simple search and replace, and then
stick it in the command buffer. If you define an alias that calls
itself, you could end up with a stack overflow, same as with server
functions.

> What happens if you press C-c during an alias, does it keep running
> subsequent
> commands? What if the editor returns an error after a \e command?
> What about
> if a \i command doesn't find the file?

You throw an error. In shell, you can use && to control if you keep
going or not after that; perhaps we should have that.

> Basically it sounds like you're treating psql as if it was a well
> defined
> language with well defined syntax and semantics. And I don't think
> it is. It's
> just one big if-else-if block with lots of strcmps. There's no
> infrastructure
> to parse or manage a stack of calls to functions.

So perhaps we should change that. Don't get me wrong, psql is the
most powerful command-line database I've ever seen, but it still
irritates me that it's not more shell-like in nature. In particular,
the inability to do things like condition processing, or save the
results of an SQL query into a psql variable are very annoying. If
that (or aliases) means psql needs to be more than a big IF-THEN-ELSE
then I think that's part of what we should do.
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-04-11 19:02:44 Re: Remove lossy-operator RECHECK flag?
Previous Message Tom Lane 2008-04-11 18:49:16 Re: Index AM change proposals, redux