pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to Convert VarChar to Date in PgSQL
6+ messages / 5 participants
[nested] [flat]
* How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:07 Venkat Rao Tammineni <vtammineni@roulacglobal.com>
0 siblings, 4 replies; 6+ messages in thread
From: Venkat Rao Tammineni @ 2009-03-10 12:07 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-admin
Dear All,
I have one table which has lot of data.In the same table I have one
varchar filed. I want to convert into Date data type? Is It possible to
convert varchar to date datatype with out loosing data.Please guide me.I am
waiting for your great response.
?Thanx & Regards
Venkat Rao Tammineni
GIS Developer
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [GENERAL] How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:09 Raymond O'Donnell <rod@iol.ie>
parent: Venkat Rao Tammineni <vtammineni@roulacglobal.com>
3 siblings, 0 replies; 6+ messages in thread
From: Raymond O'Donnell @ 2009-03-10 12:09 UTC (permalink / raw)
To: Venkat Rao Tammineni <vtammineni@roulacglobal.com>; +Cc: pgsql-general@postgresql.org; pgsql-admin
On 10/03/2009 12:07, Venkat Rao Tammineni wrote:
> I have one table which has lot of data.In the same table I have one
> varchar filed. I want to convert into Date data type? Is It possible to
> convert varchar to date datatype with out loosing data.Please guide me.I am
> waiting for your great response.
If the varchar is already in the format you need (yyyy-mm-dd) then you
ought to be able just to cast it:
'2009-03-10'::date
If not, you may need to do some clever things with regular expressions
first to get it into this format, and then cast it.
Ray.
------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:11 Jaume Sabater <jsabater@gmail.com>
parent: Venkat Rao Tammineni <vtammineni@roulacglobal.com>
3 siblings, 1 reply; 6+ messages in thread
From: Jaume Sabater @ 2009-03-10 12:11 UTC (permalink / raw)
To: Venkat Rao Tammineni <vtammineni@roulacglobal.com>; +Cc: pgsql-general@postgresql.org; pgsql-admin
On Tue, Mar 10, 2009 at 1:07 PM, Venkat Rao Tammineni
<vtammineni@roulacglobal.com> wrote:
> I have one table which has lot of data.In the same table I have one
> varchar filed. I want to convert into Date data type? Is It possible to
> convert varchar to date datatype with out loosing data.Please guide me.I am
> waiting for your great response.
An easy solution would be to add a new column to the table, of type
date, and then execute an update statement that reads, for each row,
the value in the varchar field and writes the converted value to the
date field.
--
Jaume Sabater
http://linuxsilo.net/
"Ubi sapientas ibi libertas"
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:13 A. Kretschmer <andreas.kretschmer@schollglas.com>
parent: Venkat Rao Tammineni <vtammineni@roulacglobal.com>
3 siblings, 0 replies; 6+ messages in thread
From: A. Kretschmer @ 2009-03-10 12:13 UTC (permalink / raw)
To: pgsql-general@postgresql.org
In response to Venkat Rao Tammineni :
> Dear All,
>
>
>
>
>
> I have one table which has lot of data.In the same table I have one varchar
> filed. I want to convert into Date data type? Is It possible to convert varchar
> to date datatype with out loosing data.Please guide me.I am waiting for your
> great response.
Sure, if you have valid varchar-data.
to_date('2009-03-11'::text, 'yyyy-mm-dd');
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [GENERAL] How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:14 Pavel Stehule <pavel.stehule@gmail.com>
parent: Venkat Rao Tammineni <vtammineni@roulacglobal.com>
3 siblings, 0 replies; 6+ messages in thread
From: Pavel Stehule @ 2009-03-10 12:14 UTC (permalink / raw)
To: Venkat Rao Tammineni <vtammineni@roulacglobal.com>; +Cc: pgsql-general@postgresql.org; pgsql-admin
hello
2009/3/10 Venkat Rao Tammineni <vtammineni@roulacglobal.com>:
> Dear All,
>
>
>
>
>
> I have one table which has lot of data.In the same table I have one
> varchar filed. I want to convert into Date data type? Is It possible to
> convert varchar to date datatype with out loosing data.Please guide me.I am
> waiting for your great response.
>
>
>
use function to_date, please
http://www.postgresql.org/docs/8.3/static/functions-formatting.html
postgres=# select to_date('2009-07-17', 'YYYY-MM-DD');
to_date
----------
2009-07-17
(1 row)
regards
Pavel Stehule
>
>
>
>
> ?Thanx & Regards
>
> Venkat Rao Tammineni
>
> GIS Developer
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [GENERAL] How to Convert VarChar to Date in PgSQL
@ 2009-03-10 12:16 Pavel Stehule <pavel.stehule@gmail.com>
parent: Jaume Sabater <jsabater@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Pavel Stehule @ 2009-03-10 12:16 UTC (permalink / raw)
To: Jaume Sabater <jsabater@gmail.com>; +Cc: Venkat Rao Tammineni <vtammineni@roulacglobal.com>; pgsql-general@postgresql.org; pgsql-admin
2009/3/10 Jaume Sabater <jsabater@gmail.com>:
> On Tue, Mar 10, 2009 at 1:07 PM, Venkat Rao Tammineni
> <vtammineni@roulacglobal.com> wrote:
>
>> I have one table which has lot of data.In the same table I have one
>> varchar filed. I want to convert into Date data type? Is It possible to
>> convert varchar to date datatype with out loosing data.Please guide me.I am
>> waiting for your great response.
>
> An easy solution would be to add a new column to the table, of type
> date, and then execute an update statement that reads, for each row,
> the value in the varchar field and writes the converted value to the
> date field.
>
resp.
alter table someatb alter column columname type date using
to_data(columname, 'YYYY-MM-DD');
regards
Pavel
> --
> Jaume Sabater
> http://linuxsilo.net/
>
> "Ubi sapientas ibi libertas"
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2009-03-10 12:16 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-03-10 12:07 How to Convert VarChar to Date in PgSQL Venkat Rao Tammineni <vtammineni@roulacglobal.com>
2009-03-10 12:09 ` Raymond O'Donnell <rod@iol.ie>
2009-03-10 12:11 ` Jaume Sabater <jsabater@gmail.com>
2009-03-10 12:16 ` Pavel Stehule <pavel.stehule@gmail.com>
2009-03-10 12:13 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2009-03-10 12:14 ` Pavel Stehule <pavel.stehule@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox