DELETE FROM ...报告在或接近“。”的语法错误。 [英] DELETE FROM ... reporting syntax error at or near "."

查看:522
本文介绍了DELETE FROM ...报告在或接近“。”的语法错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的数据库只删除一个数据,但是,当我写的命令,我不断得到有一些语法错误,你能告诉我在哪里的错误吗?

I'm trying to delete just one data from my DB, but, when I write the command I keep getting that there's some syntax error, could you tell me where is the error?

这是我试过的命令:

DELETE FROM database_userprofile WHERE user.username = 'some';
ERROR:  syntax error at or near "."
LINE 1: DELETE FROM database_userprofile WHERE user.username = 'some'...

DELETE FROM database_userprofile USING database_user WHERE user.username="some";
ERROR:  syntax error at or near "."
LINE 1: ... database_userprofile USING database_user WHERE user.username=...

希望你能帮助我。

推荐答案

您的查询没有任何意义。

Your query doesn't make any sense.

DELETE FROM database_userprofile WHERE user.username = 'some';
                                       ^^^^

用户 c $ c>来自?它不在查询中引用。是 database_userprofile 的列吗?如果是这样,你不能写 user.username (除非是一个复合类型,在这种情况下你必须写(user).username

Where'd user come from? It isn't referenced in the query. Is it a column of database_userprofile? If so, you can't write user.username (unless it's a composite type, in which case you would have to write (user).username to tell the parser that; but I doubt it's a composite type).

直接的原因是 user 是一个保留字 。您不能使用该名称而不引用它:

The immediate cause is that user is a reserved word. You can't use that name without quoting it:

DELETE FROM database_userprofile WHERE "user".username = 'some';

...但是,这个查询还是没有意义,它会给出一个不同的错误:

... however, this query still makes no sense, it'll just give a different error:

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...

我的猜想是你试图做一个删除连接。我假设你有如下的表:

My wild guess is that you're trying to do a delete over a join. I'm assuming that you have tables like:

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
);

并且您尝试使用其他表格中的条件删除。

and you're trying to do delete with a condition across the other table.

如果是这样,您不能只写 user.username 。您必须使用:

If so, you can't just write user.username. You must use:

DELETE FROM database_userprofile
USING "user"
WHERE database_userprofile.user_id = "user".id
AND "user".username = 'fred';

你会注意到我双引号的user。这是因为它是一个关键字,不应真正用于表名或其他用户定义的标识符。双引号将它强制作为标识符而不是关键字。

You'll notice that I've double-quoted "user". That's because it's a keyword and shouldn't really be used for table names or other user defined identifiers. Double-quoting it forces it to be intepreted as an identifier not a keyword.

这篇关于DELETE FROM ...报告在或接近“。”的语法错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆