Postgresql将属性混淆为表

时间:2014-10-30 16:04:55

标签: sql postgresql

我正在尝试使用属性名称中包含。(d0t)的属性,但似乎postgresql很困惑,并且认为我正在尝试访问表属性。

这是我正在尝试运行的SQL查询

select count(metadata.username), metadata.username from appointment join appointment_wrapper a on a.id=appointment_wrapper_id where property='state' and string_value='Kano' and timestamp > '2014-08-01' and timestamp < '2014-11-01' group by metadata.username;

当我运行该查询时,它说

ERROR:  missing FROM-clause entry for table "metadata"

当我添加引号时,它说

ERROR:  non-integer constant in GROUP BY

有关如何解决此问题的任何帮助?

谢谢

1 个答案:

答案 0 :(得分:3)

您正在寻找的是"quoted identifier",您可以通过将列名包含在 double 引号中来防止将其解释为关键字:

SELECT count("metadata.username") from app group by "metadata.username";

只是一个reminder,你真的,真的想避免在列或表名中保留字符带来的混淆。