Thread

  1. cast text as date

    Richard Lynch <lynch@lscorp.com> — 1998-06-16T08:14:56Z

    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@lscorp.com
    
    
    
    
  2. Re: [SQL] cast text as date

    Herouth Maoz <herouth@oumail.openu.ac.il> — 1998-06-16T09:12:52Z

    At 11:14 +0300 on 16/6/98, Richard Lynch wrote:
    
    
    > 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.
    
    What version of Postgres, and what error, exactly, did it report?
    
    Herouth
    
    --
    Herouth Maoz, Internet developer.
    Open University of Israel - Telem project
    http://telem.openu.ac.il/~herutma