Re: PL/Python prepare example's use of setdefault

From: Jonathan Rogers <jrogers(at)socialserve(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: PL/Python prepare example's use of setdefault
Date: 2014-11-01 20:13:28
Message-ID: 54553EE8.1060307@socialserve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/01/2014 12:13 PM, Peter Eisentraut wrote:
> On 10/15/14 5:58 PM, Jonathan Rogers wrote:
>> BTW, I would rewrite the 9.1 example to be shorter while
>> behaving the same:
>>
>>
>> CREATE FUNCTION usesavedplan() RETURNS trigger AS $$
>> plan = SD.get("plan")
>> if plan is None:
>
> If we're going for shortness, how about
>
> if not plan:

Sure, that's fine as long as a plan object never looks Falsey.

>
> ?
>
>> SD["plan"] = plan = plpy.prepare("SELECT 1")
>
> and here maybe
>
> plan = SD["plan"] = plpy.prepare("SELECT 1")
>
> to emphasize the assignment to "plan"?

Yeah, order of assignment shouldn't matter.

>
>> # rest of function
>> $$ LANGUAGE plpythonu;
>

--
Jonathan Ross Rogers

In response to

Browse pgsql-general by date

  From Date Subject
Next Message rohtodeveloper 2014-11-02 10:15:56 How to implent the CONVERT ( data_type [ ( length ) ] , expression ) function in PostgreSQL
Previous Message Andrus 2014-11-01 20:02:31 Re: Converting char to varchar automatically