PostgreSQL删除声明

时间:2015-02-24 20:11:36

标签: sql postgresql

表1:书虫数据库的模式。主键带下划线。有一些外键引用将表连接在一起;你可以利用天然连接来利用它们。

Author(aid, alastname, afirstname, acountry, aborn, adied).
Book(bid, btitle, pid, bdate, bpages, bprice).
City(cid, cname, cstate, ccountry).
Publisher(pid, pname).
Author_Book(aid, bid).
Publisher_City(pid, cid).

我一直试图删除1985年以后发布的所有图书,只删除了author_book和book表中的元组,只使用了两个删除语句。

到目前为止,我已经尝试过..

delete from book
where bdate > 1985;

给我语法:

ERROR:  update or delete on table "book" violates foreign key constraint 
"author_book_bid_fkey" on table "author_book"
DETAIL:  Key (bid)=(cltl) is still referenced from table "author_book".

和...

delete from author_book
where bid > 1985;

使用另一种语法:

ERROR:  operator does not exist: character > integer
LINE 2: where bid > 1985;
              ^
HINT:  No operator matches the given name and argument type(s). 
You might need to add explicit type casts.

我知道这比我想象的要容易,但是不能理解出了什么问题。期待听到您的意见。这仍然没有用,有人可以帮忙!

1 个答案:

答案 0 :(得分:1)

更改此

delete from book
where bdate = bdate > 1985;

delete from book
where bdate  > 1985;

它不起作用的原因是(bdate> 1985)返回一个布尔值 并将布尔值与smallint进行比较。删除需要一个真正的值来执行。类似于下一期