Search Postgresql Archives

Re: Verifying a timestamp is null or in the past

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Awesome advices here.

Thank you and happy new year.


On Fri, Dec 30, 2011 at 2:07 PM, Alban Hertroys <haramrae@xxxxxxxxx> 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 can get 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 peculiarities of SQL... For posterity's sake it may be better to add that part to the query anyway, that's up to personal preference:
>
> select 1 from pref_users where id=_from and (vip is not null or vip > current_timestamp + interval '1 week');

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux