#### Category : postgresql

i want to sort the values of the table in descending order and the null value is in the first like this: null null 2020-09-27 16:36:17 2020-09-27 18:20:30 2020-09-27 22:45:26 2020-09-28 02:11:14 2020-09-28 10:31:43 I used the following code but it did not work Source::orderBy(‘last_rank_update’, ‘asc’)->get(); how can i achieve that? Sourc..

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 ..

I have a problem with inserting into table where updated_at, created_at, deleted_at have type integer. But as I understood, this columns have default type datetime and when I update note, I have an error like Invalid text representation: 7 ERROR: invalid input syntax for type integer: "2020-09-28 04:21:06". Therefore when I create a new note, ..

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 I’m writing a project in Laravel 5.3, using Postgres 10 DB. My project includes a tags list, which are stored in a "tags" jsonb column (Value example: ["hello", "goodbye"]). I’m looking to implement a filter by tags feature, which will include three different types of filters: any, all or none. (I’m given a list of .. 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 . ..

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 = ..

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 = ..

This is "tags" field as json in products table: [{"id":1,"name":"Adidas","slug":"adidas"},{"id":2,"name":"Nike","slug":"nike"}] In Eloquent, I used query: $query->whereJsonContains(‘tags->slug’, ‘adidas’); But no results are returned. How can I search by tag’s slug in products table with Laravel? Sourc.. 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 ..

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 ..

I have data: [ [ id => 1, order => 1 ], [ id => 2, order => 2 ] ] that I want to reorder to look like: [ [ id => 1, order => 2 ], [ id => 2, order => 1 ] ] Although, the order column is unique and I ..

I ran artisan migrate command successfully but I don’t see any tables created in my database. Here is full background => I am using XAMPP server with PostgreSQL(9.5) (Both servers were running at the time of creating the project) for my Laravel project I created my project with the following command: laravel new myapp –auth ..

Issue: when I browse to my login route. and attempt login, with username and password (created via tinker) I get this error: "could not find driver" using artisan’s migrate, and tinker work fine. i can connect and edit, update and remove from the database. i have no idea why its not working and spent a ..

I’m currently trying to structure a database that will work with the following 4 entities: Account: an account is a group of users Customer: customers are created by a user of the account and are linked to it (with an account_id) Service Provider: just like customers and also linked to the account Company group: a ..

I’m currently trying to structure a database that will work with the following 4 entities: Account: an account is a group of users Customer: customers are created by a user of the account and are linked to it (with an account_id) Service Provider: just like customers and also linked to the account Company group: a ..

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 ..

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’ : ..

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 I have a string column, but I have only double numbers (age), and I want to do a order by, but the obvious problem is that i get wrong response, because is string. ex: (1,10,2,3,4,40,etc…). In my code$table = name of the table, sort_by, in this particular case is “age”. $query->orderBy(“CAST(” .$table . ..

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) ..
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..