To_timestamp function

Is there any to_timestamp function in Cockroach equivalent of the postgres function? I can see the github issue closed but not able to find this function in the docs?

I believe experimental_strptime performs a similar role in Cockroach. See
for details.

But experimental_strptime does not convert epoch to timestamp.

I think that casting an integer to a timestamp should interpret it as an epoch.

Also I believe that the %s strptime directive will interpret the unix epoch in seconds.

@david @benesch I did not get you. In postgres we can use to_timestamp(1284352323). Can we achieve the same using experimental_strptime?

Also why is this method name starting with experimental is it not fully supported?

@tuk It is marked as experimental because we’re unsure if we will keep it – as I recall, it is borrowed from C and doesn’t match its Postgres counterpart exactly, though @knz can offer more details.

As far as that to_timestamp call, I believe you can replace it with 1284352323::timestamp to get the same behavior.

1 Like

So our implementation of strptime is probably fine (it is inspired from C but we made an implementation which is not dependent on C) for the purpose here. The set of formatters we support is currently documented here: (we’ll make a doc page later) and indeed %s is probably what you want.

We will also probably keep strptime as non-experimental in a future release, but perhaps using a different name than “strptime”, as David explained because pg’s function of the same name works slightly differently and perhaps we can’t support the pg semantics exactly.