Re: Help reqd: Copying char to date

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: <rjb26(at)hotmail(dot)losethis(dot)nothere(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help reqd: Copying char to date
Date: 2002-03-13 18:18:02
Message-ID: 20020313101508.M84314-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 8 Mar 2002 rjb26(at)hotmail(dot)losethis(dot)nothere(dot)com wrote:

> On Fri, 08 Mar 2002 12:38:29 +0100, rjb26(at)hotmail(dot)losethis(dot)nothere(dot)com
> wrote:
>
> >Anybody offer some advice please:
> >
> >I want to copy a char field to a date field. Is there any quick way of
> >doing this?
> >TIA
>
> Sorry - this was not very clear. I can copy text to a date field; but
> actually want to be able to perform the following:
>
> I have a text field (contents: 20020301)
> I would like to change the field type to Date, but retain the
> contents, but formatted as a date type. Any ideas, suggestions?

Umm, if you don't have complicated foreign key structures and the like,
you might just be able to do something like:

select col1, col2, ... , coln::date, ... into tmp from starttable;
alter table starttable rename to old;
alter table tmp rename to starttable;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2002-03-13 19:50:12 Re: Referential integrity implementation - bug or user error?
Previous Message Graham Vickrage 2002-03-13 17:41:24 Casting