Re: Timestamp operator error - Mailing list pgsql-sql

From Tom Lane
Subject Re: Timestamp operator error
Date
Msg-id 27580.1014701489@sss.pgh.pa.us
Whole thread Raw
In response to Re: Timestamp operator error  ("Josh Berkus" <josh@agliodbs.com>)
Responses Re: Timestamp operator error  ("Josh Berkus" <josh@agliodbs.com>)
Re: Timestamp operator error  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
"Josh Berkus" <josh@agliodbs.com> writes:
> FMI, though, how difficult is defining an operator if I paid a C
>  programmer to do it?  

Pretty trivial when it's only the commutation of an existing operator...

Actually you don't even need any C code.  You could limp along at some
sacrifice of performance with an SQL function definition.  Say

regression=# create function interval_plus_timestamp(interval,timestamp)
regression-# returns timestamp as '
regression'# select $2 + $1;
regression'# ' language 'sql';
CREATE

regression=# create operator + (procedure = interval_plus_timestamp,
regression(# leftarg = interval,
regression(# rightarg = timestamp);
CREATE

et voila:

regression=# select ('6 days'::INTERVAL + current_timestamp);          ?column?
-------------------------------2002-03-04 00:28:30.230026-05
(1 row)

I'd not want to make an index depend on this operator, but for
occasional query use it should do fine ...
        regards, tom lane


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Timestamp operator error
Next
From: "Josh Berkus"
Date:
Subject: Re: Timestamp operator error