Re: Proposal: USING clause for DO statement

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Proposal: USING clause for DO statement
Дата
Msg-id 26839.1258832402@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Proposal: USING clause for DO statement  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: Proposal: USING clause for DO statement
Re: Proposal: USING clause for DO statement
Список pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
> See my earlier comment:
>> Perhaps part of the problem is that psql can't interpolate its 
>> variable into strings. Solving that might lessen the impetus for this, 
>> and have other uses besides.

It seems to me that this is sliding down the wrong slope.  You're
basically assuming that psql itself is or should be a programming
language.  It's not.  The variable mechanism is an enormous kluge
with limited flexibility caused by a horrid syntax; and psql hasn't
got any control structures at all.

I think Petr was on the right track.  What people really want is not
psql scripts but plpgsql scripts.  DO effectively gives that to them,
with a few characters' worth of overhead.  The problem they have to
solve is to interpolate actual-parameter values into such a script;
but it's not clear to me that that's noticeably harder than getting
such values into a psql script.  I foresee people doing things like

psql -c 'DO $$'"declare x int := $SHELLVARIABLE; ... "'$$;' ...

The fact that $ is special to the shell as well as to DO is
kind of a PITA here, but it's not that hard to work around.

The main limitation of this type of approach is that it's hard to
properly quote a variable value that might contain any random character
sequence.  However, that's also true of the variable-interpolation stuff
Pavel was proposing.  In any case I don't think that "getting stuff from
psql variables into a DO script" is the way to define the problem.
It's "getting stuff from shell variables into a DO script" that is the
real-world problem.  Maybe psql is the wrong tool altogether.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: Hot standby and removing VACUUM FULL
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Hot standby and removing VACUUM FULL