Re: to_char incompatibility

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Roberts, Jon" <Jon(dot)Roberts(at)asurion(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: to_char incompatibility
Date: 2008-01-10 14:47:02
Message-ID: 162867790801100647i4162d014ufa109cdeee3802d9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

small non important note: your function is very expensive

exactly same but faster is:

CREATE OR REPLACE FUNCTION fn_to_date(p_date varchar, p_format varchar)
RETURNS timestamp AS $$
SELECT to_timestamp(replace($1, ' ', ''), replace($2, ' ', ''));
$$ LANGUAGE SQL STRICT IMMUTABLE;

or

CREATE OR REPLACE FUNCTION fn_to_date(p_date varchar, p_format varchar)
RETURNS timestamp AS $$
BEGIN
RETURN to_timestamp(replace(p_date, ' ', ''), replace(p_format, ' ', ''));
END$$ LANGUAGE SQL STRICT IMMUTABLE;

there isn't any reason for using security definer and you forgot IMMUTABLE,

Regards
Pavel Stehule

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2008-01-10 14:51:07 tag REL8_2_6 not present in file xyz
Previous Message Sim Zacks 2008-01-10 14:40:04 8.2.4 serious slowdown