X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 75442B43162 for ; Wed, 9 Jul 2003 22:54:45 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 16589-04 for ; Wed, 9 Jul 2003 19:54:14 -0300 (ADT) Received: from black-label.cs.stevens-tech.edu (black-label.cs.stevens-tech.edu [155.246.89.85]) by svr1.postgresql.org (Postfix) with ESMTP id B804FB430AF for ; Wed, 9 Jul 2003 19:54:13 -0300 (ADT) Received: by black-label.cs.stevens-tech.edu (Postfix, from userid 4405) id 3A60990447; Wed, 9 Jul 2003 14:55:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by black-label.cs.stevens-tech.edu (Postfix) with ESMTP id 1AC45900FA; Wed, 9 Jul 2003 14:55:04 -0400 (EDT) Date: Wed, 9 Jul 2003 14:55:04 -0400 (EDT) From: Yasir Malik To: Dmitry Tkach Cc: pgsql-sql@postgresql.org Subject: Re: Datatype conversion help In-Reply-To: <3F0C9C84.5000808@openratings.com> Message-ID: References: <1057695693.24179.0.camel@localhost> <3F0C99E5.4090205@openratings.com> <3F0C9C84.5000808@openratings.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/115 X-Sequence-Number: 14229 I will surely use your suggestion in my future programs. Thanks, Yasir On Wed, 9 Jul 2003, Dmitry Tkach wrote: > Date: Wed, 09 Jul 2003 18:51:48 -0400 > From: Dmitry Tkach > To: Yasir Malik > Cc: pgsql-sql@postgresql.org > Subject: Re: [SQL] Datatype conversion help > > Yasir Malik wrote: > > >I used trim and here's what I came up with: > >to_date(trim(to_char(yr, '9999') || trim(to_char(mn, '00')) || > >trim(to_char(dy, '00'))), 'YYYYMMDD') > > > >Apparently to_char adds a space to the charecter you are casting. > > > > > I know :-) > And lpad doesn't - that's why I suggested it :-) > > Dima > > > > >On Wed, 9 Jul 2003, Dmitry Tkach wrote: > > > > > > > >>Date: Wed, 09 Jul 2003 18:40:37 -0400 > >>From: Dmitry Tkach > >>To: Yasir Malik > >>Cc: pgsql-sql@postgresql.org > >>Subject: Re: [SQL] Datatype conversion help > >> > >>What about lpad? > >> > >>select lpad (7, 2, 0) || '-' || lpad (9, 2, '0') || '-2003'; > >> ?column? > >>------------ > >> 07-09-2003 > >>(1 row) > >> > >> > >>I hope, it helps... > >> > >>Dima > >> > >>Yasir Malik wrote: > >> > >> > >> > >>>Thank you so much! But my problem is that when I do > >>>to_char(mn, '00') || '-' || to_char(dy, '00') || '-' || to_char(yr, > >>>'9999') > >>> > >>>where mn, dy, and yr are ints, is that the output has a space after the > >>>the dash. For example, I get > >>>07- 25- 1994 > >>> > >>>instead of what I want: > >>>07-25-1994 > >>> > >>>Thanks, > >>>Yasir > >>> > >>>On Tue, 8 Jul 2003, Richard Rowell wrote: > >>> > >>> > >>> > >>> > >>> > >>>>Date: 08 Jul 2003 15:21:33 -0500 > >>>>From: Richard Rowell > >>>>To: Yasir Malik > >>>>Subject: Re: [SQL] Datatype conversion help > >>>> > >>>>On Tue, 2003-07-08 at 15:07, Yasir Malik wrote: > >>>> > >>>> > >>>> > >>>> > >>>>>I've tried to_char(in_val, '99'), and that returns a string that is two > >>>>> > >>>>> > >>>>> > >>>>> > >>>>select to_char(9,'00'); > >>>> > >>>> > >>>> > >>>> > >>>> > >>>---------------------------(end of broadcast)--------------------------- > >>>TIP 8: explain analyze is your friend > >>> > >>> > >>> > >>> > >> > >> > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html >