Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#1032 closed defect (fixed)

column names unquoted in postgres backend CHECK expressions

Reported by: exoweb adrian Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I was seeing errors like this:

The full error: ERROR:  syntax error at or near "group" at character 99

CREATE TABLE "my_table" (
    "id" serial NOT NULL PRIMARY KEY,
    "group" smallint CHECK (group >= 0) NOT NULL,

so I made this change:

Index: core/db/backends/
--- core/db/backends/      (revision 1569)
+++ core/db/backends/      (working copy)
@@ -174,8 +174,8 @@
     'NullBooleanField':  'boolean',
     'OneToOneField':     'integer',
     'PhoneNumberField':  'varchar(20)',
-    'PositiveIntegerField': 'integer CHECK (%(column)s >= 0)',
-    'PositiveSmallIntegerField': 'smallint CHECK (%(column)s >= 0)',
+    'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
+    'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
     'SlugField':         'varchar(50)',
     'SmallIntegerField': 'smallint',
     'TextField':         'text',

and then everything worked fine.

Change History (1)

comment:1 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1583]) Fixed #1032 -- CREATE TABLE SQL in Postgres now quotes column name in 'CHECK' clause. Thanks, exoweb adrian

Note: See TracTickets for help on using tickets.
Back to Top