With SphinxQL it's rather simple to search for MVAs:
SELECT * FROM s3_shop2_product
WHERE MATCH('ware 19') AND mva_field_1 = 1 AND mva_field_1 = 3;
How do I search for MVAs using SphinxSE? The following query doesn't work for me:
SELECT ... WHERE query="ware 19;filter=mva_field_1,1;filter=mva_field_1,3"
ERROR 1429 (HY000): Unable to connect to foreign data source:
failed to connect to searchd (host=127.0.0.1, errno=111, port=33
I'm using MariaDB 5.5.28.
Thanks.
After re-indexing it surprisingly worked. Thus, the following SphinxQL query:
SELECT * FROM s3_shop2_product
WHERE MATCH('#name ware 19') AND mva_field_1 IN(1,2) AND mva_field_1 = 3;
in SphinxSE looks like the following:
SELECT * FROM s3_shop2_product*emphasized text*
WHERE query='#name ware 19;filter=mva_field_1,1,2;filter=mva_field_1,3';
Related
I'm practicing SQL in Jupyter Notebook. I use sqlaclhemy and psycopg2 libs for practicing PostgreSQL syntax (using ElephantSQL) and sqlite3 lib for local db.
I have a request:
sql = '''
with medium_credits as (
select t.credit_amount from german_credit t
where t.credit_amount > 1000 and t.credit_amount < 3000
group by t.credit_amount),
medium_credits_info as (
select * from german_credit t
where t.credit_amount in medium_credits)
select t.purpose, t.housing, count(1) as count
from medium_credits_info t
group by t.purpose, t.housing
'''
Running this request using pd.read_sql(sql,connection), where connection is object created with sqlite3 - it goes great.
When I try to try it in Postgres-like system using pd.read_sql(sql,engine), where engine is object created with sqlalchemy, it throws a ProgrammingError:
ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "medium_credits"
LINE 14: where t.credit_amount in medium_credits)
I guess, Postgres doesn't let you use values from CTE-created table directly this way.
Is there any option I could run this code without an error?
PS: local and elephantsql databases are identical
try this :
with medium_credits as (
select t.credit_amount from german_credit t
where t.credit_amount > 1000 and t.credit_amount < 3000
group by t.credit_amount),
medium_credits_info as (
SELECT *
FROM german_credit t
INNER JOIN medium_credits m
ON m.credit_amount = t.credit_amount)
SphinxSearch: 3.3.1
Ubuntu 22.04
PHP 8.1.12
I am trying to use SphinxQL with PHP to find rows where two different categories match, such as:
$db = new PDO('mysql:host=127.0.0.1;port=9306', '', '');
$sql = "SELECT id FROM index,delta,rtindex WHERE category2 > 0 AND category2 = category1 LIMIT 1000 OPTION max_matches=1000";
$stmt = $db->query($sql);
However, I am receiving a syntax error whenever I do this. I thought this query had worked in the past, but I'm just now noticing it in the logs. Is this the correct way to do it, or is there some other way dictated by sphinx's rules?
I am referring https://github.com/zubkov-andrei/pg_profile for generating awr like report.
Steps which I have followed are as below :
1) Enabled below parameters inside postgresql.conf (located inside D:\Program Files\PostgreSQL\9.6\data)
track_activities = on
track_counts = on
track_io_timing = on
track_functions = on
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = 'top'
pg_stat_statements.save = off
pg_profile.topn = 20
pg_profile.retention = 7
2) Manually copied all the file beginning with pg_profile to D:\Program Files\PostgreSQL\9.6\share\extension
3) From pgAdmin4 console executed below commands successfully
CREATE EXTENSION dblink;
CREATE EXTENSION pg_stat_statements;
CREATE EXTENSION pg_profile;
4) To see which node is already present I executed SELECT * from node_show();
which resulted in
node_name as local
connstr as dbname=postgres port=5432
enabled as true
5) To create a snapshot I executed SELECT * from snapshot('local');
but getting below error
ERROR: could not establish connection
DETAIL: fe_sendauth: no password supplied
CONTEXT: SQL statement "SELECT dblink_connect('node_connection',node_connstr)"
PL/pgSQL function snapshot(integer) line 38 at PERFORM
PL/pgSQL function snapshot(name) line 9 at RETURN
SQL state: 08001
Once I am able to generate multiple snapshot then I guess I should be able to generate report.
just use SELECT * from snapshot()
look at the code of the function. It calls the other one with node as parameter.
I'm using psycopg2 to query a database that starts with a number + ".district", so my code goes like:
number = 2345
cur = conn.cursor()
myquery = """ SELECT *
FROM {0}.districts
;""".format(number)
cur.execute("""{0};""".format(query))
data = cur.fetchall()
conn.close()
And i keep receiving the following psycopg2 error..
psycopg2.ProgrammingError: syntax error at or near "2345."
LINE 1: SELECT * FROM 2345.districts...
Thought it was the type of data the problem, maybe int(number) or str(number)..but no, same error appears.
¿ What am i doing wrong ?
The way you are trying to use to pass parameters is not supported. Please read the docs.
I need help to build a Laravel query from my raw SQL Query. I tried many way and did not find my Luck. Can anybody help me? My Raw SQL code is given bellow.
SELECT exams. * , count( question_details.exam_id ) AS qus_enter
FROM exams
INNER JOIN question_details ON exams.id = question_details.exam_id GROUP BY exams.id
This is what I've tried:
$examListsID = DB::table('exams')
->join('question_details', function($join) {
$join->on('exams.id', '=', 'question_details.exam_id as qus_enter');
})
->whereraw('count(qus_enter) = exams.total_question')
->select('exams.id as examID','qus_enter','exams.total_question')
->count('qus_enter')
->groupby('exams.id')
->get();
$examLists = Addexam::where('id','=',$examListsID->examID)
And I Get this Error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as qus_enter where count(qus_enter) = exams.total_question' at line 1 (SQL: select count(qus_enter) as aggregate from exams inner join question_details on exams.id = question_details.exam_id as qus_enter where count(qus_enter) = exams.total_question)
$result = DB::table('exams')->join('question_details','exams.id','=','question_details.exam_id')->select([
exams.*,
DB::raw('count( question_details.exam_id ) AS qus_enter')
])->GroupBy('exams.id')->get()
Hope this helps
DB::listen(function ($data) {
var_dump($data->bindings);
dd($data->sql);
});