Clickhouse client version : 1.1.54318
This is my query
SELECT toDayOfWeek(event_date) as dd,event_date,toString(toDateTime(toString(event_time))) as event_time,severity
from tbl_sla_alert
PREWHERE sla_id = 94 AND event_time >= '2018-02-27 14:55:00' AND (event_time >= '2018-02-27 00:00:00' AND event_time <= '2018-02-27 23:59:59') AND (dd in (4))
ORDER BY event_date,event_time
While executing this query I am getting following error :
DB::Exception: Received from localhost:9000, ::1. DB::Exception: Set for IN is not created yet!.
but I put more than 1 value into "in" condition it works perfectly.
Please suggest, Is it clickhouse bug or something I missed...
Try use 1.1.54343 and later your error message currently not exists on Clickhouse Server sources and maybe it is currently fixed
Related
Limit select count subquery work in 21.4.5.46 version but can not work in 21.10.2.15
Sql is
select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);
The sql can work very well in in 21.4.5.46 version but can not work in 21.10.2.15.
Exception is : [1002] ClickHouse exception, message: Code: 440. DB::Exception: Illegal type Nullable(Int32) of LIMIT expression, must be numeric type. (INVALID_LIMIT_EXPRESSION) (version 21.10.2.15 (official build))
How to reproduce
1 create table sql:
create table mytable(cid String,create_time String,sid String)engine = MergeTree PARTITION BY sid ORDER BY cid SETTINGS index_granularity = 8192;
2 execute sql
select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);
ClickHouse release v21.9, 2021-09-09
Backward Incompatible Change
Now, scalar subquery always returns Nullable result if it's type can be Nullable. It is needed because in case of empty subquery it's result should be Null. Previously, it was possible to get error about incompatible types (type deduction does not execute scalar subquery, and it could use not-nullable type). Scalar subquery with empty result which can't be converted to Nullable (like Array or Tuple) now throws error. Fixes #25411. #26423 (Nikolai Kochetov).
Now you should use
SELECT *
FROM mytable
ORDER BY sid ASC
LIMIT assumeNotNull((
SELECT toUInt64(count(cid) * 0.01)
FROM mytable
))
Query id: e3ab56af-96e4-4e01-812d-39af945d7878
Ok.
0 rows in set. Elapsed: 0.004 sec.
I have JPA Native queries to an Oracle database. The only way I know to limit results is using 'rownum' in Oracle, but for some reason, query parser of a jar driver I have to use does not recognize it.
Caused by: java.sql.SQLException: An exception occurred when executing the following query: "/* dynamic native SQL query */ SELECT * from SFDC_ACCOUNT A where SBSC_TYP = ? and rownum <= ?". Cause: Invalid column name 'rownum'. On line 1, column 90. [parser-2900650]
com.compositesw.cdms.services.parser.ParserException: Invalid column name 'rownum'. On line 1, column 90. [parser-2900650]
How can I get rid of that?
ANSI Standard would be something like the following
SELECT *
FROM (
SELECT
T.*,
ROW_NUMBER() OVER (PARTITION BY T.COLUMN ORDER BY T.COLUMN) ROWNUM_REPLACE
FROM TABLE T
)
WHERE
1=1
AND ROWNUM_REPLACE < 100
or you could also use the following:
SELECT * FROM TABLE T
ORDER BY T.COLUMN
OFFSET 0 ROWS
FETCH NEXT 100 ROWS ONLY;
I have a simple code to display latest error msg based on timestamp:
SELECT
line_item || ': ' || error_msg as RejectionMsg
FROM reqs
WHERE reqs_number = 'XXXXXXX'
and rqj_timestamp = (select max(rqj_timestamp) from reqs
WHERE reqs_number = 'XXXXXX' )
My data is something like :
rqj_timestamp line_item Error_msg
08-MAY-2009 14:00:04 8928 INVALID (RC4C) E
08-MAY-2009 14:00:04 8929 INVALID (R4CO) EY0
05-AUG-2013 00:13:42 11760 OO_USR_1 - NO_DATA_FOUND:No Data found for REQUEST
05-AUG-2013 00:13:42 11761 OO_USR_1 - NO_DATA_FOUND:No Data found for REQUEST
05-AUG-2013 00:13:42 11762 OO_USR_1 - NO_DATA_FOUND:No Data found for REQUEST
05-AUG-2013 00:14:59 11763 OO_USR_1 - NO_DATA_FOUND:No Data found for REQUEST
06-AUG-2013 06:55:59 11807 OO_45_ERROR_REGION_DERIV
06-AUG-2013 06:55:59 11808 OO_45_ERROR_REGION_DERIV
06-AUG-2013 06:55:59 11809 OO_45_ERROR_REGION_DERIV
My query is giving me output for 08-MAY-2009 14:00:04 time-stamp instead of the 06-AUG-2013 06:55:59 time-stamp.
3: INVALID (RC4C) E
3: INVALID (R4CO) EY0
Any idea where I am going wrong in this?OR how i can improve my query.. if i remove 08-MAY-2009 14:00:04 rows, it works perfectly fine.
Thanks in advance for help.
I would assuem your timestamp is not a date or similar data type, but a character data type like nvarchar2. Change you table to the proper data type.
A working but less clean solution would be to use something like
cast((select max(cast(rqj_timestamp as date)) from reqs) as nvarchar2)
which might depend on national language settings etc.
You would use the character data type that the column has in the outer cast.
Try something like (untested):
select *
from (
select r.*,
row_number() over (partition by reqs_number order by rqj_timestamp desc nulls last) rnum
from reqs r
where reqs_number = 'XXXXXXX'
)
where rnum = 1;
Also, the assumption is the "rqj_timestamp" is actually a timestamp (or at least a date).
Thanks for pointing out to check the datatype..turns out it was varchar, adding to_date(rqj_timestamp,'DD-MON-YYYY HH24:MI:SS') worked.
I'm doing some db querys using ActiveRecord and i need to paginate the results so i do a
$this->db->limit($pPagination['Start'], $pPagination['Length']);
but i don't get any results. Using $this->db->last_query(); it seems that CodeIgniter produces the following SQL
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0 OFFSET 15
which when i run it inside PHPMyAdmin also returns 0 rows.
But if i modify it an run :
SELECT *
FROM (`viw_contacts`)
WHERE `user_id` = '1'
ORDER BY `contact_name` asc
LIMIT 0, 15
Then i get the correct results. Any ideea why CodeIgniter generates this SQL and why it doesn't work?
I use CodeIgniter 1.7.3 and MySQL 5.1.41
Ok, found the issue.
It's
$this->db->limit($pPagination['Length'], $pPagination['Start']);
instead of
$this->db->limit($pPagination['Start'], $pPagination['Length']);
First param is the Length and second is the offset, not the other way around as i thought.
simple query causes ora - 01013 error
select count (*) as counter, 'month_stat' as name
from s_contact_x
where created < last_upd
and (sysdate - last_upd) < 1
Message: Query failed ORA-01013: user
requested cancel of current operation
This select query is succesfully running in TOAD editor, but it takes 3-5 min get resultset.
As I understood, this problem corresponding with oracle query timeout, how we can set it in query?
As others have suggested, you should first look at changing settings and adding indexes. If that doesn't work then you may want to look into using parallelism to speed up the query:
select /*+ parallel(s_contact_x) */ count (*) as counter, 'month_stat' as name
from s_contact_x
where created < last_upd
and (sysdate - last_upd) < 1