volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Postgres - reserved word not quoted #518

Closed ilk closed 5 years ago

ilk commented 5 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

sqlboiler version: v3.2.0 Database: postgres

Issue is that this queryMod produces a query where the column group ("group" is a reserved word in postgres) is not in double quotes

mods := []qm.QueryMod{
  qm.InnerJoin(models.TableNames.Providers + " p on p." + models.ProviderColumns.ID + ` = "` + models.TableNames.References + `".` + models.ReferenceColumns.ProviderID),
  models.ProviderWhere.GroupID.EQ("group"),
}

If this happened at runtime what code produced the issue?

SELECT COUNT(*) 
FROM "references" 
INNER JOIN providers p on p.id = "references".provider 
WHERE (group = $1);

Further information. What did you do, what did you expect?

SELECT COUNT(*) 
FROM "references" 
INNER JOIN providers p on p.id = "references".provider 
WHERE ("group" = $1);

Is there something I can do or is this an issue with the "ProviderWhere"?

aarondl commented 5 years ago

This makes sense. There's no quoting currently, will have to fix this: https://github.com/volatiletech/sqlboiler/blob/dev/queries/qmhelper/qmhelper.go#L78-L84

Ideally it'd be using the quoting that normal where queries do.