receiving batch error running an update on talend into PostgreSQL database - postgresql

I have a talend solution where inside it rests a tMap --> tPostgreSQLOutput.
Inside the schema is a integer(key field) and a Date(Timestamp) in the format of "dd-MM-yyyy HH:mm:ss". The intent is to update the date field with the current time/date (Timestamp).
the date is set with this talend function call in the tMap:
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"))
I have confirmed the date(timestamp) format, and confirmed that the timestamp data type in the PostgreSQL database. However, I'm getting this error upon runtime:
Batch entry 0 UPDATE "bitcoin_options" SET "last_notified" = 2017-04-08 12:02:40.000000 -05:00:00 WHERE "id" = 3 was aborted. Call getNextException to see the cause.
I took the query it errored and manually ran it into PostgreSQL. I got this response:
ERROR: syntax error at or near "11"
LINE 1: ...bitcoin_options" SET "last_notified" = 2017-04-08 11:53:11.0...
^
Again, I checked the format, the datatype, and compared them against other tables and their UPSERTS. same format. same datatype.
In addition, I attempted to add a second space between date and time, with no avail.
UPDATE 1
I updated the tMap output to:
TalendDate.getCurrentDate();
and got the same error.
Thanks
UPDATE 2
Here's my layout for Talend:

I figured it out. after much trial and error.
The tPostgresSQLCommit x3 was redundant. When I removed the first two and placed just one, it gave me the proper output.
LESSONS LEARNED: You only need 1 commit.

Notice your timestamp is not properly formatted:
UPDATE "bitcoin_options" SET "last_notified" = '2017-04-08 12:02:40.000000 -05:00:00' WHERE "id" = 3
It's missing the single quotes surrounding the timestamp. If you add those you should be good to go.

Related

Cognos Where Clause on Date column?

I am a SQL DBA trying to get some information in Cognos.
The column name is [Packingdate] column.
In order to retrieve last 7 days of packing data information I use the below.
where [Packingdate] >_add_days( current_date, -7 ) -This is working fine.
However when i tried to get November month data I tried the below
[Packingdate] between '2021-11-01' and '2021-11-30'
It is giving me the below error
RQP-DEF-0177 An error occurred while performing operation 'sqlPrepareWithOptions' status='-126'.
Ami missing something?
Remove the quotes:
[Packingdate] between 2021-11-01 and 2021-11-30
When dealing with date or datetime data, YYYY-MM-DD (without quotes) is the format Cognos understands.

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.

Redshift varchar column time convert to 12 hours format

I have a varchar column in redshift table where the time is stored in 24 hours format, e.g, 17:00, I want to query the table and convert the format to 12 hours format showing AM or PM in time. When I test like to_char('17:00'::time,'HH12:MI AM') it works fine but when I put column name in place of hardcoded value querying the table,
SELECT to_char(prepoll_start::time,'HH12:MI AM')
FROM votecast.poll_hours AS ph
WHERE ph.prepoll_start is not null
and state = 'AL'
AND tab_elec_type = 'primary'
It won't work, gives an error
Invalid operation: Specified types or functions (one per INFO message) not supported on Redshift tables.;
Postgres version is 8.0.2
Please let me know what am doing wrong :(
First I had to create a timestamp value out of the time available. Then fetch the time in a 12 hour format.
select to_char( to_timestamp('1900-01-01 '||prepoll_start||':00' ,'YYYY/MM/DD HH:MI:SS') , 'HH12:MI AM')
from votecast.poll_hours;
Amazon Redshift does not support a TIME data type.
See: Datetime Types - Amazon Redshift
However, you are correct that it seems to support TIME for non-table related operations.
I tried playing around with string manipulation but was unable to get beyond the error you experienced. I think it is because TIME is recognized on the leader node, but fails to run on the compute nodes. (This is similar to the behaviour of time_series().)
Thus, you won't be able to use the TIME data type for anything that relies on table data.

Add Filter to extract rows where the timestamp falls in between yesterday at 4 AM and today at 3 AM in Cognos

I am new to Cognos and I am trying to add a filter to a column that only allows rows that are in between Yesterday at 4 AM and today at 3 AM. I have a working query in db2 but when I try to add it to the filter in Cognos I get a parsing error. Also, I found in the properties that the data type for the column I am trying to filter to be Unknown (Unsupported) type. I started off by creating two Data Item Expressions for each time frame I am trying to limit the data by. But I got a parsing error on the first one:
[Presentation Layer].[Cr dtime]=timestamp(current date) - 1 day + 4 hour
This works in my db2 local test database but doesn't even compile in Cognos. I also tried casting the column into a timestamp but that isn't working either. Any help is appreciated. I also tried using the _add_days function but I still get a parsing error. Also sampling the column I get values that appear to be timestamps as this string: 2016-01-02T11:11:45.000000000
Eventually if I get the two filters working I expect the original filter to be close to this syntax:
[Presentation Layer].[Cr dtime] is between [Yesterday 4AM] AND [Today 3AM]
Here is your filter:
[Presentation Layer].[Cr dtime] between
cast(_add_hours(_add_days(current_date,-1),4),timestamp)
and
cast(_add_hours(current_date,3),timestamp)
This works because current_date in Cognos does not have a time component. If you were to cast it directly to a timestamp type you would see the time part of the date as 12:00:00.000 AM, or midnight. Knowing this we can then simply add how much time after midnight we want, cast as a timestamp type and use this in the filter.

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?