Casting varchar to timestamp fails in plpgsql - Mailing list pgsql-general

From Bart Teeuwisse
Subject Casting varchar to timestamp fails in plpgsql
Date
Msg-id 3C77ECCC.2070205@7-sisters.com
Whole thread Raw
Responses Re: Casting varchar to timestamp fails in plpgsql  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
While the following cast works in psql, an equivalent cast fails in plpgsql:

   select cast ('Dec 14 1901 08:45:52' as timestamp);

The following equivalent plgsql function

   create function rdbms_date(varchar) returns timestamp as '
   declare
     p_raw_date alias for $1;
   begin
     return cast (p_raw_date as timestamp);
   end;' language 'plpgsql';

fails with error message:

   ERROR: Cannot cast type 'varchar' to 'timestamp'

when called like so:

   select rdbms_date('Dec 14 1901 08:45:52');

Can someone explain how to cast a varchar to a timestamp in plpgsql?

Thanks,
Bart


pgsql-general by date:

Previous
From: "Tom Sheehan"
Date:
Subject: Re: where can I find latest jdbc driver for postgresql?
Next
From: "Thomas T. Thai"
Date:
Subject: help with getting index scan