Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1032 closed defect (fixed)

column names unquoted in postgres backend CHECK expressions

Reported by: exoweb adrian Owned by: Adrian Holovaty
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: no UI/UX: no

Description

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/postgresql.py
===================================================================
--- core/db/backends/postgresql.py      (revision 1569)
+++ core/db/backends/postgresql.py      (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 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(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