TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rarely Used Postgres Datatypes

129 pointsby narfzabout 11 years ago

16 comments

zrailabout 11 years ago
One of the coolest things about Postgres is how easy it is to make your <i>own</i> datatypes[1]. At previous jobs we&#x27;ve had custom types and aggregates that allowed super fact set operations with comparatively small data storage requirements.<p>[1]: <a href="http://www.postgresql.org/docs/9.3/static/sql-createtype.html" rel="nofollow">http:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.3&#x2F;static&#x2F;sql-createtype.htm...</a>
评论 #7714291 未加载
评论 #7714207 未加载
mahmudabout 11 years ago
If your ORM doesn&#x27;t let you take advantage of these goodies, maybe it&#x27;s time you went past ORM? Java&#x27;s JOOq library is stellar at this kind of raw SQL access stuff, while still being expressive and well-typed:<p><a href="http://www.jooq.org/" rel="nofollow">http:&#x2F;&#x2F;www.jooq.org&#x2F;</a>
评论 #7713414 未加载
wlievensabout 11 years ago
Let&#x27;s certainly not forget the awesome PostGIS extension with its spatial types and functions.
评论 #7713010 未加载
评论 #7713138 未加载
评论 #7715606 未加载
radiowaveabout 11 years ago
Hstore, and the supplied functions for converting to&#x2F;from records has been very useful for making a &quot;one size fits all&quot; history table.<p>Currently I&#x27;m working with numeric range types to model order quantities and stock quantities, and forecasting which order is going to consume what stock by joining on rows with overlapping ranges, then taking the intersections of those overlaps. Again, Postgres supplies functions and operators for range overlaps, intersections, etc.<p>In the absence of those datatypes, there&#x27;d be a lot more work required to achieve either of these.
apinsteinabout 11 years ago
The ltree module is really awesome. If you have to do any hierarchical stuff I feel it&#x27;s much better than nested set implementations. Great performance with gist indexes and high level operators for querying.
joevandykabout 11 years ago
The ip4&#x2F;ip4r data type is fantastic as well if you just need to store an ip address.<p>(<a href="https://github.com/RhodiumToad/ip4r-historical/blob/master/README.ip4r" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;RhodiumToad&#x2F;ip4r-historical&#x2F;blob&#x2F;master&#x2F;R...</a>)
评论 #7719108 未加载
评论 #7713438 未加载
yawboakyeabout 11 years ago
Why aren&#x27;t they getting a lot of use? Is it because they&#x27;re new or ORMs don&#x27;t have them yet? (Note: This might sound like a false dichotomy but these are the only 2 reasons I know so feel free to add more reasons.)
评论 #7713132 未加载
评论 #7713579 未加载
troykabout 11 years ago
I keep seeing the uuid idea for pkeys, but have yet to see them used by any big site. Last I looked, twitter, facebook are using bigints all over the place. Also, instagram went bigint and blogged about it here <a href="http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram" rel="nofollow">http:&#x2F;&#x2F;instagram-engineering.tumblr.com&#x2F;post&#x2F;10853187575&#x2F;sha...</a><p>Also, I tried the uuid extension once... It is not well supported, had to make a small change to a c header file to get it to compile on ubuntu, for dev on os x I think I gave up.
评论 #7714600 未加载
评论 #7714048 未加载
bwooceabout 11 years ago
the only bit I&#x27;d prefer clarification on is:<p><i>Timestamp with Timezone</i><p><i>There’s seldom a case you shouldn’t be using these.</i><p>For recording most event times that&#x27;s true but:<p>Birthdates (which can include times) shouldn&#x27;t use them.<p>Calendaring should think very carefully too, should the 9am meeting move to 10am due to DST? or should it &quot;stay put&quot; but potentially move for other timezones?
评论 #7713767 未加载
评论 #7713934 未加载
评论 #7713913 未加载
groupmuseabout 11 years ago
Kind of confused here: I was under the impression that timestamp with timezone only did the converting to-and-from your system timezone, but still always stored in UTC. Is that incorrect?
评论 #7714126 未加载
malkiaabout 11 years ago
I wish arrays and hstore-like types were available in sqlite (not through plugins, but standard-wise).<p>I&#x27;ve used something else from my experiments in PostgreSQL - the TXID - this way I was able to track down changes in the database (by keeping previous TXID and some other various bits, and then by polling again (or making the server call me)) - polling again and only instructing to get the rows that have changed since my last TXID.
Alex3917about 11 years ago
The array type is actually one of the most interesting, I&#x27;d love to see the performance implications of those specifically covered in more detail.
Ixiausabout 11 years ago
Postgres is a great database, I&#x27;m particularly in love with hstore for the data that it makes sense for.
dholowiskiabout 11 years ago
While I don&#x27;t disagree with the coolness of uuid, how exactly do you &#x27;run out of integers&#x27; ?
评论 #7713550 未加载
评论 #7714098 未加载
评论 #7713711 未加载
troykabout 11 years ago
I think the money type is awesome! Under the hood it uses int (I believe int32 even on 64bit) so it takes 50% less space than decimal.<p>So if your only dealing with US currency, why not love the money type?
评论 #7713920 未加载
评论 #7713931 未加载
评论 #7714173 未加载
frankpintoabout 11 years ago
Yes, amazing. About to work on stats caching and that Ranges datatype will be suuuper useful for using ranges of timestamps when caching a stat every week, month, etc.