Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching from MySQL to PostgreSQL - tips, tricks and gotchas?

I am contemplating a switch from MySQL to PostgreSQL.

What are your tips, tricks and gotchas for working with PostgreSQL?

What should a MySQLer look out for?

See also: How different is PostgreSQL to MySQL?
See also: Migrate from MySQL to PostgreSQL

Note - I don't think this is a duplicate. In particular the type of answers are quite diffferent and the responses here have much more implementation detail, which is what I was looking for

like image 441
Toby Hede Avatar asked Apr 21 '09 11:04

Toby Hede


People also ask

Is PostgreSQL better then MySQL?

Postgres offers a wider variety of data types than MySQL. If your application deals with any of the unique data types it has available, or unstructured data, PostgreSQL may be a better pick. If you're using only basic character and numeric data types, both databases will suit you.

Is PostgreSQL harder to learn than MySQL?

PostgreSQL supports more advanced queries, it performs better on complicated queries, but is harder to manage. MySQL is fast, easy to manage, but you can run into it's limitations on advanced queries, stored procedures and the like.

Is MySQL or PostgreSQL easier?

In general, PostgreSQL is best suited for systems that require execution of complex queries, or data warehousing and data analysis. MySQL is the first choice for those web-based projects which require a database merely for data transactions and not anything intricate.


Video Answer


1 Answers

Just went through this myself, well I still am...

  • Case sensitive text
  • Lack of INSERT IGNORE and REPLACE
  • Explicit casting needed almost everywhere
  • No backticks
  • LOAD DATA INFILE (COPY is close, but not close enough)
  • Change autoincrement to SERIAL
  • Although bad form in MySQL, in Postgres, an INNER JOIN without an ON clause can't happen, use CROSS JOIN or the like
  • COUNT(*) can be crazy slow
  • Databases are encoded with character sets, not tables
  • You can have multiple databases, with multiple schemas (MySQL really has just one database and multiple schema)
  • Partitioning is different
  • MySQL interval vs. Postgres interval (for time intervals)
  • Implicit column renaming, Postgres requires AS
  • Cannot update multiple tables at the same time in Postgres
  • Postgres functions are powerful. So there is no CALL proc();; rewrite proc() as a function and SELECT proc();.
like image 104
rfusca Avatar answered Sep 19 '22 10:09

rfusca