You can’t actually select from a table within a Redshift function. From the documentation:
SQL_clause
A SQL SELECT clause.
The SELECT clause can’t include any of the following types of clauses:
- FROM
- INTO
- WHERE
- GROUP BY
- ORDER BY
- LIMIT
Seriously… how useful is that?