SnowConvert AI - Redshift - SELECT INTO¶
Description¶
Returns rows from tables, views, and user-defined functions and inserts them into a new table. (Redshift SQL Language Reference SELECT statement)
Grammar Syntax¶
For more information please refer to each of the following links:
FROM clause¶
Description¶
The
FROMclause in a query lists the table references (tables, views, and subqueries) that data is selected from. If multiple table references are listed, the tables must be joined, using appropriate syntax in either theFROMclause or theWHEREclause. If no join criteria are specified, the system processes the query as a cross-join. (Redshift SQL Language Reference FROM Clause)
Warning
The FROM clause is partially supported in Snowflake. Object unpivoting is not currently supported.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
EMPLOYEE_NAME |
DEPARTMENT_NAME |
|---|---|
John |
HR |
Jorge |
Sales |
Kwaku |
Sales |
Liu |
Sales |
Mateo |
Engineering |
Nikki |
Marketing |
Paulo |
Marketing |
Richard |
Marketing |
Sofía |
Engineering |
Output Code:¶
Redshift¶
Results¶
| EMPLOYEE_NAME | DEPARTMENT_NAME |
|---|---|
| John | HR |
| Jorge | Sales |
| Kwaku | Sales |
| Liu | Sales |
| Mateo | Engineering |
| Nikki | Marketing |
| Paulo | Marketing |
| Richard | Marketing |
| Sofía | Engineering |
Known Issues¶
There are no known issues.
GROUP BY clause¶
Description¶
The
GROUP BYclause identifies the grouping columns for the query. Grouping columns must be declared when the query computes aggregates with standard functions such asSUM,AVG, andCOUNT. (Redshift SQL Language Reference GROUP BY Clause)
Note
The GROUP BY clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
1 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
100 |
1 |
101 |
3 |
102 |
2 |
103 |
3 |
104 |
3 |
1 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
HAVING clause¶
Description¶
The
HAVINGclause applies a condition to the intermediate grouped result set that a query returns. (Redshift SQL Language Reference HAVING Clause)
Note
The HAVING clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
101 |
3 |
103 |
3 |
104 |
3 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
TOTAL_EMPLOYEES |
|---|---|
101 |
3 |
103 |
3 |
104 |
3 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
LIMIT and OFFSET clauses¶
Description¶
The LIMIT and OFFSET clauses retrieves and skips the number of rows specified in the number.
Note
The LIMIT and OFFSET clauses are fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
LIMIT number¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
100 |
Carlos |
120000.00 |
|
101 |
John |
100 |
90000.00 |
102 |
Jorge |
101 |
95000.00 |
103 |
Kwaku |
101 |
105000.00 |
104 |
Paulo |
102 |
110000.00 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
100 |
Carlos |
120000.00 |
|
101 |
John |
100 |
90000.00 |
102 |
Jorge |
101 |
95000.00 |
103 |
Kwaku |
101 |
105000.00 |
104 |
Paulo |
102 |
110000.00 |
LIMIT ALL¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
100 |
Carlos |
120000.00 |
|
101 |
John |
100 |
90000.00 |
102 |
Jorge |
101 |
95000.00 |
103 |
Kwaku |
101 |
105000.00 |
104 |
Paulo |
102 |
110000.00 |
105 |
Richard |
102 |
85000.00 |
106 |
Mateo |
103 |
95000.00 |
107 |
Liu |
103 |
108000.00 |
108 |
Zhang |
104 |
95000.00 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
100 |
Carlos |
120000.00 |
|
101 |
John |
100 |
90000.00 |
102 |
Jorge |
101 |
95000.00 |
103 |
Kwaku |
101 |
105000.00 |
104 |
Paulo |
102 |
110000.00 |
105 |
Richard |
102 |
85000.00 |
106 |
Mateo |
103 |
95000.00 |
107 |
Liu |
103 |
108000.00 |
108 |
Zhang |
104 |
95000.00 |
OFFSET without LIMIT¶
Snowflake doesn’t support OFFSET without LIMIT. The LIMIT is added after transformation with NULL, which is the default LIMIT.
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
105 |
Richard |
102 |
85000.00 |
106 |
Mateo |
103 |
95000.00 |
107 |
Liu |
103 |
108000.00 |
108 |
Zhang |
104 |
95000.00 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
105 |
Richard |
102 |
85000.00 |
106 |
Mateo |
103 |
95000.00 |
107 |
Liu |
103 |
108000.00 |
108 |
Zhang |
104 |
95000.00 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
Local Variables and Parameters¶
Description¶
Redshift also allows SELECT INTO variables when the statement is executed inside stored procedures.
Note
This pattern is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
SELECT INTO with expressions at the left¶
Input Code:¶
Redshift¶
Results¶
param1 |
|---|
10 |
Output Code:¶
Snowflake¶
Results¶
TEST_SP1 |
|---|
{ “param1”: 10 } |
SELECT INTO with expressions at the right¶
Input Code:¶
Redshift¶
Results¶
param1 |
|---|
10 |
Output Code:¶
Since Snowflake doesn’t support this grammar for SELECT INTO, the expressions are moved to the left of the INTO.
Snowflake¶
Results¶
TEST_SP1 |
|---|
{ “param1”: 10 } |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
ORDER BY clause¶
Description¶
The
ORDER BYclause sorts the result set of a query. (Redshift SQL Language Reference Order By Clause)
Note
The ORDER BY clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
107 |
Liu |
103 |
108000.00 |
103 |
Kwaku |
101 |
105000.00 |
102 |
Jorge |
101 |
95000.00 |
106 |
Mateo |
103 |
95000.00 |
108 |
Zhang |
104 |
95000.00 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
SALARY |
|---|---|---|---|
107 |
Liu |
103 |
108000.00 |
103 |
Kwaku |
101 |
105000.00 |
102 |
Jorge |
101 |
95000.00 |
106 |
Mateo |
103 |
95000.00 |
108 |
Zhang |
104 |
95000.00 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
SELECT list¶
Description¶
The SELECT list names the columns, functions, and expressions that you want the query to return. The list represents the output of the query. (Redshift SQL Language Reference SELECT list)
Note
The query start options are fully supported in Snowflake. Just keep in mind that in Snowflake the DISTINCT and ALL options must go at the beginning of the query.
Note
In Redshift, if your application allows foreign keys or invalid primary keys, it can cause queries to return incorrect results. For example, a SELECT DISTINCT query could return duplicate rows if the primary key column does not contain all unique values. (Redshift SQL Language Reference SELECT list)
Grammar Syntax¶
Sample Source Patterns¶
Top clause¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
100 |
Carlos |
null |
101 |
John |
100 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
100 |
Carlos |
null |
101 |
John |
100 |
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
ALL¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
101 |
101 |
102 |
103 |
103 |
103 |
104 |
104 |
102 |
104 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
101 |
101 |
102 |
103 |
103 |
103 |
104 |
104 |
102 |
104 |
DISTINCT¶
Input Code:¶
Redshift¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
102 |
103 |
104 |
Output Code:¶
Snowflake¶
Results¶
MANAGER_ID |
|---|
null |
100 |
101 |
102 |
103 |
104 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
UNION, INTERSECT, and EXCEPT¶
Description¶
The
UNION,INTERSECT, andEXCEPTset operators are used to compare and merge the results of two separate query expressions. (Redshift SQL Language Reference Set Operators)
Note
Set operators are fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
103 |
Kwaku |
101 |
110 |
Liu |
101 |
102 |
Jorge |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
102 |
Jorge |
101 |
103 |
Kwaku |
101 |
110 |
Liu |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
WHERE clause¶
Description¶
The
WHEREclause contains conditions that either join tables or apply predicates to columns in tables. (Redshift SQL Language Reference WHERE Clause)
Note
The WHERE clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
102 |
Jorge |
101 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
102 |
Jorge |
101 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
WITH clause¶
Description¶
A
WITHclause is an optional clause that precedes the SELECT INTO in a query. TheWITHclause defines one or more common_table_expressions. Each common table expression (CTE) defines a temporary table, which is similar to a view definition. You can reference these temporary tables in theFROMclause. (Redshift SQL Language Reference WITH Clause)
Note
The WITH clause is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Non-Recursive form¶
Input Code:¶
Redshift¶
Results¶
ORDER_ID |
CUSTOMER_ID |
ORDER_DATE |
TOTAL_AMOUNT |
|---|---|---|---|
2 |
102 |
2024-02-02 |
600.00 |
4 |
104 |
2024-02-04 |
750.00 |
5 |
105 |
2024-02-05 |
900.00 |
Output Code:¶
Snowflake¶
Results¶
ORDER_ID |
CUSTOMER_ID |
ORDER_DATE |
TOTAL_AMOUNT |
|---|---|---|---|
2 |
102 |
2024-02-02 |
600.00 |
4 |
104 |
2024-02-04 |
750.00 |
5 |
105 |
2024-02-05 |
900.00 |
Recursive form¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
103 |
Kwaku |
101 |
102 |
Jorge |
101 |
110 |
Liu |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
105 |
Richard |
103 |
110 |
Nikki |
103 |
104 |
Paulo |
103 |
120 |
Saanvi |
104 |
200 |
Shirley |
104 |
205 |
Zhang |
104 |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
MANAGER_ID |
|---|---|---|
101 |
John |
100 |
103 |
Kwaku |
101 |
102 |
Jorge |
101 |
110 |
Liu |
101 |
106 |
Mateo |
102 |
201 |
Sofía |
102 |
105 |
Richard |
103 |
110 |
Nikki |
103 |
104 |
Paulo |
103 |
120 |
Saanvi |
104 |
200 |
Shirley |
104 |
205 |
Zhang |
104 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.