Add missing function abs (interval)
От | Isaac Morland |
---|---|
Тема | Add missing function abs (interval) |
Дата | |
Msg-id | CAMsGm5cTHQLjfrRj00y6P05uegdn7qBSaXic7u_GMTViPS1A8Q@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Add missing function abs (interval)
|
Список | pgsql-hackers |
On a newly set up system there are 7 types with a unary minus operator defined, but only 6 of them have an abs function:
postgres=# \df abs
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+------+------------------+---------------------+------
pg_catalog | abs | bigint | bigint | func
pg_catalog | abs | double precision | double precision | func
pg_catalog | abs | integer | integer | func
pg_catalog | abs | numeric | numeric | func
pg_catalog | abs | real | real | func
pg_catalog | abs | smallint | smallint | func
(6 rows)
I now have the following definition in my database:
CREATE OR REPLACE FUNCTION abs (
p interval
) RETURNS interval
LANGUAGE SQL IMMUTABLE STRICT
SET search_path FROM CURRENT
AS $$
SELECT GREATEST (p, -p)
$$;
COMMENT ON FUNCTION abs (interval) IS 'absolute value';
Would a patch to add a function with this behaviour to the initial database be welcome?
If so, should I implement it essentially like the above, or as an internal function? I've noticed that even when it seems like it might be reasonable to implement a built-in function as an SQL function they tend to be internal.
В списке pgsql-hackers по дате отправления: