[ ] 常用操作示例
查询一段时间内的数据
SELECT count(1) FROM pictureWHERE create_date between (SELECT current_timestamp - interval '12 month')and current_timestamp;
按月统计
SELECT to_char(create_date, 'yyyy-MM') as month, count(*) FROM pictureWHERE create_date between (SELECT current_timestamp - interval '12 month') and current_timestampGROUP BY month;
函数
explain analyze \copy (select(random()::numeric(7,6)*1000000)::integer as user_id,round((random()*100)::numeric, 2) as pay_money,('2020-01-01'::date + (random()*364)::integer) as create_datefrom generate_series(1, 10000000)) to '/home/yanjing/database/pgsql/data.txt';INSERT INTO native_emp (level,postal_code,create_time) SELECT RANDOM()*6, (((RANDOM()::NUMERIC(5, 4))*10000)::INTEGER)::TEXT, gFROM generate_series('2020-01-01 00:00'::timestamp, NOW(), '15 seconds') as g;
