【问题标题】:Laravel: Eloquent and Multicolumn indexLaravel:雄辩和多列索引
【发布时间】:2023-04-03 20:31:01
【问题描述】:

我正在使用 Laravel 5.7 和 PostgreSQL 构建一个站点。问题是:

Schema::table('the_table', function (Blueprint $table) {
    $table->index(['column1', 'column2'], 'the_index', 'the_method')
});

相当于

CREATE INDEX the_index ON the_table USING the_method ((ARRAY[column1, column2]));

?

如果没有,有没有办法用 Eloquent 做到这一点?

【问题讨论】:

    标签: php sql laravel postgresql eloquent


    【解决方案1】:

    使用原始表达式和algorithm():

    Schema::table('the_table', function (Blueprint $table) {
        $table->index([DB::raw('(ARRAY[column1, column2])')], 'the_index')->algorithm('btree');
    });
    

    【讨论】:

    • 谢谢。顺便说一句,我猜这相当于CREATE INDEX the_index ON the_table USING the_method (column1, column2);?有没有办法使用 Eloquent 创建带有 (ARRAY[column1, column2]) 的索引?
    猜你喜欢
    • 2020-02-11
    • 2020-03-19
    • 2021-05-12
    • 1970-01-01
    • 2015-03-04
    • 2014-07-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多