Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在 PostgreSQL 中创建某种函数或触发器来更新关于时间的列字段?
例如,今天我希望该字段等于 1,在 10 小时内我希望它等于 0。
这可能吗?
如果该值仅是时间的函数,则可以在查询时计算。这将始终为 0 或 1:
select (extract(hour from current_time) >= 12)::int * 1; ?column? ---------- 0
或添加到视图中:
create view v as select *, (extract(hour from current_time) >= 12)::int * 1 from t;