Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 807939F9A77 for ; Thu, 30 Aug 2007 11:40:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 37010-03 for ; Thu, 30 Aug 2007 11:40:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtai04.charter.net (mtai04.charter.net [209.225.8.184]) by postgresql.org (Postfix) with ESMTP id 3A5C89F9A5A for ; Thu, 30 Aug 2007 11:40:00 -0300 (ADT) Received: from aa02.charter.net ([10.20.200.154]) by mtai04.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070830143950.RNMW12338.mtai04.charter.net@aa02.charter.net>; Thu, 30 Aug 2007 10:39:50 -0400 Received: from [10.0.1.3] (really [66.188.165.91]) by aa02.charter.net with ESMTP id <20070830143950.UWFM26124.aa02.charter.net@[10.0.1.3]>; Thu, 30 Aug 2007 10:39:50 -0400 In-Reply-To: <1188478863.4876.23.camel@ivangeo> References: <1188478863.4876.23.camel@ivangeo> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <39419CF6-0708-46BE-9C90-2CDC950313F4@seespotcode.net> Cc: postgresql sql list Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: date problems Date: Thu, 30 Aug 2007 09:39:47 -0500 To: marchesini@unipg.it X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/255 X-Sequence-Number: 29193 On Aug 30, 2007, at 8:01 , ivan marchesini wrote: > a lot of table have some timestamp fields containing data as DD/MM/ > YYYY, > and I'm no able to copy this table into postgres... because it needs > YYYY/MM/DD... > I used \copy... The input and output formats of dates is controlled by the datestyle setting. You can easily change this to allow COPY (and I assume \copy) to load the dates in their current format. test=# create table dates (a_date date primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "dates_pkey" for table "dates" CREATE TABLE test=# copy dates (a_date) from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 2007/08/30 >> 2007/08/29 >> \. No problem loading dates in YMD. test=# copy dates (a_date) from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 08/28/2007 >> \. No problem with MDY. test=# copy dates (a_date) from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 27/08/2007 >> \. ERROR: date/time field value out of range: "27/08/2007" HINT: Perhaps you need a different "datestyle" setting. CONTEXT: COPY dates, line 1, column a_date: "27/08/2007" DMY fails. test=# show datestyle; DateStyle ----------- ISO, MDY (1 row) The current datestyle is ISO for output and MDY for input. This explains why '27/08/2007' failed. test=# set datestyle to 'iso, dmy'; -- output still iso, input day- month-year SET test=# show datestyle; DateStyle ----------- ISO, DMY (1 row) test=# copy dates (a_date) from stdin; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 27/08/2007 >> \. Since the datestyle was changed, we can now input '27/08/2007'. test=# select * from dates; a_date ------------ 2007-08-30 2007-08-29 2007-08-28 2007-08-27 (4 rows) And there they are: all output in ISO format. Hope this helps. Michael Glaesemann grzm seespotcode net