I have a timestamp attribute in my oracle 11g database table. I generated JPA entities from table and the timestamp attribute was created as a date entity. I only want to store and retrieve time values into the database. how to do this? I am using eclipseLink2.4
You can use the #Temporal(TemporalType.TIME) annotation
#Temporal(TemporalType.TIME)
private Date value;
Then only the time portion should be stored to the database.
If you're using the JPA Criteria API to create Queries, you should make sure that the Date portion is zero on existing data. I.e. on an Oracle Database if you query the data like select to_char(timecolumn,'dd.mm.yyyy hh24:mi:ss') from sometable the result should look like "01.01.1970 XX:XX:XX". Normally if you're using the JPA to store Time Values with TemporalType.TIME it will take care of that for you. If the Date portion isn't zero you may have problems comparing the time field.
Related
I am not a coder, and very much flying blind, so please excuse the simplicity of this query.
I am streaming Firebase Firestore updates to a BigQuery table using the Firebase extension "Stream collection to BigQuery" which I am then linking as a DataSource in Google Data Studio. This is currently working as intended.
I have 2 questions:
Is there a more efficient way to convert a Firebase timestamp into a BigQuery Date/Time value? The Firebase Timestamp shows in JSON format in the BigQuery table as follows:
{"created_time":{"_seconds":1647554254,"_nanoseconds":234000000}}
My BigQuery SQL code to convert it (which works) is:
DATETIME(TIMESTAMP_SECONDS(CAST(JSON_VALUE(DATA,'$.created_time._seconds') AS int64)),"Africa/Johannesburg") AS createDate
Is there a more efficient way to do this, or is this reasonable?
How do I reference the createDate computed field (above) in another computed field ageDays within this same query? I haven't found it in Google or StackOverflow, either because of poor phrasing or its just too basic a query. I tried using a table alias referencing the createDate computed field (e.g. T.createDate) but no dice. My very ugly workaround was therefore just to reperform the createDate calculation in it's entirety (which feels wrong) in my new computed column ageDays as follows:
DATE_DIFF(current_date("Africa/Johannesburg"),DATETIME(TIMESTAMP_SECONDS(CAST(JSON_VALUE(DATA,'$.created_time._seconds') AS int64)),"Africa/Johannesburg"), DAY) AS ageDays
Would be sincerely grateful for any insights - many thanks.
For your requirement, JSON_EXTRACT can also be used instead of JSON_VALUE. You can use below query to get the expected output.
select
date(timestamp_seconds(cast(json_extract( data , '$.created_time._seconds') as int64))) AS Date_Created
from `project.dataset.timetable`
Output
Table alias cannot be used to reference a field in another column with a SELECT statement as it has limited visibility. Alias can be used with Order By, Group By or Having clauses in a SELECT statement. The best way to get the ageDays is by again computing the whole createDate field.
I have columns like a int, b varchar,c timestamp in my table x (redshift) and am trying to load those three columns into another table b(redshift) by using a mapping m1, in that am using odbc connection's.
Issue is am able to load the data for all the columns except date fields (c timestamp) whether those are from src or expression.
In place of date null values are storing.
Mapping ran successful without any issue/warning.
Note: am using odbc connection's because I need to call stored procedure in Post sql.
thanks for your response.
As I modified the lookup transformation then I resolved the issue.
In lookup mapping I just modified the multiple matches to return all rows then the date fields are getting loaded from source/expression transformation to target.
I am using PostgreSQL as db, i have a timestamptz column
I want to convert it into given timezone.
select
shipment0_.estimated_delivery_date_time at time zone 'IST'
from
shipment shipment0_
is the query,
How can I implement it using JPA criteria with timezone as a user input.
I cannot use native query or JPQL since I already have other filters using criteria API
As per this blog post https://vladmihalcea.com/sql-functions-multiple-parameters-jpql-hibernate/
Managed to register a custom function using MetadataBuilderContributor
I have a field in my postgres database using the time (without time zone) data type. I have a Microsoft Access front-end for the database connected using psqlODBC, which reads this field as a "Date/Time" data type.
If I try to insert something into the field through the front end, I get the following error:
ODBC - insert on a linked table "table_name" failed.
ERROR: column "column_name" is of type time without time zone but expression is of type date;
I'm assuming that access is trying to input a time stamp instead.
Basically my question is it even really possible to use the time data type with Access? Or should I just be using the timestamp datatype instead?
If you are manually typing data into a linked table then no this won't be possible at present, if you have the option of updating your table via forms or VB then you could try this to get access to produce only a time value:
TimeSerial(Hour(Now()), Minute(Now()), Second(Now()))
Otherwise as you say, it's probably a good idea to change your data type to timestamp.
I am now building an iPhone app and it involves core data. One of the entities has an attribute with Date type, which effectively generates a column with TIMESTAMP type in the corresponding sqlite DB. The value looks something like 320928592.400471
My question is... how can I convert ordinary datetime into the TIMESTAMP type? I would like to preload some static data to the DB. Therefore, I need to know how to store the data directly to the DB.
Chances are that number is the same number returned by NSDate's timeIntervalSinceReferenceDate, i.e. seconds since 1 January 2001.
It might be easier to either populate the database on the first run of your program, or to generate the prefilled database and export it from your phone to include in the bundle.