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@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828