I'm trying to compute Teradata queries execution time for a specific Teradata user. I currently have the following query inspired from there:
Calculating-the-actual-query-run-time
Query:
SELECT date
,a.username
,a.errorcode
,SUBSTR(b.sqltextinfo, 1, 15000)
,a.starttime
,a.firstresptime
,a.firststeptime
,((a.firstresptime - a.starttime) HOUR(4) TO SECOND(2)) AS elapsedtime
,((a.firstresptime - a.firststeptime) HOUR(4) TO SECOND(2)) AS executiontime
,elapsedtime - executiontime AS delaytime
FROM dbc.QryLogV a
INNER JOIN dbc.QryLogSqlV b ON a.procid = b.procid AND a.queryid = b.queryid
WHERE a.Username = 'xxx';
Sadly it's triggering the error:
Executed as Single statement. Failed [7453 : HY000] Interval field overflow.
Years ago the datataype for the timestamps in DBQL changed from TIMESTAMP(2) to TIMESTAMP(6), now when you try to get SECOND(2) in your result it overflows. To fix this either use SECOND(6) or ``SECOND`.
Btw, depending on your release, you'll find ElapsedTime & DelayTime pre-calculated in dbc.QryLogV.
Related
I would like to update multiple rows in the table on the PostgreSQL Database.
I tried to update the date column to the current time by using this SQL command, however, it did not work.
UPDATE data as d SET
date = c.date
FROM (values
('data_id_1', NOW()),
('data_id_2', NOW())
) as c(data_id, date)
where c.data_id = c.date;
I got this error message when I run this SQL command on the console.
ERROR: operator does not exist: text = timestamp with time zone
I am not sure where the is wrong. I would appreciate any advice or suggestions! Thank you very much.
I assume you intend something like this:
update data d
set date = c.date
from (values ('data_id_1', NOW()),
('data_id_2', NOW())
) c(data_id, date)
where c.data_id = d.data_id;
That is, the join condition should be between the tables rather than just on c.
This logic would more typically be written as:
update data d
set date = now()
where d.data_id in ('data_id_1', 'data_id_2')
I m using this query to get a result of the difference between the start time and end time of an activity. Where the end time is null i wanted to put the minimum value as 500. Please advice and HELP!!
select * from table
where (end_time - start_time) * 24 * 60 > 1,
IF end_time IS NULL THEN '500';
So this is your query:
select * from table where (end_time - start_time) * 24 * 60 > 1;
But you want to treat a null end_time as 500. So use NVL or COALESCE to replace the null with 500:
select * from table where (nvl(end_time,500) - start_time) * 24 * 60 > 1;
IF end_time IS NULL THEN '500';
Just to make it more clear, '500' is not a number rather a string since it is enclosed within single quotation marks.
Now, end_time is. DATE data type or a timestamp, ideally. So, 500 makes no sense. You must convert it to appropriate type, whether 500 is days, hours, minutes, seconds, fraction of a second.
As in other answer it is suggested to use NVL(end_time, 500), it makes no sense. What does 500 - a date mean? Applying NVL is the need, however, you must convert it to the required value, else those are two different data types and Oracle won't allow it.
UPDATE
In my opinion,
Difference between two dates gives the number of days to the precision of seconds converted back to days. But, difference between an arbitrary number and a date makes no sense.
I assumed that start_time and end_time columns have number as datatype, for this calculation you need to select these specific columns and not all (*). Comparison is in where clause, this works in oracle11.
select ((NVL(END_TIME, 500)-START_TIME) * 24 * 60) from TABLE_NAME where ((NVL(END_TIME, 500)-START_TIME) * 24 * 60) > 1;
I want to query a subset from a dataset. Each row has a time stamp of the following format:
2014-04-25T17:25:14
2014-04-25T18:40:16
2014-04-25T18:44:57
2014-04-25T19:10:32
2014-04-25T20:22:12
...
Currently, I use the following query to select a time-based subset:
time LIKE '%2014-04-25T18%' OR time LIKE '%2014-04-25T19%'
This becomes quite complicated when you start to filter by mintutes or seconds.
Is there a way to run a query that such as ...
time > '%2014-04-25T18%' AND time < '%2014-04-25T19%'
A regular expression would be okay, too.
The database is a SpatiaLite database. The time column is of type VARCHAR.
If the date is being treated as a string and based on the example above:
time LIKE '%2014-04-25T18%' AND time <> '%2014-04-25T18:00:00:000'
Otherwise, you could convert the date to seconds since midnight and add 60 minutes to that to create the range part of the filter
DECLARE #test DATETIME = '2014-04-25T17:25:14'
SELECT #test
, CONVERT(DATE,#test) AS JustDate
, DATEDIFF(s,CONVERT(DATETIME,(CONVERT(DATE,#test))), #test) AS SecondsSinceMidnight
-- 60 seconds * 60 minutes * 24 hours = 86400
Thanks to your posts and this answer I came up with this solution:
SELECT * FROM data
WHERE DATETIME(
substr(time,1,4)||'-'||
substr(time,6,2)||'-'||
substr(time,9,2)||' '||
substr(time,12,8)
)
BETWEEN DATETIME('2014-04-25 18:00:00') AND DATETIME('2014-04-25 19:00:00');
I have a table which stores an amount of seconds as integer.
I want to display it and use it as Time or Date.
If I write this:
Select Cast(ColAmountofSeconds as Time) as ThisTime From MyTable;
same with:
Select Cast(ColAmountofSeconds as Date) as ThisTime From MyTable;
I get the following error:
Overflow occurred during data type conversion. conversion error from
string "14".
Note "14" is the value of the first row in the ColAmountofSeconds column.
This is so natural in SQL Server, that I can't believe the amount of time I've spent on figuring this out.
EDIT
I can't believe this is the answer:
Update MyTable
Set TIMESPENT = time '00:00:00' + ColAmountOfSeconds;
Firebird cast function does not support converting a numeric value to date, time or timestamp.
You can take advantage of the fact that Firebird supports arithmethic between dates and numeric values, so you can write your query like this:
select dateadd(second, ColAmountOfSeconds, cast('00:00:00' as time))
from myTable;
--or the equivalent:
select cast(cast('2013-01-01' as timestamp) + cast(ColAmountofSeconds as double precision) / 86400 as TIME)
from myTable;
I have this problem. I have an sql query am trying to make to my postgres db. These queries work fine in oracle but am in the process of converting it to a postgres query but it complains. This is the query:
select to_char(calldate,'Day') as Day, date_trunc(calldate) as transdate,
Onnet' as destination,ceil(sum(callduration::integer/60) )as total_minutes,round(sum(alltaxcost::integer) ,2)as revenue
from cdr_data
where callclass ='008' and callsubclass='001'
and callduration::integer >0
and regexp_like(identifiant,'^73')
and bundleunits = 'Money'
and inserviceresultindicator in (0,5)
and regexp_like(regexp_replace(callednumber,'^256','') ,'^73')
group by to_char(calldate,'Day') ,trunc(calldate),'Onnet' order by 2
And the error am getting is this:
Err] ERROR: function date_trunc(timestamp without time zone) does not exist
LINE 4: select to_char(calldate,'Day') as Day, date_trunc(calldate)...
What am I doing wrong, or what is the solution to this error?
Try:
... date_trunc('day',calldate) ...
For PostgreSQL date_trunc() function you must always specify precision as the first argument.
Details here.