在postgres数据库sequelize的raw query也是受时区影响的.
同样的语句,用sequelize直接执行某些跟时间相关的query和在数据库执行是不一样的.
语句如下:
update table_A set is_enable=1 where EXTRACT(hour from now())+(EXTRACT(MINUTE from now()))/60 >= start_t and EXTRACT(hour from now())+(EXTRACT(MINUTE from now()))/60 < end_t;
解决很简单,在配置里加timezone:"+8:00"即可
const client = new Sequelize(
current_config.database,
current_config.user,
current_config.password,
{
dialect: "postgres",
host: current_config.host,
port: current_config.port,
operatorsAliases: operatorsAliases,
logging: true,
timezone: "+08:00"
}
);
很奇怪,因为在sequelize的github上,2016年的作者回复说postgres没有此类问题.