Category : postgresql

I have the table test and want to extract the month from the field month which is character varying. distinct month Field value as ‘August-2020′,’September-2020’ I have tried as SELECT extract(Month from to_date(t.month, ‘%Month-%YYYY’)) as test FROM test as t but getting the error invalid value "ugust-2020" for "MONTH" DETAIL: The given value did not ..

Read more

I have this Eloquent query in vendor code from this package: H5pContent::where(‘library_id’, $library_id)->update([‘filtered’ => null]); I use Postgres for my app. The package is hardwired for MySQL, so I had to make some changes, but I’d expect this query to work with Postgres as well. However, it doesn’t: SQLSTATE[HY093]: Invalid parameter number: parameter was not ..

Read more

What is the best way to get non-utf8 results when slug contains UTF8 letters? (For example: When I type the slug "Zaidimai", select all from the database where like "Žaidimai" and "Zaidimai"). Current code: $results = DB::table(‘channels’) -> where([[‘name’, ‘like’, ‘%’ . $slug . ‘%’], [‘status’, ‘=’, ‘OK’]]) -> orWhere([[‘slug’, ‘like’, ‘%’ . $slug . ..

Read more

I am using an Ubuntu 20.04 EC2 instance with php7.4/NGINX and Laravel 8.4 point to a PostgreSQL RDS instance (no public access) in AWS. When I try to migrate (php artisan migrate) I am getting the following error: IlluminateDatabaseQueryException could not find driver (SQL: select * from information_schema.tables where table_schema = xxxxx-db-prod and table_name = ..

Read more

I’m trying to run a new laravel installation using laradock but when i try to run a artisan command this error shows up: IlluminateDatabaseQueryException SQLSTATE[08006] [7] could not translate host name "postgres" to address: Name or service not known (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = ..

Read more

I have the well executed postgres query.I have tried to convert this in laravel but query not executed select id,month,meeting_start_date,call_start_date from mgl_report_targets where extract(Month from to_date(mgl_report_targets.month, ‘%Month-%YYYY’)) in (extract(MONTH from meeting_start_date), extract(MONTH from call_start_date)); try 1 $db=DB::table(‘mgl_report_targets as t’); $db=$db->where(function ($query){ return $query->whereIn(DB::Raw("extract(MONTH from meeting_start_date)"),DB::Raw("extract(Month from to_date(‘t.month’, %Month-%YYYY))"))->orWhereIn(DB::Raw("extract(MONTH from call_start_date)"),DB::Raw("extract(Month from to_date(‘t.month’, %Month-%YYYY))")); })->select(‘id’,’month’,’meeting_start_date’,’call_start_date’)->get(); but ..

Read more

I have the query month is a field name. below is working in mysql but not in postgres. month is a character varying,metting and call start date is a date time without timestamp dataype. getting error as operator does not exist: ` character varying LINE 2: WHERE MONTH(TO_DATE(CONCAT(’01-‘, `month`), ‘%d-%M-%Y’)) ^ HINT: No operator matches ..

Read more

I’m trying to use whereExists() on an existing Eloquent query builder (called $trips): $trips = $trips->whereExists(function ($query) use ($filterValue) { $query->from(DB::raw("jsonb_array_elements(passengers->’adults’->’persons’) as p(person)")) ->whereRaw("p.person->>’name’ LIKE ‘?%’", $filterValue); }); The query I’m trying to create in raw postgres format is the following (this query works fine using pgAdmin): SELECT * from trips WHERE exists (select * ..

Read more

I am trying to save multiple records in DB and have an array which looks like:- $insert_data = array( array(record 1), array(record 2), array(record 3) ) Now, I tried two options:- Model::create($insert_data) But it doesn’t create any entry in DB. Model::insert($insert_data) It’s creating entry in DB with null datestamps. I wanna insert multiple records with ..

Read more

I try to export some data in excel using MaatwebsiteExcel. Also from front-end I pass some params ,and the problem is that in dd() I get correct data, but in excel file I get wrong data (usually nothing or all rows from db.) public function query() { $direction = ($this->request->sort_direction === ‘false’) ? ‘asc’ : ..

Read more

I try to do a query on a view from DB, with Laravel but I get an error, and I am not sure why. ViewData::query()->where(‘page’, ‘=’, ‘918’); “SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near “”””↵LINE 1: …data” where “page” = $1 order by “view_full_data”.”” asc lim…↵ ^ (SQL: select * from ..

Read more

I have data json column in my database. and I use filter by language->name in data json column. here it is languages array in data json column “languages”: [ { “name”: “Russian”, “value”: 1, “checked”: true, “editable”: false, “deletable”: false, “license_id”: 5595 }, { “name”: “English”, “value”: null, “checked”: false, “editable”: false, “deletable”: false } ..

Read more

Hi I have a large csv file with 130.000 rows I use laravel excel 3.1 and lavaravel 5.8 Import class: <?php namespace AppImports; use AppUsoSuelo; use MaatwebsiteExcelConcernsToModel; use MaatwebsiteExcelConcernsWithHeadingRow; use MaatwebsiteExcelConcernsWithChunkReading; use MaatwebsiteExcelConcernsWithBatchInserts; class UsoSueloImport implements ToModel, WithHeadingRow, WithChunkReading, WithBatchInserts { /** * @param array $row * * @return IlluminateDatabaseEloquentModel|null */ public function model(array $row) ..

Read more

A null value is value is saved every time the textbox is empty. I need the code to not save anything in the database if the textbox is left empty. if(‘questionName’!=”){ $questionName = NEW Question(); $questionName->question_name = request(‘questionName’); $questionName->user_id = Auth::user()->user_id; $questionName->save(); $questionid = DB::getPdo()->lastInsertId(); } elseif(‘questionName’==”){ $questionid = request(‘question_id’); } Source: Laravel Sta..

Read more