Home > Back-end >  why is group a wrong alias in postgres Django for auth_group table
why is group a wrong alias in postgres Django for auth_group table

Time:02-23

Why is that the following simple query does not work (Using Django in the backend)

# select group.name from auth_group as group;
ERROR:  syntax error at or near "."
LINE 1: select group.name from auth_group as group;

while the following works

# select groupd.name from auth_group as groupd;
     name      
---------------
 FO Admin Role
 admin
 alice
 bob
(4 rows)

What is wrong with using group as an alias ?

CodePudding user response:

group is a reserved keyword (group by) and thus can't be used as a regular identifier.

You could use it by enclosing it in double quotes as "group" but I strongly recommend to use some other name.

  • Related