sphinxQl getting query log - sphinx

Using SphinxQl, while executing this query , i am getting following error
select fieldname from indexname where height >= 165.25 and height <= 175.25 OR Age >=51;
ERROR 1064 (42000): sphinxql: syntax error, unexpected OR, expecting $end near 'OR Age >=51'
select fieldname from indexname where (height >= 165.25 and height <= 175.25) OR Age >=51;
ERROR 1064 (42000): sphinxql: only >=, <=, and BETWEEN floating-point filter types are supported in this version near '(height >= 165.25 and height <= 175.25) OR Age >=51'
Advance thanks , Please suggest

Try something like
SELECT fieldname, IF( (height >= 165.25 AND height <= 175.25) OR Age >=51, 1, 0)
AS myfilter FROM indexname WHERE myfilter = 1
Sphinx can do 'OR', they just can't physically be in the WHERE clause itself.

Related

Database migration syntax

I am unsure how to rewrite this. I understand the issue or at least I think I do. I am unable to use instances of t before it is defined by the follow "AS" statement. How can I resolve this so that so that it works the same way without using the instance of t before definition?
The error that I am getting thrown from the converter is "unable to convert .t"
Converted code
INSERT INTO t$trades_long (portfolio_name, fund, cusip, td_num, desc_instmt, trd_price, trd_trade_dt, t.trd_settle_dt, trd_counterparty, trd_td_par, tran_type, sec_type, trd_type, t.trd_trader)
SELECT
p.portfolio_name, t.fund, t.cusip, t.td_num, a.desc_instmt, t.trd_price, t.trd_trade_dt, t.trd_settle_dt, t.trd_counterparty, t.trd_td_par, t.tran_type, a.sec_type, 'long' AS trd_type, trd_trader
FROM pfi_pilot.br_transaction AS t, pfi_pilot.br_portfolio_group AS p, pfi_pilot.br_asset AS a
WHERE t.fund = p.fund AND p.portfolio_group = 'ALL_FUNDS' AND t.cusip = a.cusip AND t.tran_type IN ('BUY', 'SELL', 'ISSUE', 'ALLOC') AND t.trd_status <> 'C' AND a.sm_sec_group NOT IN ('CASH', 'FUTURE', 'FX', 'FUND', 'SWAP', 'OPTION') AND a.sec_type != 'MBS_TBA' AND t.trd_counterparty NOT IN ('IFUND', 'GHOST', 'SPO', 'SPOBO', 'CONV', 'ASSGN') AND t.trd_trade_dt >= par_from_dt AND t.trd_trade_dt <= par_to_dt AND t.cusip NOT IN (SELECT DISTINCT
cusip
FROM pfi_pilot.br_asset
WHERE (COALESCE(risk_country, country) = 'US' AND sm_sec_type IN ('GOVT', 'TBILL'))) AND t.trd_td_par > 0;
Original code
insert into #trades_long(portfolio_name, fund, cusip, td_num, desc_instmt, trd_price, trd_trade_dt, t.trd_settle_dt,
trd_counterparty, trd_td_par, tran_type , sec_type, trd_type, t.trd_trader)
select p.portfolio_name, t.fund, t.cusip, t.td_num, a.desc_instmt, t.trd_price, t.trd_trade_dt, t.trd_settle_dt,
t.trd_counterparty, t.trd_td_par, t.tran_type, a.sec_type,'long' as trd_type, trd_trader
from br_transaction t, br_portfolio_group p, br_asset a
where t.fund = p.fund
and p.portfolio_group = 'ALL_FUNDS'
and t.cusip = a.cusip
and t.tran_type in ('BUY','SELL','ISSUE','ALLOC')
and t.trd_status <> 'C'
and a.sm_sec_group not in ('CASH','FUTURE','FX','FUND','SWAP','OPTION')
and a.sec_type != 'MBS_TBA'
and t.trd_counterparty not in ('IFUND','GHOST','SPO','SPOBO','CONV','ASSGN')
and t.trd_trade_dt >= #from_dt
and t.trd_trade_dt <= #to_dt
and t.cusip not in (select distinct cusip from br_asset where (isnull(risk_country,country) = 'US'
and sm_sec_type in ('GOVT','TBILL')))
and t.trd_td_par > 0

postgresql ERROR: syntax error at or near "CONCAT"

i am trying to fetch users list who older than and between 20 to 60 minute randomly. here is my query
SELECT *
FROM t_users
WHERE create_time <= NOW() - INTERVAL CONCAT(floor(random()* (60-20 + 1) + 20),' minutes');
it's giving me error ERROR: syntax error at or near "CONCAT"
You can't use concat() like that to create an interval. The easiest solution is to use make_interval:
WHERE create_time <= NOW() - make_interval(mins => (floor(random()* (60-20 + 1) + 20))::int )

NULLIF how to set it properly in this query

I am using the following query to get some tablespaces usage at a glance:
db2 "select substr(tbsp_name,1,30) as Tablespace_Name, tbsp_type as Type, substr(tbsp_state,1,20) as Status, (tbsp_total_size_kb / 1024 ) as Size_Meg, smallint((float(tbsp_free_size_kb)/ float(tbsp_total_size_kb))*100) as Percent_Free_Space, int((tbsp_free_size_kb) / 1024 )as Meg_Free_Space from sysibmadm.tbsp_utilization where smallint((float(tbsp_free_size_kb)/ float(tbsp_total_size_kb))*100) < 20 order by Percent_Free_Space"
however, I'm stuck with the following error:
SQL0801N Division by zero was attempted. SQLSTATE=22012
I understand you can fix this error with a NULLIF however I can't find the correct way to set in in the query, thanks for the help.
( using "DB2 v9.7.0.11", "s150922", "IP23937", and Fix Pack
"11")
Maybe you should use case:
CASE WHEN tbsp_total_size_kb=0 THEN NULL ELSE (tbsp_total_size_kb / 1024 ) END as Size_Meg
if tbsp_total_size_kb can be null IFNULL like this:
CASE WHEN IFNULL(tbsp_total_size_kb,0)=0 THEN NULL ELSE (tbsp_total_size_kb / 1024 ) END as Size_Meg
Try this:
smallint(float(tbsp_free_size_kb) / float(nullif(tbsp_total_size_kb,
0)) * 100)

Using "BETEEN" operator on a LONG-EMBEDDED-LIST property declared in OrientDB 2.2.17

I am using OrientDB 2.2.17 (enterprise edition) and I have a problem searching on the data:
I have a vertex called: EN70 with a property: EP70_4 from type 'embedded list = LONG'.
I added a record to this vertex with the value of [2,3,4] in this 'EP70_4' property.
The index on this property: Not_Unique (sbtree). [must support range queries]
SELECT * FROM EN70 WHERE (EP70_4 >= 1) is working and returns my record.
SELECT * FROM EN70 WHERE (EP70_4 <= 3) is working and returns my record.
The operator "Between" is not woking and throw exception:
SELECT * FROM EN70 WHERE (EP70_4 BETWEEN 1 AND 3 )
I tried to simulate a "between" operator:
SELECT * FROM EN70 WHERE ((EP70_4 >= 1) AND (EP70_4 <= 3)) IS NOT WORKING
but it is not working.
both sections 6 and 7 throws an exception:
Error on using index EN70.EP70_4 in query 'SELECT * FROM EN70 WHERE (EP70_4 BETWEEN 1 AND 3 )'. Probably you need to rebuild indexes. Now executing query using cluster scan
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Long
at com.orientechnologies.common.serialization.types.OLongSerializer.preprocess(OLongSerializer.java:36)
at com.orientechnologies.orient.core.index.sbtree.local.OSBTree.iterateEntriesBetweenAscOrder(OSBTree.java:1474)
at com.orientechnologies.orient.core.index.sbtree.local.OSBTree.iterateEntriesBetween(OSBTree.java:771)
at com.orientechnologies.orient.core.index.engine.OSBTreeIndexEngine.iterateEntriesBetween(OSBTreeIndexEngine.java:185)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.doIterateIndexEntriesBetween(OAbstractPaginatedStorage.java:2065)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.iterateIndexEntriesBetween(OAbstractPaginatedStorage.java:2053)
at com.orientechnologies.orient.core.index.OIndexMultiValues.iterateEntriesBetween(OIndexMultiValues.java:275)
at com.orientechnologies.orient.core.index.OIndexAbstractDelegate.iterateEntriesBetween(OIndexAbstractDelegate.java:104)
at com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue.iterateEntriesBetween(OIndexTxAwareMultiValue.java:339)
at com.orientechnologies.orient.core.sql.operator.OQueryOperatorBetween.executeIndexQuery(OQueryOperatorBetween.java:131)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchForIndexes(OCommandExecutorSQLSelect.java:2184)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchInClasses(OCommandExecutorSQLSelect.java:1001)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetAbstract.assignTarget(OCommandExecutorSQLResultsetAbstract.java:209)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.assignTarget(OCommandExecutorSQLSelect.java:530)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:512)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:488)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:74)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:2624)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:2570)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:69)
at com.orientechnologies.orient.server.network.protocol.http.command.post.OServerCommandPostCommand.execute(OServerCommandPostCommand.java:106)
at com.orientechnologies.orient.graph.server.command.OServerCommandPostCommandGraph.execute(OServerCommandPostCommandGraph.java:37)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.service(ONetworkProtocolHttpAbstract.java:169)
at com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpAbstract.execute(ONetworkProtocolHttpAbstract.java:622)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:77)
What can it be??? Please help me...
I'd say it's a bug, I strongly suggest you to report it here: https://github.com/orientechnologies/orientdb/issues

PostgreSQL View Error Handling

The code given below is a part of a view that I have created. But sometimes it may throw an error saying:
division by zero
The reason for this error is that sum(bills.past_arrear) part may be 0 for some months.
SELECT (SELECT revenue_driver.driver_id
FROM ccdb.revenue_driver
WHERE revenue_driver.driver_desc::text = 'Arrear Collection Efficiency'::text) AS driver_id
,bills.org_unit_id::integer AS section_id
,date_part('Month'::text, bills.due_date) AS mnth
,date_part('Year'::text, bills.due_date) AS yr
,ROUND(SUM(COALESCE(bills.arrear_collected,0::numeric))/sum(bills.past_arrear)*100::numeric, 2) AS per_efficiency
,now() AS creation_dt
FROM ccdb.bills
WHERE bills.due_date::date >= date_trunc('Month'::text,'now'::text::date::timestamp with time zone)::date
AND bills.due_date::date <= 'now'::text::date
AND (bills.bill_type_group_code::text = ANY (ARRAY['EB'::character varying::text, 'Energy'::character varying::text]))
GROUP BY bills.org_unit_id, date_part('Year'::text, bills.due_date), date_part('Month'::text, bills.due_date);
What I want is if ROUND(SUM(COALESCE(bills.arrear_collected,0::numeric))/sum(bills.past_arrear)*100::numeric, 2) throws division by zero error I want to replace the value with 0.
I have not idea how do handle this error. Kindly someone help me on this.
You need to use a CASE WHEN in your select statement like below :-
CASE
WHEN sum(bills.past_arrear) = 0
THEN 0
ELSE ROUND(SUM(COALESCE(bills.arrear_collected, 0::NUMERIC)) / sum(bills.past_arrear) * 10 ‌​0::NUMERIC, 2)
END AS per_efficiency