Passing varchar parameter to INTERVAL - Mailing list pgsql-general

From Alexander Farber
Subject Passing varchar parameter to INTERVAL
Date
Msg-id CAADeyWjto+cJ6+LKW799MY2qb3n5t5kqSjkJKFomUWChLiC13Q@mail.gmail.com
Whole thread Raw
Responses Re: Passing varchar parameter to INTERVAL
Re: Passing varchar parameter to INTERVAL
Re: Passing varchar parameter to INTERVAL
Re: Passing varchar parameter to INTERVAL
List pgsql-general
Good afternoon,

when trying to create a custom function to temporary ban a user:

CREATE OR REPLACE FUNCTION words_ban_user(
        IN in_uid integer,
        IN in_until varchar,    -- '1 week' OR '1 month' OR '1 year'
        IN in_reason varchar)
        RETURNS void AS
$func$
BEGIN
........
        UPDATE words_users SET
                banned_until  = CURRENT_TIMESTAMP + INTERVAL in_until,
                banned_reason = in_reason,
                vip_until     = vip_until + INTERVAL in_until,    -- for paying user
                grand_until   = grand_until + INTERVAL in_until
        WHERE uid = in_uid;

END
$func$ LANGUAGE plpgsql;

in 9.5.4 I unfortunately get the error:

ERROR:  syntax error at or near "in_until"
LINE 69: ...       banned_until = CURRENT_TIMESTAMP + INTERVAL in_until,
                                                               ^
Is there please a better way here?

Thank you
Alex

pgsql-general by date:

Previous
From: Jehan-Guillaume de Rorthais
Date:
Subject: Re: PGDATA / data_directory
Next
From: rob stone
Date:
Subject: Re: pgadmin4 rc1 query tool performance