Skip to content

Create View fail when the query has a boolean column condition #110

@glamax13

Description

@glamax13

Hello,
I had an issue today when i tried to create a view.
I think i found the root of the problem.

As mentioned in this previous issue, toSql() is not a perfect representation of what is actually send to postgres as it will replace a boolean condition with an integer (which works fine with MySql but not Postgres).
The unfortunate consequence is that when calling Query::toSql($query), as we try to create the view BuilderView->createView(), the definition will have the integer instead of the boolean.

This behaviour applied to this exemple

<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::createView(
			'disabled',
			DB::table('disable_products')->where('soft_disabled', true)->select('disable_id')
		);
	}
}

Produces the following error:

   2025_08_08_100000_add_disabled_view .................................................................................................. 4.24ms FAIL

   Illuminate\Database\QueryException 

  SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: boolean = integer at character 93
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts. (Connection: pgsql, SQL: create view "disabled" as select "disable_id" from "disable_products" where "soft_disabled" = 1)

Calling whereBoolean() did not fix the issue as it come from the value substitution of toSql() and not the query in itself.

Thank you for your time and your work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions