Invalid input syntax for type interval Error - postgresql-10

When i add a day to a date in postgres as below
SELECT '2018-08-20 00:00:00.0' + INTERVAL '1 DAY';
Getting below exception in pgAdmin4. Can any one help me here.
ERROR: invalid input syntax for type interval: "2018-08-20 00:00:00.0"
LINE 1: SELECT '2018-08-20 00:00:00.0' - INTERVAL '1 DAY';

SELECT date '2018-08-20 00:00:00.0' - INTERVAL '1 DAY';
Solved the problem.

Related

How to get the records from the past 1 hour in psql

SELECT * FROM auto_sync WHERE time > UNIX_TIMESTAMP(NOW() - INTERVAL 1 HOUR);
I am trying to fetch data which get added in the past 1 hour from my query but it's throwing me an error on Internal 1. Thank you
Try this.
SELECT * FROM table_name
WHERE timestamp >= NOW() - INTERVAL 1 HOUR
ORDER BY timestamp DESC
SELECT *
FROM table_name
WHERE timestamp >= NOW() - INTERVAL 1 HOUR
ORDER BY timestamp DESC
try this maybe? not sure if timestamp or time, try with both

How to get the Initial date of the month in DB2

In StoredProcedure we are passing the date like 'From date' = 2014-08-12 and 'End Date' = 2015-06-24.
I want to find like 'From Date' = 2014-08-01 and 'End Date' =2015-06-30.
So you want to go from the beginning of whatever month is passed in as from, to the ending of whatever month is passed in as end.
Beginning of month
last_day(fromdate) + 1 day - 1 month
End of the month
last_day(enddate)
You might find it useful to create a user defined function that encapsulates the beginning of month logic.
--Beginning of month
FromDate - (day(FromDate) -1) days
--End of the month
LAST_DAY(EndDate)
To get the dates between the start and end of the current month:
where date between (current_date - (day(current_date) - 1) days) and (current_date + 1 month - (day(current_date)) days)
You will probably want to replace this current date with another date, or the minimum and maximum values from some other table or result.

Informix - Need to create date time parameters for Where clause

Informix is not my normal environment and the way it handles datetime values is throwing me for a loop. I can't imagine this is difficult, but for the life of me I'm not yet able to figure it out.
This is the SQL:
SELECT agentid,
extension As Ext,
resourcefirstname As FirstNm,
resourcelastname As LastNm,
Min(eventdatetime) As FirstIn
FROM agentstatedetail AS asdr Join
resource As r On asdr.agentid = r.resourceid
WHERE asdr.eventdatetime BETWEEN '2016-10-20 04:00:00' AND '2016-10-21 03:59:59'
AND eventtype = 3
AND assignedteamid = 14
Group By agentid, extension, resourcefirstname, resourcelastname
Order By Min(eventdatetime)
Everything works as is, but the dates in the Between clause are currently entered manually- not optimal. I just need some way to describe "yesterday at 4:00 AM" and "Today at 4:00 AM" Will somebody please clue me in?
Using Informix version 12.10.FC6DE, I can do this:
SELECT
TODAY::DATETIME YEAR TO SECOND AS today_zerohour
, TODAY::DATETIME YEAR TO SECOND - '20:00:00'::INTERVAL HOUR TO SECOND AS yesterday_dawn
, TODAY::DATETIME YEAR TO SECOND + '04:00:00'::INTERVAL HOUR TO SECOND AS today_dawn
FROM
systables
WHERE
tabid = 1;
And it returns:
today_zerohour yesterday_dawn today_dawn
2016-10-21 00:00:00 2016-10-20 04:00:00 2016-10-21 04:00:00
So, what is happening here:
The operator TODAY returns the system date as a DATE type. The DATE type does not have the precision I want (it only has year, month and day), so I cast the value (cast operator is ::) to a DATETIME with precision from year to second (the hour, minutes and seconds are set to zero):
TODAY::DATETIME YEAR TO SECOND
In Informix, for an addition or subtraction with a DATETIME value to return another DATETIME value, I need to add or subtract an INTERVAL value. So I created 2 INTERVAL values.
One INTERVAL of 20 hours to subtract from the today value (again the cast operator :: is used, this time to cast from a string to an INTERVAL):
'20:00:00'::INTERVAL HOUR TO SECOND
One INTERVAL of 4 hours to add to the today value:
'04:00:00'::INTERVAL HOUR TO SECOND

Query influxdb for a date

I have a table in influxdb that has a column called 'expirydate'. In the column I have afew dates e.g. "2016-07-14" or "2016-08-20". I want to select only the 2016-07-14 date, but I am unsure how?
My query is currently:
SELECT * FROM tablee where expirydate = '2016-07-14' limit 1000
But this does not work. Can someone please help me?
Assuming the value table**e** is a valid measurement...
If you are looking at selecting all of the points for the day '2016-07-14', then your query should look something like.
Query:
SELECT * FROM tablee where time >= '2016-07-14 00:00:00' and time < '2016-07-15 00:00:00'
You might also be interested in the influx's date time string in query.
See:
https://docs.influxdata.com/influxdb/v0.9/query_language/data_exploration/#relative-time
Date time strings Specify time with date time strings. Date time
strings can take two formats: YYYY-MM-DD HH:MM:SS.nnnnnnnnn and
YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ, where the second specification is
RFC3339. Nanoseconds (nnnnnnnnn) are optional in both formats.
Note:
The limit api could be redundant in your original query as it is there to impose restriction to the query from returning more than 1,000 point data.
I had to force influx to treat my 'string date' as a string. This works:
SELECT * FROM tablee where expirydate=~ /2016-07-14/ limit 1000;

Informix: Date-Time conversion

I am getting lost and nuts with the DATETIME in Informix.I have two problems which I can hardly solve:
I have a DATETIME column (e.g. starttime) which I need to convert into an int value, e.g. seconds of year or epoch, or whatever. I found some conversion into utc, but this depends on the timezone the server runs, which I have no idea how to specify for the conversion.... Any other hint, how to convert it into seconds would be appreciated.
I need to calculate the difference between two DATETIME-fields (e.g. endtime-starttime) and then sum it up. To my understanding the result is interval day(13) to fraction(3). I need to convert the sum once again into seconds, cause I need to update other values with this result.
So, can anybody help me as to how to convert within a SQL-statement the different result-types?
CAST it to INT, example:
select
((current + 5 units day - current)::interval second(9) to second)
,((current + 5 units day - current)::interval second(9) to second)::char(10)::int8
from systables
where tabid=1

Resources