Django

Code

Ticket #1032 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

column names unquoted in postgres backend CHECK expressions

Reported by: exoweb adrian Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

12/08/05 21:32:47 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #1032 (column names unquoted in postgres backend CHECK expressions)




Change Properties
Action