Migrating SQL statements to PostgreSQL
When moving from a database to PostgreSQL, it makes sense to take a look and figure out which database engine provides which kind of functionality. Moving the data and the structure itself is usually fairly easy. However, rewriting SQL might not be. Therefore, I decided to include a section that explicitly focuses on various advanced features of SQL and their availability in today’s database engines.
Using LATERAL joins
In SQL, a LATERAL
join can basically be seen as some sort of loop. This allows us to parameterize a join and execute everything inside the LATERAL
clause more than once. Here is a simple example of this:
test=# SELECT * FROM generate_series(1, 4) AS x, LATERAL (SELECT array_agg(y) FROM generate_series(1, x) AS y ...