How to return the records of the last 7 days counting the current day with postgreSQL?

1

I am doing a search in the database where I want to return the records of the last seven days. I made a SQL script that returns me the records of the last 7 days but it does not count the current day as being the first day of the 7. For example if I add a new item in the table with today's date and execute the script it just goes show me this new record when it is completed one day. Here's the script:

SELECT * FROM postagem_pagina WHERE postagem_pagina.data_postagem BETWEEN CURRENT DATE - 7 AND CURRENT DATE
    
asked by anonymous 03.11.2015 / 17:37

1 answer

5

If you do not need to enter a time limit, you can search for anything later than the current day -7

select * from postagem_pagina where data_postagem > current_date - interval '7 days'
    
03.11.2015 / 17:40