Problem with COPY and DateStyle

Started by Bruce Momjianabout 22 years ago3 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

I just found out that datestyle affects the output of COPY, and hence
pg_dump:

test=> create table test(x date);
CREATE
test=> insert into test values ('2001-07-31');
INSERT 17239 1
test=> set datestyle to 'postgres, dmy';
SET
test=> copy test to '/tmp/x';
COPY
test=> \!cat /tmp/x
31-07-2001
test=> set datestyle to 'postgres, mdy';
SET
test=> copy test to '/tmp/x';
COPY
test=> \!cat /tmp/x
07-31-2001

Should we set the datestyle at the top of pg_dump files like we do with
encoding and other settings? Seems we should.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#2Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#1)
Re: Problem with COPY and DateStyle

Never mind. I found out that pg_dump already does a SET datestyle =
'ISO' before dumping, so all the dates are in ISO format.

I just need to mention that COPY honors Datesyle.

---------------------------------------------------------------------------

pgman wrote:

I just found out that datestyle affects the output of COPY, and hence
pg_dump:

test=> create table test(x date);
CREATE
test=> insert into test values ('2001-07-31');
INSERT 17239 1
test=> set datestyle to 'postgres, dmy';
SET
test=> copy test to '/tmp/x';
COPY
test=> \!cat /tmp/x
31-07-2001
test=> set datestyle to 'postgres, mdy';
SET
test=> copy test to '/tmp/x';
COPY
test=> \!cat /tmp/x
07-31-2001

Should we set the datestyle at the top of pg_dump files like we do with
encoding and other settings? Seems we should.

-- 
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 359-1001
+  If your life is a hard drive,     |  13 Roberts Road
+  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#1)
Re: Problem with COPY and DateStyle

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Should we set the datestyle at the top of pg_dump files like we do with
encoding and other settings? Seems we should.

That was dealt with quite a while back.

regards, tom lane