cast text as date

From: lynch(at)lscorp(dot)com (Richard Lynch)
To: pgsql-sql(at)postgresql(dot)org
Subject: cast text as date
Date: 1998-06-16 08:14:56
Message-ID: v02140b24b1ab8fc52a9f@[207.152.64.133]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm probably an idiot, but I can't find a way in the docs or archives to
cast from text to date. The text field in question looks like a date, and
I know there's a function to parse it 'cuz if it were in a table to be
imported using \copy it would work, but what that function would be called,
I'm failing to guess... Does that make sense?

Here's the mess I've created:

I've got two tables that I need to "merge". Both have mostly the same
fields but t1 has type 'text' on fields that are really, really dates, and
t1 has more rows than t2. So I'm using:

insert into t2 select blah, blah, cast (blah as date) from t1 where not
exists (select id from t2 where t2.id = t1.id);

Maybe I'm just going about this all wrong...

I've never created a function of my own, and maybe that's the way to go,
but I'm not sure where to start...
The strings in question actually only have a month/year (no date), if that
matters (they're expirations)...
The resulting date can just default to 1 for the date.

--
--
-- "TANSTAAFL" Rich lynch(at)lscorp(dot)com

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Francois TETE 1998-06-16 09:02:39 Rule "Delete"
Previous Message David Hartwig 1998-06-15 23:10:21 Re: [SQL] Binary large objects