Can I automatically populate `created_at` timestamp to transaction timestamp with Google Spanner? - google-cloud-storage

I am looking through the documentation for Google Cloud Spanner, and it looks like write operations return a timestamp when the row was actually written.
But when reading rows, it doesn't seem possible to re-capture that timestamp (either as a column that can be read or as a column that could be limited and sorted on).
I assume that I could just update the row after it is written to append a new column (created_at), but ideally it would be nice to have that field automatically appended.
Is there any way to access the original transaction timestamp when querying spanner? I also noticed that there was a CURRENT_TIMESTAMP() sql function. Is that equivalent to the transaction timestamp?

You can create commit timestamp columns, and Cloud Spanner writes the timestamp as part of the transaction:
https://cloud.google.com/spanner/docs/commit-timestamp

Currently, updating the timestamp column is the closest we can get.

CURRENT_TIMESTAMP() returns the current time.
See for more information:
https://cloud.google.com/spanner/docs/functions-and-operators#current_timestamp

Related

What is the best way to store formatted timestamp in Postgresql

What is the best way to store a timestamp value in Postgresql in a specific format.
For example I would like to store a TIMESTAMP '2020-07-09 17:29:30.873513Z' down to the minute and ignore seconds value.
I can drop the seconds by using date_trunc('minute', TIMESTAMP '2020-07-09 17:29:30.873513Z') Is there anyway for me to specify this format in the column itself when I create a table?
Don't store formatted timestamps in the database, use timestamp with time zone or timestamp without time zone. You would lose powerful datetime arithmetic, value checking and waste storage space.
To have the values truncated to minute precision, use a BEFORE INSERT trigger that uses date_trunc on the value.
If you want to ascertain that only such values are stored, add a check constraint.
I would like to recommend not to drop seconds or anything from the stored data. Because it will create issues while you process the data later. And if you have to eliminate anything, you may eliminate it while retrieving the data.
Use the following code while creation of table
col_name timestamp without time zone DEFAULT timezone('gmt'::text, now())
This will give you a result as shown in the following image:
Good Luck.

Pentaho Data Integration Auto Create Date Created and Last Updated

I am trying to create a job to insert all my data from Mysql to MongoDB
and this is my configuration :
how to auto generate date_created and last_updated?
so every data insert will auto fill date_created to new Date() or current date time and every data updated will auto update field last_updated with new Date() or current date.
You are looking for the Get System Info step.
It gives you a number of variables realted to the environement, including the time of the run. I usually use the system date (fixed), so that all the date-created are the same for the run, which ease retrieval.
For the last_update, it is that same technique, if you can setup your Match field for update in the MongoDB output step. If you cannot, have a look at the Merge Row (diff) : it tells you if the record is new, deleted, identical or changed.

Postgres timestamp to date

I am building a map in CartoDB which uses Postgres. I'm simply trying to display my dates as: 10-16-2014 but, haven't been able to because Postgres includes an unneeded timestamp in every date column.
Should I alter the column to remove the timestamp or, is it simply a matter of a (correct) SELECT query? I can SELECT records from a date range no problem with:
SELECT * FROM mytable
WHERE myTableDate >= '2014-01-01' AND myTableDate < '2014-12-31'
However, my dates appear in my CartoDB maps as: 2014-10-16T00:00:00Z and I'm just trying to get the popups on my maps to read: 10-16-2014.
Any help would be appreciated - Thank you!
You are confusing storage with display.
Store a timestamp or date, depending on whethether you need time or not.
If you want formatted output, ask the database for formatted output with to_char, e.g.
SELECT col1, col2, to_char(col3, 'DD-MM-YY'), ... FROM ...;
See the PostgreSQL manual.
There is no way to set a user-specified date output format. Dates are always output in ISO format. If PostgreSQL let you specify other formats without changing the SQL query text it'd really confuse client drivers and applications that expect the date format the protocol specifies and get something entirely different.
You have two basic options.
1 Change the column from a timestamp to a date column.
2 Cast to date in your SQL query (i.e. mytimestamp::date works).
In general if this is a presentation issue, I don't usually think that is a good reason to muck around with the database structure. That's better handled by client-side processing or casting in an SQL query. On the other hand if the issue is a semantic one, then you may want to revisit your database structure.

PostgreSQL table: How can I find a list of values that were inserted during a given time period?

Is there a Postgres function that would allow me to find which values were inserted during/after a giving time period, even if that given table/row does not have a timestamp value?
No. You can find the involved transaction ids by looking at the hidden system columns xmin and xmax, but you can't find the timestamp.

Can Perl DBIx::Class override the way a column is retrieved from the database?

I have never used DBIx::Class until today, so I'm completely new at it.
I'm not sure if this is possible or not, but basically I have a table in my SQLite database that has a timestamp column in it. The default value for the timestamp column is "CURRENT_TIMESTAMP". SQLite stores this in the GMT timezone, but my server is in the CDT timeszone.
My SQLite query to get the timestamp in the correct timezone is this:
select datetime(timestamp, 'localtime') from mytable where id=1;
I am wondering if it is possible in my DBIx schema for "MyTable" to force it to apply the datetime function every time it is retrieving the "timestamp" field from the database?
In the cookbook it looks like it is possible to do this when using the ->search() function, but I am wondering if it's possible to make it so if I'm using search(), find(), all(), find_or_new(), or any function that will pull this column from the database, it will apply the datetime() SQLite function to it?
DBIx::Class seems to have great documentation - I think I'm just so new at it I'm not finding the right places/things to search for.
Thanks in advance!
I've used InflateColumn::DateTime in this way and with a timestamp, and I can confirm it works, but I wonder if you have this backward.
If your column is in UTC, mark the column UTC, and then it should be a UTC time when you load it. Then when you set_timezone on the DateTime (presumably that would be an output issue - it's at output that you care it's locally zoned) you can set it to local time and it will make the necessary adjustment.