Postgresql 删除行直到定义了一个数字?
我的服务器给了我10000行的限制,我的想法是删除给定表中的所有旧行,并保留一定数量的行。 示例:表“posts”中有10000行,我希望命令删除所有最旧的me,直到5000行 更多信息:Postgresql 删除行直到定义了一个数字?,postgresql,numbers,delete-row,Postgresql,Numbers,Delete Row,我的服务器给了我10000行的限制,我的想法是删除给定表中的所有旧行,并保留一定数量的行。 示例:表“posts”中有10000行,我希望命令删除所有最旧的me,直到5000行 更多信息: create_table "posts", :force => true do |t| t.string "title" t.string "slug" t.string "link" t.datetime "pubdate" t.text "description" t
create_table "posts", :force => true do |t|
t.string "title"
t.string "slug"
t.string "link"
t.datetime "pubdate"
t.text "description"
t.integer "blog_id"
end
delete from posts where pubdate这假设pubdate决定什么是最古老的,什么是最新的谢谢!这项工作:从pubdate很高兴有帮助的帖子中删除:)您很可能希望在pubdate上有一个索引
delete from posts where pubdate <=
(select pubdate from posts order by pubdate desc limit 1 offset 5000)