orientdb set date value to vertex fails - orientdb

OrientDB update statement fails.
Below update statement to update the date on vertex fails.
Update VertexA SET UpdatedDate = "2018-09-18" where #rid=#27:0
Tried couple of other options with asDate() and date() function as shown below but no luck.
Update VertexA SET UpdatedDate = "2018-09-18 00:00:00" where #rid=#27:0
Update VertexA SET UpdatedDate = "2018-09-18".asDate() where #rid=#27:0
Thanks in advance for any help.

There are two things to note here.
1. We have to set the Date format at the database using the following syntax.
ALTER DATABASE DATEFORMAT "yyyy-MM-dd"
After this statement was run, everything works fine.
In other vertex/edges I had date column name as From and To. These column names were not working. It seems they are conflicting with OrientDB key words.
Solution : Change the column name and to something like FromDate and ToDate.
It started working.
If you would like to use the column names as From and To then you have look/search for the documentation of OrientDB to see if they provide any escape char to allow the keywords to be used as column names.
In MS SQL You can use the Key words as column names with in the square brackets [] ex: [Description]
I hope this is useful for other developers.

Related

I want to know an efficient way to link "yyyy-mm-dd" date type data to DataStudio

Can I accept "yyyy-mm-dd" instead of "yyyymmdd" when I put data into a date type column in DataStudio?
From the following Q&A and the official documentation, it looks like "yyyymmdd" only.
Google data studio table shows date column as null
https://support.google.com/datastudio/answer/6401549?hl=en#zippy=%2Cin-this-article
However, since the date type of Snowflake, the source of the linkage, only allows "yyyy-mm-dd", the
I'd like to know how to do this efficiently, because I'm changing the date type to a character type, linking it to DataStudio, and then changing it back to a date type in DataStudio.
https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#date
I would appreciate it if you could tell me.
Not exactly sure how things are mapped from Snowflake to DataStudio, but Snowflake can produce yyyymmdd dates.
SELECT TO_VARCHAR('2021-08-19'::DATE, 'YYYYMMDD');
If DataStudio requires that the data type from the source be a DATE then perhaps you could alter the date_output_format of your connection session or user to be 'YYYYMMDD'.
https://docs.snowflake.com/en/sql-reference/parameters.html#label-date-output-format
Import your data as it is into Data Studio. In the schema screen, ensure your source date field ("yyyy-mm-dd") is formatted as text. Then add a calculated field with the formula:
TODATE(source_date_field,"%Y-%m-%d","%Y%m%d")
TODATE reference
Formate the new calculated field as date.

Date CAST in SQL Server throwing conversion failed for a date

I am experiencing a very unique cast error I don't understand why it happens with some dates and only in one particular case.
First at all, I cannot change the current code, it's a dynamic query from a legacy application and it's the result of queries to different tables to assemble the query I am having troubles with.
The error is a classic 'conversion failed when converting date and/or time from character string'.
At the beginning I thought it was a classic file naming error, we obtain the date from the file name in the format YYYYMMDD, the file has prefix and suffix and it's always formatted like that. It was pretty common to get wrongly formatted dates but it doesn't happen anymore. The issue is interesting because it only happens in 1 case for some dates that do not look like errors, for example, 20201105 which is basically translated to 11/05/2020 (US Format with month first).
This is the query:
SELECT TOP 1 CAST(LEFT(REPLACE(FileName, 'XXYYY_,''),8) AS DATE) AS MyDate FROM Mytable
The file name in this case is XXYYY_20201105.txt
Why the top 1? Well, it is a very bad design, there are many rows with the same value and it has to take only one to determine the date.
The most interesting part of it, when it fails I can "fix" the error just adding one more column:
SELECT TOP 1 CAST(LEFT(REPLACE(FileName, 'XXYYY_,''),8) AS DATE) AS MyDate, AnotherColumn
FROM Mytable
This query, just adding a column, doesn't fail. That's the weirdest part. I am trying wrap my head around what is the difference between obtaining ONE column and TWO columns. When I add any other column it seems to make the issue disappear.
Thanks a lot.

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.

Amazon Redshift Date Comparison

I am getting an error "Specified types or functions (one per INFO message) not supported on Amazon Redshift tables." and I am unsure as to why and couldn't find any support anywhere else.
I am trying to filter or delete rows where the current date is after a certain date. I've created a very simple example.
Table "tmp" has one column "date" with one row with the value '2016-01-01'.
I want to delete the row, because it is a date that is in the future.
So my query would be:
DELETE FROM "tmp" WHERE TO_DATE((NOW()),'YYYY-MM-DD HH:MI:SS') < "date";
However I get the error:
"Specified types or functions (one per INFO message) not supported on Amazon Redshift tables."
I also tried casting the "date" column to DATE datatype but same error.
I also tried the function "DATE_CMP" to do a BOOLEAN comparison
SELECT DATE_CMP((TO_DATE(NOW(),'YYYY-MM-DD HH:MI:SS')),"date"::DATE), "date"
FROM "tmp"
but that produced the same error.
Could someone help me out with why this is? The only thing I can find in Redshift documentation is here but it doesn't seem to really mention anything relevant.
to_date(now(), ...) makes no sense. now() is already a date there is no need to convert it to one.
The condition "where the current date is after a certain date" can be written as:
delete from tmp
where current_date > "date";
All date functions are documented here: http://docs.aws.amazon.com/redshift/latest/dg/Date_functions_header.html
date is a horrible name for a column. For one because it is also a keyword, but more importantly it does not document what the column contains. A start date? An end date? A due date? A visit date? An invoice date?

IBM i (AS400/ISeries) - Adding days to date field in WRKQRY

I have a decimal date field (TDDATR) that is in the YYYYMMDD format.
I would like to create a field that is TDDATR + 30 days but I am unable to.
Using 'Define Results Field' I have tried a few things;
Simply doing this;
TDDATR + 30 DAYS
But it returned this error: Labeled duration not used correctly.
I tried using the DIGITS and SUBSTR commands to create a field in the DDMMYYYY format and then +30 days but got the same error.
Same as above but in the DD/MM/YYYY format - same error.
Using DATE(TDDATR) but all I see is +'s in the field.
Using DATE( ) on the fields created in step 2 and 3 - still get +'s
I've ran out of ideas - any help would be greatly appreciated.
Query/400 lacks a lot of the features that an SQL based interface has.
I'd urge you to consider switching to Query Manager (STRQM) which is a fully SQL based product. You can even convert Query/400 queries to Query Manager queries with the RTVQMQRY command by having the ALWQRYDFN parm set to *YES.
The other option that IBM is pushing is Web Query. Again, fully SQL based and you can convert Query/400 queries into it.
Having said that, the problem is that FLD + 30 DAYS only works when FLD is a DATE data type. Query/400 includes a DATE() function to convert non-date types into date. But it's very limited in that it only works with character fields formatted according to your job defaults. Assuming you're in the US, it'd only work with a character value of '07/01/15'.
You could do a lot of manipulation in Query/400 and end up with a result field that meets DATE()'s requirements. But a better solution would be to create an SQL view over your table and have your numeric date converted into a date data type in the view.
You can find code examples that show how to convert a numeric YYYYMMDD to a actual date data type in the view. However, I'd recommend create a user defined function (UDF) that will do the conversion for you. That will make it much easier to use in the view and to reuse in other places.
If you'd like, there's an open source package called iDate, that includes all the code required for convert to/from date data types.
Download that, install/compile it and your SQL view becomes
select ... idate(TDDATR,'*CCYMD') as TD_DATE
from myfile
The use of days is as follow
Field Expression
CURDATE_30 days(current(date)) + 30
The solution to your problem is: given the field A dec(8,0)
Field Expression
YYYYMMDD_ date(substr(digits(a),5,2)||'/'||
substr(digits(a),7,2)||'/'||
substr(digits(a),3,2))
NEXT_MONTH DAYS(YYYYMMDD_) + 30
Remember to check the date format in your job description. In the example the format is MDY or MM/DD/YY.
More info here
Based on the information here, I created the below 2 fields;
TDDIGI DIGITS(TDDATR)
TDDAT1 SUBSTR(TDDIGI,7,2)||'/'||
SUBSTR(TDDIGI,5,2)||'/'||
SUBSTR(TDDIGI,3,2)
From here I was able to create a date field;
TDDAT2 DATE(TDDAT1)
Which allowed me to perform the necessary calculations.
The format of TDDAT1 is based on your job description which can be found by;
WRKJOB
Option 2
Page down
Date format..: X
Mine was *DMY, so TDDAT1 was formatted based on this.