0

I have a MySQL table where I am recording token creation times and I would like to create the equivalent of this Postgres construct:

token_start_times INTEGER DEFAULT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)

MySQL provides unix_timestamp(now()) but it returns a timestamp value and not an integer value.

I tried this

token_start_times INTEGER DEFAULT timestamp(now())

but MySQL complains about the syntax. I read this post but it doesn't answer my question.

Community
  • 1
  • 1
Not a machine
  • 508
  • 1
  • 5
  • 21
  • 2
    A timestamp **is** an integer. But you can't put function calls into the `DEFAULT` option. – Barmar Apr 25 '16 at 16:51
  • The function call was a hail mary pass. I looked through the documentation and I didn't see any value I could isolate with Extract. I may have to refactor and move the functionality into the code. – Not a machine Apr 25 '16 at 17:13
  • With all the power and flexibility behind `DATETIME` and `TIMESTAMP`, why do you want a plain `INT`? – Rick James Apr 26 '16 at 00:15
  • It is far faster and simpler to perform calculations on integers when processing tokens. In general, I store all my JWT token create and expire values as INT. – Not a machine May 09 '16 at 17:33

2 Answers2

0

try this to get the value as integer:

SELECT now()+0;
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39
0

It appears the only way to do what I want to do is with an AFTER INSERT trigger. I prefer not to use triggers as it causes the development environment to increase in complexity. For more details see this post by Ike Walker.

Community
  • 1
  • 1
Not a machine
  • 508
  • 1
  • 5
  • 21