From vtammineni@roulacglobal.com Tue Mar 10 12:03:47 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id AC6FD634C2C; Tue, 10 Mar 2009 09:03:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 23211-03-4; Tue, 10 Mar 2009 09:03:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from IPDDFZ2047ATL2.f3technologies.com (unknown [216.247.254.67]) by mail.postgresql.org (Postfix) with ESMTP id 5B225634B18; Tue, 10 Mar 2009 09:03:42 -0300 (ADT) Received: from rgprtw74 ([203.196.150.245] RDNS failed) by IPDDFZ2047ATL2.f3technologies.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 10 Mar 2009 08:04:34 -0400 From: "Venkat Rao Tammineni" To: , Subject: How to Convert VarChar to Date in PgSQL Date: Tue, 10 Mar 2009 17:37:38 +0530 Message-ID: <005901c9a178$d00c3c20$7024b460$@com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_005A_01C9A1A6.E9C47820" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcmheM18/g2X+dg1Rw+nRrSxbRC8hw== Content-Language: en-us X-OriginalArrivalTime: 10 Mar 2009 12:04:34.0781 (UTC) FILETIME=[60BB60D0:01C9A178] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.101 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200903/126 X-Sequence-Number: 31626 This is a multipart message in MIME format. ------=_NextPart_000_005A_01C9A1A6.E9C47820 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_005A_01C9A1A6.E9C47820 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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

 

------=_NextPart_000_005A_01C9A1A6.E9C47820-- From rod@iol.ie Tue Mar 10 12:10:38 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id B227263536D for ; Tue, 10 Mar 2009 09:10:38 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 25995-01-6 for ; Tue, 10 Mar 2009 09:10:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail20.svc.cra.dublin.eircom.net (mail20.svc.cra.dublin.eircom.net [159.134.118.221]) by mail.postgresql.org (Postfix) with SMTP id 566D6635CB4 for ; Tue, 10 Mar 2009 09:09:22 -0300 (ADT) Received: (qmail 41909 messnum 16316261 invoked from network[86.43.79.16/unknown]); 10 Mar 2009 12:09:19 -0000 Received: from unknown (HELO ?127.0.0.1?) (86.43.79.16) by mail20.svc.cra.dublin.eircom.net (qp 41909) with SMTP; 10 Mar 2009 12:09:19 -0000 Message-ID: <49B65870.60807@iol.ie> Date: Tue, 10 Mar 2009 12:09:20 +0000 From: Raymond O'Donnell Reply-To: rod@iol.ie User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: Venkat Rao Tammineni CC: pgsql-general@postgresql.org, pgsql-admin@postgresql.org Subject: Re: [GENERAL] How to Convert VarChar to Date in PgSQL References: <005901c9a178$d00c3c20$7024b460$@com> In-Reply-To: <005901c9a178$d00c3c20$7024b460$@com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090309-0, 09/03/2009), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/127 X-Sequence-Number: 31627 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 ------------------------------------------------------------------ From jsabater@gmail.com Tue Mar 10 12:12:44 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7ED13633EA3; Tue, 10 Mar 2009 09:12:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 26893-08-2; Tue, 10 Mar 2009 09:12:33 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f168.google.com (mail-fx0-f168.google.com [209.85.220.168]) by mail.postgresql.org (Postfix) with ESMTP id 31D2F6361D4; Tue, 10 Mar 2009 09:11:30 -0300 (ADT) Received: by fxm12 with SMTP id 12so2328977fxm.19 for ; Tue, 10 Mar 2009 05:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9d5U92+9/0XY8kiqnIWW9cYtv+utDfvPw/M9c2UTHaE=; b=CQhIsQf0yD4jZ4Dg1Lvx1IZSGPPEk3KZ6P840ZWPsK4ORC0VJBELcF15fobsvomCnW rqvaJ/GrVB7yrrmwnsAp5Vtn3S1gVjfzQ2narU1TIWMjiq5wlw4lcqrrXsi+dR3HRNs3 z2bSOWbUu5PM0YurfRfzs3ykmQKS9CNo1UbII= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=gS4dry0k4iaqYf+qG2WFBPfUizHsnzlwLBvm7DYzkXoYcnSGSLnhnCjn0IyCpXCeED +UXXE5nAlktQyc2wICqAuU4l4IMr0+04/4MLyqjkm/iGook52a4t3MWfEHYpiMILmiWB Jd1mxSMmqGXdrO3UcqzURbPOA4bQOEgcrSm2A= MIME-Version: 1.0 Received: by 10.223.112.130 with SMTP id w2mr5283763fap.65.1236687088084; Tue, 10 Mar 2009 05:11:28 -0700 (PDT) In-Reply-To: <005901c9a178$d00c3c20$7024b460$@com> References: <005901c9a178$d00c3c20$7024b460$@com> Date: Tue, 10 Mar 2009 13:11:27 +0100 Message-ID: <3786f7bb0903100511t5fe45b63tbe84b502b0d64bbc@mail.gmail.com> Subject: Re: How to Convert VarChar to Date in PgSQL From: Jaume Sabater To: Venkat Rao Tammineni Cc: pgsql-general@postgresql.org, pgsql-admin@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/128 X-Sequence-Number: 31628 On Tue, Mar 10, 2009 at 1:07 PM, Venkat Rao Tammineni wrote: > =C2=A0 I have one table which has lot of data.In the same table I have on= e > 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. --=20 Jaume Sabater http://linuxsilo.net/ "Ubi sapientas ibi libertas" From andreas.kretschmer@schollglas.com Tue Mar 10 12:14:16 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BE260634ED9 for ; Tue, 10 Mar 2009 09:14:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 27498-01-9 for ; Tue, 10 Mar 2009 09:14:05 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by mail.postgresql.org (Postfix) with ESMTP id 03741634BDF for ; Tue, 10 Mar 2009 09:13:47 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis) id 0ML31I-1Lh0q81swu-00053N; Tue, 10 Mar 2009 13:13:45 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1Lh0q7-00026Y-00 for pgsql-general@postgresql.org; Tue, 10 Mar 2009 13:13:43 +0100 Date: Tue, 10 Mar 2009 13:13:43 +0100 From: "A. Kretschmer" To: pgsql-general@postgresql.org Subject: Re: How to Convert VarChar to Date in PgSQL Message-ID: <20090310121343.GC13749@a-kretschmer.de> References: <005901c9a178$d00c3c20$7024b460$@com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <005901c9a178$d00c3c20$7024b460$@com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1/sOCh9dsx1aokkxi3MBWuKIyfQr0DkLz/Ozan 2duteR61Q/rBkNqaiaWfeA5JRat5F/3I8QkBNzdL3IgDHqACX0 Wenm5TopGVieN2riqWrLRXZ+6jgRzL1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/360 X-Sequence-Number: 144946 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 From pavel.stehule@gmail.com Tue Mar 10 12:14:21 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A2719634E93; Tue, 10 Mar 2009 09:14:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 27638-06-3; Tue, 10 Mar 2009 09:14:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f170.google.com (mail-bw0-f170.google.com [209.85.218.170]) by mail.postgresql.org (Postfix) with ESMTP id 3E1C5634AE0; Tue, 10 Mar 2009 09:14:10 -0300 (ADT) Received: by bwz18 with SMTP id 18so2241491bwz.19 for ; Tue, 10 Mar 2009 05:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=c2YoWXZ82IrWnVEAoqy95CuytIGpqnPwg32cQf3/Um0=; b=YoVhV19qeC5uigE/IWiXUOq4fM8xe47MBXMv390yjV9DX3S+8PEZzXJYyKPTHWBoWP InSl0NcNeJTRpdVtYPF8YTm0emxeGoNqFeGA4oI7NmmGxjq5P0GV7aVB/loX5mK5SZRr kbk50o8dVmJqHA5XnPRMlzZ+AeEm8qxY0+s9g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=j+6wZPB22XlbnU1LUbP0pLOvWKKTbbZCwNVFmGLYWBoZK2ru36YdgzJBOB8smUG8L+ GqJOrVD7VTZxgTQ3mcvV9wjQPSfnIEJc2oz7Fl7PN1OB+tp43a8gD7jidgKvgbbiS+53 hwbcJQBVV0A1rrPaOIr2jGeNuSgH7yaalE+/c= MIME-Version: 1.0 Received: by 10.103.214.8 with SMTP id r8mr3210890muq.92.1236687248006; Tue, 10 Mar 2009 05:14:08 -0700 (PDT) In-Reply-To: <005901c9a178$d00c3c20$7024b460$@com> References: <005901c9a178$d00c3c20$7024b460$@com> Date: Tue, 10 Mar 2009 13:14:07 +0100 Message-ID: <162867790903100514u19ee4d0cje262cd98f213ae4a@mail.gmail.com> Subject: Re: [GENERAL] How to Convert VarChar to Date in PgSQL From: Pavel Stehule To: Venkat Rao Tammineni Cc: pgsql-general@postgresql.org, pgsql-admin@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/129 X-Sequence-Number: 31629 hello 2009/3/10 Venkat Rao Tammineni : > Dear All, > > > > > > =C2=A0 I have one table which has lot of data.In the same table I have on= e > 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=3D# select to_date('2009-07-17', 'YYYY-MM-DD'); to_date ---------- 2009-07-17 (1 row) regards Pavel Stehule > > > > > ?Thanx & Regards > > =C2=A0Venkat Rao Tammineni > > GIS Developer > > From pavel.stehule@gmail.com Tue Mar 10 12:16:41 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 5708A635167; Tue, 10 Mar 2009 09:16:41 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 28631-01-6; Tue, 10 Mar 2009 09:16:31 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f170.google.com (mail-bw0-f170.google.com [209.85.218.170]) by mail.postgresql.org (Postfix) with ESMTP id 2DF20634F33; Tue, 10 Mar 2009 09:16:37 -0300 (ADT) Received: by bwz18 with SMTP id 18so2242609bwz.19 for ; Tue, 10 Mar 2009 05:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=FV25LLIeXADeM6Jsw72m7L0MezZ6mdcwXSmaexbznCY=; b=uNboutYzV2kKNlujlhQ6ZbkUc1nEWZThJyz792Mk8hdhTBRP8+heTX3aZOPxvqCNtS 0MyFLiuvztu1X/K20urpsu07MSoihpMdpIlEOtjeAzblJZpGv67wckskkHaAFmFZcuAd 6v++tiYmTwixXPxUHEgHVHaSgsFEgxfp29iwg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=WMnCnNcdP8o/qkauVid+jpcqeLFye1aukayXbfuPkATpzxb+WxhDN7JHreixg3pvPm NNahRe76FHdBZuU9KuvFWfhT5I77DN/ytuF7Iy4Pwz6xAnhguNvfuVZ/rCI+s8STol51 pKKr95xwXu98j+Rw1h0xhqBbtf719FtC4+x6g= MIME-Version: 1.0 Received: by 10.223.118.9 with SMTP id t9mr5321351faq.20.1236687395083; Tue, 10 Mar 2009 05:16:35 -0700 (PDT) In-Reply-To: <3786f7bb0903100511t5fe45b63tbe84b502b0d64bbc@mail.gmail.com> References: <005901c9a178$d00c3c20$7024b460$@com> <3786f7bb0903100511t5fe45b63tbe84b502b0d64bbc@mail.gmail.com> Date: Tue, 10 Mar 2009 13:16:35 +0100 Message-ID: <162867790903100516i1e259d1bl1273c13b25515d9a@mail.gmail.com> Subject: Re: [GENERAL] How to Convert VarChar to Date in PgSQL From: Pavel Stehule To: Jaume Sabater Cc: Venkat Rao Tammineni , pgsql-general@postgresql.org, pgsql-admin@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/130 X-Sequence-Number: 31630 2009/3/10 Jaume Sabater : > On Tue, Mar 10, 2009 at 1:07 PM, Venkat Rao Tammineni > wrote: > >> =C2=A0 I have one table which has lot of data.In the same table I have o= ne >> 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 >