-- 函数
-- generate_series(时间开始, 时间结束, 时间跨度)
--最近10年
SELECT TO_CHAR(generate_series(now(), now() - INTERVAL '9 YEAR', '-1 YEARS'), 'YYYY') "year";
--最近12个月
SELECT TO_CHAR(generate_series(now(), now() - INTERVAL '11 MONTH', '-1 months'), 'YYYY-MM') "month";
1、近七天
create_time BETWEEN current_date - INTERVAL '7 days' AND current_date
2、本周
create_time>= date_trunc('week', now()) AND create_time < date_trunc('week', now()) + INTERVAL '1 week';
3、本月
create_time >= date_trunc('month', current_date) AND create_time < date_trunc('month', current_date) + INTERVAL '1 month'
4、本年
EXTRACT(YEAR FROM create_time) = EXTRACT(YEAR FROM CURRENT_DATE)
*// PostgreSQL JDBC 驱动类*
String JDBC_DRIVER = "org.postgresql.Driver";
// 数据库的 URL,其中需要指定数据库名和要使用的模式*
String DB_URL = "jdbc:postgresql://hostname:port/database?currentSchema=schema_name";
// PostgreSQL数据库的用户名与密码*
String USER = "username";
String PASS = "password";