Postgres saves the timestamp in an internal format, and when you read it, it displays it in the format you request.
knex_test=
knex_test=
created_at
2017-04-20 19:33:56.774+03
(1 row)
knex_test=
Table "public.accounts"
Column | Type | Modifiers
id | bigint | not null default nextval('test_table_one_id_seq'::regclass)
last_name | character varying(255) |
email | character varying(255) |
logins | integer | default 1
about | text |
created_at | timestamp with time zone |
updated_at | timestamp with time zone |
phone | character varying(255) |
Indexes:
"test_table_one_pkey" PRIMARY KEY, btree (id)
"test_table_one_email_unique" UNIQUE CONSTRAINT, btree (email)
"test_table_one_logins_index" btree (logins)
knex_test=
You can change in which time window postgres returns timestamps for your connection with
knex_test=
SET
knex_test=
created_at
----------------------------
2017-04-20 16:33:56.774+00
(1 row)
knex_test=
And this is how it is done with knex https://github.com/tgriesser/knex/issues/97
var knex = Knex.initialize({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test',
},
pool: {
afterCreate: function(connection, callback) {
connection.query('SET timezone = timezone;', function(err) {
callback(err, connection);
});
}
}
});
source
share