Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web devs who have made the switch from MySQL, what postgresql features could you now not do without?

I'm contemplating the switch (mainly because of the more permissive license), and tend to hear a lot of Internet murmuring about how much better Postgres is than MySQL, but not many specifics. What do you do in Postgres that make you more productive, or you find elegant?

It doesn't have to be fancy, for example some of my favorite things about MySQL include

  • easy primary key incrementing with AUTOINCREMENT (having to write a generator for every table seems more of a pain than it should be for such a common requirement),
  • "LIMIT,OFFSET" statements (makes for easy pagination)
  • ON DUPLICATE KEY UPDATE (makes inserting/updating "many to many" tables quick and painless)
like image 582
Dylan Avatar asked Jun 04 '09 15:06

Dylan


2 Answers

PostgreSQL's most useful features (which MySQL lacks), in my opinion, are:

  • generate_series and set returning functions in general
  • ability to use correlated values in LIMIT and OFFSET clauses
  • Custom aggregates
  • DISTINCT ON clause
  • More advanced JOIN methods (MERGE JOIN and HASH JOIN)

You can do wonders with them.

PostgreSQL code also often looks more elegant (note that "looks" doesn't mean "performs"), since you can use nice casting syntax (::), nice RECORD types and these kinds of stuff.

Drawbacks are:

  • You cannot use hints (I know it's intentional; I know they should be avoided; go downvote me)
  • You cannot use session variables without access to server configuration files (you need to set custom_variable_classes)
  • DISTINCT and GROUP BY operations are laggy.

Since both these systems are quite powerful and well-developed, they differ mainly in such fancy features (that most developers never even use).

For basic SQL, they're both good.

like image 101
Quassnoi Avatar answered Oct 03 '22 04:10

Quassnoi


  • Transactional DDL - you can do "start transaction; delete table foo; rollback;" and foo will still be there.
like image 36
Tometzky Avatar answered Oct 03 '22 06:10

Tometzky