Skip to content

getting access to full precision timestamp (microseconds) in returned database value #269

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

Closed
spollack opened this issue Feb 12, 2013 · 5 comments

Comments

@spollack
Copy link
Contributor

postgres stores timestamps in microsecond precision. When a timestamp value comes back through node-postgres, it gets mapped to a javascript Date object with millisecond precision. I have a scenario now where i need to see the exact value. is there a way to do this?

Background:

  • i have a trigger that sets the updated_at timestamp on any row update
  • I'd like to use this for optimistic concurrency control across long operations, by checking if the row updated_at timestamp is still at the last value i read, or if someone else updated the row in the intervening time
    Alternatively, have folks solved this using version numbers instead of timestamps, or some other scheme? I want the version/timestamping to be database enforced, not client-code enforced, for robustness.

Thanks.

@spollack
Copy link
Contributor Author

i'm going to move to version numbers instead. sorry for the noise.

@freewil
Copy link

freewil commented Feb 13, 2013

You can override the parser for timestamp datatypes so it stays a string and isn't parsed into a Date object.

See #107 (comment)

@DaAwesomeP
Copy link
Contributor

@freewil & @brianc, it seems that types.js has been removed. I can't even get milliseconds shown now. It also doesn't round; it only truncates it, which is not correct anyways.

@freewil
Copy link

freewil commented Jun 12, 2014

@DaAwesomeP looks like @brianc has moved this out into another module, pg-types

@DaAwesomeP
Copy link
Contributor

Thanks @freewil! That works perfectly.

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

3 participants