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]

 



Hello again, please 1 more question:

can I have a SELECT statement inside of an IF-conditional?

The doc
http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html
does not list such an example.

I'm asking, because I'd like to get rid of the has_vip
variable in my rewritten procedure below:

/* move 1 week of VIP-status from
   player _from to player _to */

create or replace function pref_move_week(_from varchar,
    _to varchar) returns void as $BODY$
        declare
                has_vip timestamp;
        begin

        select vip into has_vip from pref_users
            where id=_from
            and vip > current_timestamp + interval '1 week';

        if (has_vip is NULL) then
                return;
        end if;

        update pref_users set
            vip = vip - interval '1 week'
            where id=_from;

        update pref_users set
            vip = greatest(vip, current_timestamp) + interval '1 week'
            where id=_to;

        end;
$BODY$ language plpgsql;

-- 
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