Re: PL/SQL & unset custom variable

Lists: pgsql-general
From: Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: PL/SQL & unset custom variable
Date: 2009-09-02 13:28:52
Message-ID: C6C431A4.9E89%[email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

(I'm using Postgres 8.3)

I have a trigger that references a custom variable. Most of the time this
custom variable is set, and I have no problems.

However, in certain corner cases the custom variable is not set and the
trigger fails.

Is there a way to either test if the custom variable is set, or to specify a
global default for the custom variable ?

Thanks,

GTG


From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/SQL & unset custom variable
Date: 2009-09-02 14:39:29
Message-ID: 20090902143929.GA6774@tux
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk> wrote:

> (I'm using Postgres 8.3)
>
> I have a trigger that references a custom variable. Most of the time this
> custom variable is set, and I have no problems.
>
> However, in certain corner cases the custom variable is not set and the
> trigger fails.
>
> Is there a way to either test if the custom variable is set, or to specify a
> global default for the custom variable ?

I think, you can use COALESCE(your_variable, default_value) to solve
that problem. Try it, it is untested.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


From: Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: PL/SQL & unset custom variable
Date: 2009-09-02 14:56:59
Message-ID: C6C4464B.9E9C%[email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

On 02/09/2009 15:39, "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net> wrote:
> Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk> wrote:
>> Is there a way to either test if the custom variable is set, or to specify a
>> global default for the custom variable ?
>
> I think, you can use COALESCE(your_variable, default_value) to solve
> that problem. Try it, it is untested.

Sorry, no joy :-(

grails=> SELECT current_setting('phone.id');
ERROR: unrecognized configuration parameter "phone.id"

grails=> SELECT coalesce(current_setting('phone.id'),'SYSTEM');
ERROR: unrecognized configuration parameter "phone.id"

GTG


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: PL/SQL & unset custom variable
Date: 2009-09-02 18:16:14
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk> writes:
> Sorry, no joy :-(

> grails=> SELECT current_setting('phone.id');
> ERROR: unrecognized configuration parameter "phone.id"

> grails=> SELECT coalesce(current_setting('phone.id'),'SYSTEM');
> ERROR: unrecognized configuration parameter "phone.id"

You could use a SELECT from pg_settings to probe for the value
of the parameter without getting an error.

regards, tom lane


From: Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: PL/SQL & unset custom variable
Date: 2009-09-02 19:31:16
Message-ID: 0AF872F3E2A0384696B55097A811D40A17F72FE53A@gargantua.staff-ad.csi.cam.ac.uk
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-general

Hmmm.

If I do:

select * from pg_settings where name='custom_variable_classes';

I see my entry "phone", but I can't see how I can tell if I've set "phone.id"

GTG
________________________________________
From: Tom Lane [tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: 02 September 2009 19:16
To: Gordon Ross
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] PL/SQL & unset custom variable

Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk> writes:
> Sorry, no joy :-(

> grails=> SELECT current_setting('phone.id');
> ERROR: unrecognized configuration parameter "phone.id"

> grails=> SELECT coalesce(current_setting('phone.id'),'SYSTEM');
> ERROR: unrecognized configuration parameter "phone.id"

You could use a SELECT from pg_settings to probe for the value
of the parameter without getting an error.

regards, tom lane