Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set default Date on timestamp column. #3025

Open
estaub opened this issue Feb 1, 2019 · 1 comment
Open

Cannot set default Date on timestamp column. #3025

estaub opened this issue Feb 1, 2019 · 1 comment

Comments

@estaub
Copy link

estaub commented Feb 1, 2019

Environment

Knex version: 0.16.3
Database + version: Postgresql 10.3
OS: MacOS

Problem

Trying to set a Date as timestamp column default fails:

table.timestamp('boundary_latest_update').defaultTo(new Date(0))

complains

"boundary_latest_update" timestamptz default 'Wed Dec 31 1969 19:00:00 GMT-0500 (EST)', "json" jsonb) - time zone "gmt-0500" not recognized

This works:

defaultTo(k.raw('timestamp without time zone \'1970-01-01 00:00\''))
@elhigu
Copy link
Member

elhigu commented Feb 1, 2019

Looks like .defaultTo is not using bindings to pass the value (not sure if db drivers even support using bindinds there).

That could be fixed or documented better.

Anyways it seems that if object is passed there .toString() is used to convert the value to SQL and server does not understand that timeformat. You could do .defaultTo(new Date(0).toISOString()) to use iso format for passing the datetime...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants