VALUES Statement - IBM DB2 to PostgreSQL Migration

In DB2 you can use the VALUES statement to return one or more rows with one or more columns. In PostgreSQL you can use multiple SELECT statements with UNION ALL operator.

DB2:

  -- Return 3 rows with 1 column in each row
  VALUES 1, 2, 3;

PostgreSQL:

  -- Return 3 rows with 1 column in each row
  SELECT 1
  UNION ALL
  SELECT 2
  UNION ALL
  SELECT 3;

Both queries produce the same result:

1
2
3

One more example with multiple columns now:

DB2:

  -- Return 3 rows with 2 columns in each row
  VALUES (1, 'A'), (2, 'B'), (3, 'C');

PostgreSQL:

  -- Return 3 rows with 2 columns in each row
  SELECT 1, 'A'
  UNION ALL
  SELECT 2, 'B'
  UNION ALL
  SELECT 3, 'C';

Both queries produce the same result:

1 A
2 B
3 C

For more information, see IBM DB2 to PostgreSQL Migration.