5 ms·
One of the coolest things about Postgres is how easy it is to make your own datatypes[1]. At previous jobs we've had custom types and aggregates that allowed su
by zrail 13y ago
One of the coolest things about Postgres is how easy it is to make your own datatypes[1]. At previous jobs we've had custom types and aggregates that allowed super fact set operations with comparatively small data storage requirements.
[1]: http://www.postgresql.org/docs/9.3/static/sql-createtype.html http://www.postgresql.org/docs/9.3/static/sql-createtype.htm...
- callesgg 13y agoJup I recommend creating [Postgres domains] for everything that is not specifically already a Postgres type. Want to store an order id create a OrderId domain. Want to store weight create a gram domain. Want to store quantity create a quantity domain. That way it becomes much more easy to spot logical errors and maintain data consistency. Also one can use it to create something like an auto ORM. [A domain Is like a user defined child type of the system types that can have some extra restrictions.]
- NoMoreNicksLeft 13y agoThey already have a quantity domain... it's called "integer". While I agree that domains are important and should be utilized, I hope your examples are exaggerations.
- ericcholis 13y agoI love the idea of domains, but quantity does seem to be a poor use case.
- joevandyk 13y agoYou could use use a domain to ensure a quantity can't be less than zero.
- NoMoreNicksLeft 12y agoThis is also called "unsigned int". Postgres has those.
- callesgg 13y agoI guess quantity was a poor example but I would disagree about it being the same as integer. And integer is a hole number. Nothing else can be inferred from knowing that something is a integer.
- Jweb_Guru 13y agoOne of the little-noticed (yet) features of the upcoming 9.4 release greatly increases the ability to optimize moving aggregates for certain types of numerical operations, including custom aggregates. See http://www.depesz.com/2014/04/13/waiting-for-9-4-provide-moving-aggregate-support-for-a-bunch-of-aggregates/ http://www.depesz.com/2014/04/13/waiting-for-9-4-provide-mov... for a better explanation.