I have a table (with soft delete) and it is a whats on table. There is a field which is just a date field with the start date.
What I am trying to do is use eloquent to get a list of what on today onwards, but my attempts throw an error:
$wo = App\WhatsOn::whereDate('startDate', '=>', date('Y-m-d') )->get();
The error I am getting is
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 '=> ? and whatson.deleted_at is null' at line 1 (SQL: select * from whatson where date(startDate) => 2019-05-05 and whatson.deleted_at is null)
Help greatly appreciated!
It should be:
$wo = App\WhatsOn::whereDate('startDate', '>=', date('Y-m-d') )->get();
Dumb mistake!
Related
I have a jsonb type field, I need to update a field named 'action' using an update statement below:
update tickets set action = action || '[{\"reply_to\":0,\"date_time\":\"2022-04-09\",\"comment\":\"Testing only\",\"transaction_id\":39,\"user_email\":\"someone#gmail.com\",\"task_status\":1,\"files\":null}]
but it failed with message:
SQL Error [42601]: Unterminated string literal started at position 38 in SQL update tickets set action = action || '[{"reply_to":0,"date_time":"2022-04-09","comment":"Testing only","users_pid":39,"user_email":"s","task_status":1,"files":null}] . Expected char
I have been struggling to assign the query result to a temp variable in PostgreSQL and I just can't get it to work. Can anyone guide please?
I tried with the both the below queries and I get the error shown below. I then tried with temp table. But it still fails during the assignment to the temp variable.
set var.ITEM_ID =(select t.item_id from api_item t inner join api_identifier i on i.item_id=t.item_id where i.value='99999');
set var.ITEM_ID = select t.item_id from api_item t inner join api_identifier i on i.item_id=t.item_id where i.value='99999';
The first statement throws the error :-
[2020-03-03 08:10:50] [42601] ERROR: syntax error at or near "("
[2020-03-03 08:10:50] Position: 23
Second one throws the below error:-
[2020-03-03 08:10:55] [42601] ERROR: syntax error at or near "select"
[2020-03-03 08:10:55] Position: 24
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);
});
[EDIT: This problem was a result of a bug within version 3.7.6]
The following postgresql query is returning an error:
operator does not exist date = boolean.
I can't figure out why. Here is the postgresql code that is giving me the error:
select
c.source,
s.name,
s.grouping,
s.kli,
s.term_desc,
(s.population - s.online) as non_hb_pop,
s.online as hb_pop,
s.population as full_pop,
s.rep_date
from
dwh.rpt_cu_private_kli_summary s, dwh.rpt_sgmt_clients c
where
s.partner_id::integer = $P{rpt_cu}
and s.rep_date = $P{rpt_date_beg}
and s.userid=c.userid
group by
c.source, s.term_desc, s.name, s.grouping,
s.population, s.online, s.kli, s.rep_date
order by
s.grouping,
full_pop desc,
s.term_desc;
What does the above error message mean?
What is the value for $P{rpt_date_beg} ? That's where things go wrong. Check the real query, might be in the errorlog, and do some debugging. Maybe some quotes ' are missing around the date value.
I have a database in Postgresql 9.0 and I'm trying to use Doctrine ORM 1.2 to generate models from db.
Here is my code:
<?php
require_once 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$conn = Doctrine_Manager::connection('pgsql://postgres:secret#192.168.1.108/erp','doctrine');
$conn->setAttribute( Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_FIX_CASE | PORTABILITY_RTM);
$conn->setAttribute( Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
Doctrine_Core::loadModels('../application/models');
Doctrine_Core::generateModelsFromDb('../application/models', array('doctrine'), array('generateTableClasses' => true));
?>
and when I run the page, I get this error:
Fatal error: Uncaught exception 'Doctrine_Connection_Pgsql_Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "t" LINE 6: ... t.typtype ... ^. Failing Query: "SELECT ordinal_position as attnum, column_name as field, udt_name as type, data_type as complete_type, t.typtype AS typtype, is_nullable as isnotnull, column_default as default, ( SELECT 't' in D:\Doctrine-1.2.3\Doctrine-1.2.3\Doctrine\Connection.php on line 1082
It's worth to mention, this code is working perfectly for mysql (by having mysql:// ... in the connection ofcurse), but having trouble to get it working with postgresql 9.0.
Any idea?
Sounds like this bug in Doctrine: http://www.doctrine-project.org/jira/browse/DC-919
Try to add quotes to table name, or column names.
Find right naming while exporting a table.
My problem was that someone added quotes to table name.
$sql='SELECT "id","name",
("f1"=\'aaa\' OR
"f1"=\'bbb\') AS "myflag"
FROM "mytable"';