Re: CAST and timestamp

From: Mike G <mike(at)thegodshalls(dot)com>
To: KeithW(at)narrowpathinc(dot)com
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: CAST and timestamp
Date: 2004-12-21 04:08:17
Message-ID: 1103602097.5304.22.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

That is what he is saying.

Generally you can cast char / varchar / text to each other without going
through a text cast first.

If you want to go from char / varchar to numeric or date types then you
need to cast them as text first and then the final data type.

Mike

On Mon, 2004-12-20 at 21:48, Keith Worthington wrote:
> Tom Lane wrote:
>
> >"Keith Worthington" <keithw(at)narrowpathinc(dot)com> writes:
> >
> >
> >>IPADB=# SELECT CAST(scan_date || scan_time AS timestamp) AS datetime_timestamp
> >>FROM data_transfer.tbl_inventory_scanner;
> >>ERROR: Cannot cast type character to timestamp without time zone
> >>
> >>
> >
> >
> >
> >>IPADB=# SELECT employee_id, item_id, CAST(quantity AS float4) AS quantity FROM
> >>data_transfer.tbl_inventory_scanner;
> >>ERROR: Cannot cast type character varying to real
> >>
> >>
> >
> >Try casting the inputs to type "text" and then to timestamp or real.
> >
> > regards, tom lane
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 8: explain analyze is your friend
> >
> Tom,
>
> Are you saying that I should try something like
>
> CAST( CAST( quantity AS text ) AS float4) AS quantity

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2004-12-21 04:14:37 Re: CAST and timestamp
Previous Message Tom Lane 2004-12-21 04:02:37 Re: CAST and timestamp