From: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> |
---|---|
To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: PSQL commands: \quit_if, \quit_unless |
Date: | 2016-12-04 19:55:19 |
Message-ID: | alpine.DEB.2.20.1612042045550.4497@lancre |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
>> 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.
--
Fabien.
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2016-12-04 20:20:25 | Re: PSQL commands: \quit_if, \quit_unless |
Previous Message | Tom Lane | 2016-12-04 17:51:49 | Re: Select works only when connected from login postgres |