Re: Verifying a timestamp is null or in the past - Mailing list pgsql-general

From Alexander Farber
Subject Re: Verifying a timestamp is null or in the past
Date
Msg-id CAADeyWinVfn3oHxik3-KiV7wkWq+OvSCwcmX60NAqxSB_GEOkA@mail.gmail.com
Whole thread Raw
In response to Re: Verifying a timestamp is null or in the past  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: Verifying a timestamp is null or in the past  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
Awesome advices here.

Thank you and happy new year.


On Fri, Dec 30, 2011 at 2:07 PM, Alban Hertroys <haramrae@gmail.com> wrote:
> select 1 from pref_users where id=_from and vip > current_timestamp + interval '1 week';
>
> if not found then
>    return;
> end if;
>
> "found" is a special pl/psql keyword that tells whether the last query returned any results or not. Using that you
canget rid of the entire declare-block in your function ;) 
>
> Originally I tacked a "vip is not null or" before the check in the where-clause, but that's unnecessary - if vip is
null,then the expression also evaluates to null and the where-clause will treat it as false. That's one of the
peculiaritiesof SQL... For posterity's sake it may be better to add that part to the query anyway, that's up to
personalpreference: 
>
> select 1 from pref_users where id=_from and (vip is not null or vip > current_timestamp + interval '1 week');

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Data Type for Money
Next
From: Tom Lane
Date:
Subject: Would whoever is at "Hi-Tech Gears Ltd, Gurgaon, India" fix their mailer?