Postgres schema doesn't support keylength on a unique index

Created on 6 May 2011, almost 14 years ago
Updated 3 April 2023, about 2 years ago

Problem/Motivation

Currently, the Postgres driver treats key column specifiers for UNIQUE indices as if they were always strings. Passing a column with a prefix length, as allowed by the Schema API, leads to an error.

Steps to reproduce

Create any table (in custom or contrib code) with a UNIQUE index that has a column with prefix length specified.
Works perfectly fine on MySQL and SQLite, but fails on Postgres. (Same for adding such a UNIQUE index via addUniqueKey(), addField() or changeField().)

Proposed resolution

Fix createTableSql() and addUniqueKey() in \Drupal\Core\Database\Driver\pgsql\Schema to use createPrimaryKeySql() for creating the column list for UNIQUE keys. This will already correctly disregard any specified prefix lengths, as Postgres cannot handle them in PRIMARY or UNIQUE indices.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

🐛 Bug report
Status

Fixed

Version

10.1

Component
PostgreSQL driver 

Last updated 11 days ago

No maintainer
Created by

🇨🇭Switzerland greenrover33

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024