Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have the following table in PostgreSQL:

CREATE TABLE history (
    request_date timestamp without time zone DEFAULT now() NOT NULL,
    user_id uuid,
    client_id character varying(255),
    resource character varying(255) NOT NULL,
    latency integer NOT NULL
);

I am using node-postgres to perform a COPY FROM task. This is what I have so far:

var pg = require('pg');
var copyFrom = require('pg-copy-streams').from;
var Readable = require('stream').Readable;

pg.connect(config.database.connection, function(err, client, done) {
  var stream = client.query(copyFrom('COPY history FROM STDIN WITH NULL as \'null\''));
  var rs = new Readable;

  rs.push(new Date() + '\tnull\tnull\t"' + req.originalUrl + '"\t' + responseTime);
  rs.push(null);
  rs.on('error', done);

  rs.pipe(stream).on('finish', done).on('error', function (err) {
    console.log(err);
    done();
  });
});

But I am having problems with the date (first column), I dont know what is the format needed by Postgres and I am getting the following error:

{ [error: time zone "gmt-0300" not recognized]
  name: 'error',
  length: 175,
  severity: 'ERROR',
  code: '22023',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'COPY history, line 1, column request_date: "Thu Feb 19 2015 09:51:47 GMT-0300 (ART)"',
  file: 'datetime.c',
  line: '926',
  routine: 'DecodeDateTime' }

What should be the correct way to pass that date?

share|improve this question
1  
I think copy needs an ISO formatted timestamp (2015-02-19 ...) – a_horse_with_no_name Feb 19 at 13:01
    
yes, that was the problem. I used .toUTCString() to solve this – lante Feb 19 at 13:02

1 Answer 1

up vote 0 down vote accepted

new Date().toUTCString() did the trick:

rs.push(new Date().toUTCString() + '\tnull\tnull\t"' + req.originalUrl + '"\t' + responseTime);

and then it works :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.