PostgreSQL: can't insert Entity with all properties set to null/default

Migration

$table = $schema->createTable('foobar');
$table->addColumn('id', Types::BIGINT, ['autoincrement' => true]);
$table->addColumn('baz', Types::BOOLEAN, ['default' => null, 'notnull' => false]);
$table->setPrimaryKey(['id']);

Entity

/**
 * @method ?bool getBaz()
 * @method void setBaz(?bool $baz)
 */
class Foobar extends Entity {
    /** @var ?bool */
    protected $baz;

    public function __construct() {
        $this->addType('baz', 'boolean');
    }
}

Mapper

class FoobarMapper extends QBMapper {
    public const TABLE_NAME = 'foobar';

    public function __construct(IDBConnection $db) {
        parent::__construct($db, self::TABLE_NAME);
    }

    public function create(?bool $baz = null): Foobar {
        $foobar = new Foobar();
        $foobar->setBaz($baz);
        return $this->insert($foobar);
    }
}

Description

When the FoobarMapper::create method is called with the $baz parameter set to null, PostgreSQL throws an exception:

OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ")"
LINE 1: INSERT INTO "oc_appname_foobar" () VALUES()

This is because when no columns are passed at all, PostgreSQL INSERT queries need to use DEFAULT VALUES, e.g. INSERT INTO "oc_appname_foobar" DEFAULT VALUES. If at least one column is passed, there is no exception.

Also, INSERT INTO "oc_appname_foobar" () VALUES() is totally valid in MySQL, so no issues there.

So currently I am not sure what to do. Is it possible to use the IQueryBuilder to run completely self-written SQL queries, but only when on PostgreSQL? So basically I need to be able to detect which database is used and then run a manual query.

Hello,

I looked a bit at the Nextcloud documentation and source code.

You can inject the IDBConnector as you have done so in the constructor. One of the methods, this object has is getDatabaseProvider() [public interface]. This is one of the predefined strings [known plattforms].

With these, you should be able to distinguish PostgreSQL.

To run custom SQL, you have in the object also the corresponding methods. To be honest, I am unsure, if there is some parsing/postprocessing done in the NC core, so you might want/need to do some basic research here.
You could either prepare a statement or execute a statement directly. Direct execution distinguishes between queries (fetch data) and updates (modifying data, no result in row form).

I hope, this is what you need to solve your problem.

Christian