Re: PSQL commands: \quit_if, \quit_unless

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: PSQL commands: \quit_if, \quit_unless
Дата
Msg-id CAFj8pRCs0HQCiRaUO_zHAZAWd5nnPqJrak_H_tMv8UXApS=niA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: PSQL commands: \quit_if, \quit_unless  (Fabien COELHO <coelho@cri.ensmp.fr>)
Список pgsql-hackers


2016-12-04 20:55 GMT+01:00 Fabien COELHO <coelho@cri.ensmp.fr>:

Yes, that is a possibility, but this can already be queried into a :-variable, so it is less indispensable.

can you show some examples, please?

 SELECT COUNT(*) AS has_unit_extension
   FROM pg_extension WHERE extname='unit' \gset
 \echo :has_unit_extension
 1

So that

 \if ! :hash_unit_extension
 CREATE TABLE foo(id SERIAL, stuff UNIT);
 \else
 \echo "unit extension is not loaded"
 \quit
 \fi

Ok, for this example one may try:

 CREATE EXTENSION IF NOT EXISTS unit;

Or use the "ON_ERROR_STOP" setting, but that is the idea, SQL can be used to test anything server-side.

understand

I am thinking so first step can be simply and much more friendly replaced by specialized function:

\if has_extension(...)

the functions are supported by pgbench already, so we can take code from there.

I don't think so psql script language should be too rich - it should be DSL and often use cases should be supported with friendly syntax.

The set of functions can be small in first stage - we can support only one function.

Regards

Pavel

--
Fabien.

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

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: PSQL commands: \quit_if, \quit_unless
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: Parallel tuplesort (for parallel B-Tree index creation)