Casting varchar to timestamp fails in plpgsql

From: Bart Teeuwisse <bart-postgres(at)7-sisters(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Casting varchar to timestamp fails in plpgsql
Date: 2002-02-23 19:26:04
Message-ID: 3C77ECCC.2070205@7-sisters.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-02-23 20:11:44 Re: How to Run postgres inside gdb for debugging
Previous Message Tom Lane 2002-02-23 19:19:11 Re: Problems with DBI, DBD::Pg and Postgres 7.2.