你的询问没有任何意义。
DELETE FROM database_userprofile WHERE user.username = 'some';
^^^^
Where'd user
来自?查询中未引用它。是一列吗database_userprofile
?如果是这样,你就不能写user.username
(除非它是复合类型,在这种情况下你必须写(user).username
告诉解析器;但我怀疑它是复合类型)。
直接原因是user is a 保留字 http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html。您不能在不引用该名称的情况下使用它:
DELETE FROM database_userprofile WHERE "user".username = 'some';
...但是,这个查询仍然没有意义,它只会给出不同的错误:
regress=> DELETE FROM database_userprofile WHERE "user".username = 'some';
ERROR: missing FROM-clause entry for table "user"
LINE 1: DELETE FROM database_userprofile WHERE "user".username = 'so...
我的疯狂猜测是您正在尝试通过连接进行删除。我假设你有这样的表:
CREATE TABLE "user" (
id serial primary key,
username text not null,
-- blah blah
);
CREATE TABLE database_userprofile (
user_id integer references "user"(id),
-- blah blah
);
并且您尝试在另一个表中使用条件进行删除。
如果是这样,你can't写吧user.username
。您必须使用:
DELETE FROM database_userprofile
USING "user"
WHERE database_userprofile.user_id = "user".id
AND "user".username = 'fred';
您会注意到我用双引号“用户”。这是因为它是一个关键字,不应该真正用于表名称或其他用户定义的标识符。双引号强制将其解释为标识符而不是关键字。