13

I have already tried the common PostgreSQL answer, but seems like it doesn't work with Redshift:

SELECT  * FROM VALUES (1) AS q (col1);

ERROR: 42883: function values(integer) does not exist

I need this because for some reason I can't use UNION ALL. Any help will be greatly appreciated.

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137
Inferno1892
  • 173
  • 1
  • 2
  • 9
  • 1
    Just ran into this myself. Here are the docs on which Postgres features are unsupported in Redshift: https://docs.aws.amazon.com/en_pv/redshift/latest/dg/c_unsupported-postgresql-features.html – stone Oct 07 '19 at 23:35

1 Answers1

29

The correct Postgres syntax would be:

SELECT * FROM (VALUES (1)) AS q (col1);

A set of parentheses was missing.
But it seems Redshift does not even support a VALUES expression outside of INSERT (like modern Postgres does). So, for a single row:

SELECT * FROM (SELECT 1) AS q (col1);

For multiple rows (without using UNION ALL like requested) you can use a temporary table. Note (per documentation):

A temporary table is automatically dropped at the end of the session in which it was created.

CREATE TEMP TABLE q(col1 int);
INSERT INTO q(col1)
VALUES (1), (2), (3);

SELECT  * FROM q;

If UNION ALL would be an option:

SELECT 1 AS col1
UNION ALL SELECT 2
UNION ALL SELECT 3;
Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137