Should I use CAST?

From: "Campano, Troy" <Troy(dot)Campano(at)LibertyMutual(dot)com>
To: "Pgsql-General (pgsql-general(at)postgresql(dot)org)" <pgsql-general(at)postgresql(dot)org>
Subject: Should I use CAST?
Date: 2001-12-03 16:22:23
Message-ID: 9534B16F750ED2118CF90008C724C4460C22228B@lmig-msg-20.lmig.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have two tables that are basically the same. They have different data
types through. I am trying to load data from one table to another and I get
the error:

ERROR: Attribute 'cert_expiration' is of type 'date' but expression is of
type 'varchar'
You will need to rewrite or cast the expression

So I tried this:

-----------------------------------------------------
INSERT INTO ebs_webserver_t (
install_directory,
server_instance_nme,
docs_directory_nme,
other_info,
port_num,
host_nme,
ip_num,
cert_expiration,
dns_nme,
url_nme,
app_contact_id,
cert_type_id,
domain_id,
node_id,
environment_id,
sbu_id,
server_type_id
)
SELECT
install_directory,
server_instance_nme,
docs_directory_nme,
other_info,
port_num,
host_nme,
ip_num,
CAST(cert_expiration AS DATE),
dns_nme,
url_nme,
app_contact_nme,
cert_type_id,
domain_id,
node_id,
environment_id,
sbu_id,
server_type_id
FROM ebs_webserver_tmp2;
---------------------------------------------------------

Notice I used CAST in the SELECT. But I get this error:

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

Any ideas what I can do to make a VARCHAR column a date?
All the dates are in this format: 10/23/2002

Thanks!

[:==> Troy Campano <==:]
Database (Request Manager/web/database)
http://intranet:3000/infosys/infra/software/database/dbapp/
<http://intranet:3000/infosys/infra/software/database/dbapp/>
http://intranet2/reqman/ <http://intranet2/reqman/>
Microsoft gave you Windows, UNIX the whole house.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2001-12-03 16:51:46 Re: Determining current database programmatically
Previous Message Tom Lane 2001-12-03 15:46:31 Re: Determining current database programmatically