#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.
Note:
See TracTickets
for help on using tickets.
(In [1583]) Fixed #1032 -- CREATE TABLE SQL in Postgres now quotes column name in 'CHECK' clause. Thanks, exoweb adrian