CROSS JOIN - SQL Server to PostgreSQL Migration

In SQL Server and PostgreSQL, the CROSS JOIN clause allows you to perform a cartesian product (cross-product) i.e. join each row from the first table with each row from the second table.

Consider a sample data:

  -- Sample tables
  CREATE TABLE colors (name VARCHAR(30));
  CREATE TABLE products (name VARCHAR(30));
 
  -- Sample rows
  INSERT INTO colors VALUES ('Green');
  INSERT INTO colors VALUES ('Red');
  INSERT INTO colors VALUES ('Yellow');
 
  INSERT INTO products VALUES ('Apple');
  INSERT INTO products VALUES ('Cherry');

SQL Server and PostgreSQL:

  -- Cartesian product of two tables
  SELECT c.name, p.name
  FROM colors c CROSS JOIN products p;

Result:

c.name p.name
Green Apple
Red Apple
Yellow Apple
Green Cherry
Red Cherry
Yellow Cherry

For more information, see SQL Server to PostgreSQL Migration.