Re: Passing varchar parameter to INTERVAL - Mailing list pgsql-general

From Tom Lane
Subject Re: Passing varchar parameter to INTERVAL
Date
Msg-id 1444.1473256348@sss.pgh.pa.us
Whole thread Raw
In response to Re: Passing varchar parameter to INTERVAL  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
Alexander Farber <alexander.farber@gmail.com> writes:
> unfortunately, I can not call INTERVAL 'in_until', that wouldn't work.

No, because the syntax TYPENAME 'LITERAL' only works for simple string
literals.  What you want here is a run-time cast, either
CAST(in_until AS interval) or in_until::interval.

> I would prefer to call my custom function as
>     select words_ban_user(1, '1 day', 'attacking other users');

That is not a reason not to declare the argument as interval.

> and not as
>     select words_ban_user(1, CURRENT_TIMESTAMP + '1 day', 'attacking other
> users');

Hm?  That would be passing a timestamp not an interval.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Passing varchar parameter to INTERVAL
Next
From: Sándor Daku
Date:
Subject: Re: Passing varchar parameter to INTERVAL