TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

PostgreSQL – Don't Do This

75 点作者 lobo_tuerto将近 2 年前

4 条评论

thermin将近 2 年前
I&#x27;m baffled by the insistence that &quot;users&quot; (backend services, really) should avoid timestamp in favor of timestampz.<p>I literally DO NOT understand, how is this good advice.<p>My backend service exists in some abstraction of a Linux environment, with a fixed timezone, most commonly UTC. It maintains a pool of connections to Postgres, all sharing the same Postgres user, and the same timezone.<p>Why on earth would I prefer a timestampz to timestamp? Why would I even involve the server timezone into this equation?<p>I want to store timestamps in a uniform way, I store them in UTC as timestamps. If I stored them in a timestampz column, if the server timezone were to adjust, I&#x27;d get literally different values.<p>If I want to store timezone values per user (of my service), or per operation (that my users perform), then again, surely I have to handle that users move and change their timezones. Again, how does timestampz with its reliance on the connection timezone serve me?
评论 #36148057 未加载
评论 #36150186 未加载
评论 #36148895 未加载
评论 #36149165 未加载
评论 #36148161 未加载
评论 #36149063 未加载
Arch485将近 2 年前
Another &quot;valid&quot; use of `timestamp` as opposed to `timestamptz` is for local times that don&#x27;t all share the same time zone.<p>For example, if a user can create an event scheduled in their timezone, you probably would want to use a `timestamp` and not `timestamptz`. This way, if the user schedules the event for e.g. 5:00pm, and then the time zone changes (think DST or similar), the event is still at 5:00pm (it won&#x27;t get shifted like a `timestamptz` would).
评论 #36148048 未加载
评论 #36153669 未加载
pmontra将近 2 年前
My favorite section is <a href="https:&#x2F;&#x2F;wiki.postgresql.org&#x2F;wiki&#x2F;Don%27t_Do_This#Text_storage" rel="nofollow">https:&#x2F;&#x2F;wiki.postgresql.org&#x2F;wiki&#x2F;Don%27t_Do_This#Text_storag...</a> that is using text instead of char and varchar.<p>Of course the default of the PostgreSQL driver for several ORMs of several languages is varchar(255).
评论 #36162737 未加载
revskill将近 2 年前
No, i suggest reverse these kinds of advice and DO THIS instead.<p>Why ?<p>Because IF it&#x27;s said not to do this, it should not be implemented in first place.<p>This is a trap.<p>For example, &quot;Don&#x27;t use table inheritance&quot;, you should always use this to reuse the table definition. If not, what&#x27;s the alternative ?
评论 #36154816 未加载
评论 #36147910 未加载