Creating an unsigned integer field in PostgreSQL using the Schema API fails when the field name is a SQL key word

Created on 10 October 2019, over 5 years ago
Updated 11 April 2023, almost 2 years ago

Some information about my environment:

* Ubuntu 18.04
* PHP 7.2
* PostgreSQL 10
* Drupal 8.8.x-dev

There's an unescaped field name reference in the PostgreSQL implementation of createFieldSql (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%...).

This was actually encountered while attempting to install the https://www.drupal.org/project/rest_oai_pmh module. In the install file (https://git.drupalcode.org/project/rest_oai_pmh/blob/80015646433d367bcfd...), the rest_oai_pmh_set table is adding a "limit" field that is unsigned, triggering the chunk in createFieldSql that adds " CHECK ({$name} >= 0)" to the field definition.

The result of this is the following error when attempting to install the module:

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near \"limit\" \n LINE 6: \"limit\" bigint CHECK (limit >= 0) NOT NULL default 10

Haven't really dug into this enough to determine if this is the specific issue, but I kind of want to poke at it some more to see if:

* changing that field name would fix it
* using other reserved SQL terms would break in the same way

I guess you could say the implementer can just not use reserved SQL terms, but on the other hand, this is kind of a ticking time bomb if you're using PostgreSQL where suddenly your installed modules could fail during a DB update, or a deployment could just blow up because you switched from MySQL to PostgreSQL.

🐛 Bug report
Status

Closed: duplicate

Version

10.1

Component
PostgreSQL driver 

Last updated 6 days ago

No maintainer
Created by

🇨🇦Canada qadan

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