Snowflake Connectivity¶
This page provides instructions on reading data from Snowflake and, when necessary, writing data back to Snowflake.
Syntax¶
CREATE [ OR REPLACE ] FOREIGN TABLE [schema_name].table_name (
{ column_def [, ...] }
)
[ FOREIGN DATA ] WRAPPER snowflake_fdw
[ OPTIONS ( option_def [, ... ] ) ]
option_def ::=
{
ACCOUNT_NAME = '<account_name>',
USERNAME = '<username>',
PASSWORD = '<password>',
SF_WAREHOUSE = '<warehouse_name>',
DATABASE = '<database_name>',
DB_TABLE = '<table_name>',
[ SCHEMA = '<schema_name>' ] /* Optional - will use default schema "public" if not specified. */
}
column_def ::=
{ column_name type_name [ default ] [ column_constraint ] }
column_constraint ::=
{ NOT NULL | NULL }
default ::=
DEFAULT default_value
| IDENTITY [ ( start_with [ , increment_by ] ) ]
schema_name ::= identifier
table_name ::= identifier
column_name ::= identifier
DROP TABLE [ IF EXISTS ] [schema_name.]table_name
schema_name ::= identifier
table_name ::= identifier
COPY { [schema_name].table_name [ ( column_name [, ... ] ) ] | query } TO
[FOREIGN DATA] WRAPPER
snowflake_fdw
OPTIONS
(
[ copy_to_option [, ...] ]
)
copy_to_option ::=
{
ACCOUNT_NAME = '<account name>',
USERNAME = '<username>',
PASSWORD = '<password>',
SF_WAREHOUSE = '<warehouse_name>',
DATABASE = '<database_name>',
DB_TABLE = '<table_name>',
NEW_TABLE = <TRUE | FALSE>,
[ SCHEMA = '<schema_name>' ] /* Optional - will use default schema "public" if not specified. */
}
column_name ::= identifier
schema_name ::= identifier
table_name ::= identifier
COPY
[ "<schema_name>". ]"<table_name>" [ (<column_name>) [ ,...] ]
FROM
[FOREIGN DATA] WRAPPER
<fdw_name>
OPTIONS
(
ACCOUNT_NAME = '<account name>',
USERNAME = '<username>',
PASSWORD = '<password>',
SF_WAREHOUSE = '<warehouse_name>',
SCHEMA = '<schema_name>',
DATABASE = '<database_name>',
DB_TABLE = '<table_name>'
);
Parameters¶
Parameter |
Description |
---|---|
|
The name of the Snowflake schema where the table to be imported is located |
|
The name of the Snowflake table you wish to import |
|
Snowflake account name |
|
Snowflake username |
|
Snowflake password |
|
The name of the Snowflake warehouse where the table to be imported is located |
|
The name of the Snowflake database where the table to be imported is located |
|
The name of the Snowflake schema where the table to be imported is located |
|
The name of the Snowflake table to be imported |
|
The name of the columns in the Snowflake table to be imported |
|
The column data type in the Snowflake table to be imported |
|
Specifies whether or not the |
Usage Notes¶
Data Types Mapping¶
The following Snowflake data types are not supported: BYTEINT
, BINARY
, VARBINARY
, TIMESTAMP
, TIME
, TIMESTAMP_LTZ
, TIMESTAMP_TZ
, VARIANT
, OBJECT
, GEOGRAPHY
, GEOMETRY
SQream Blue Data Type |
Snowflake Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples¶
Creating a Table¶
CREATE OR REPLACE FOREIGN TABLE snowflake_table
(
id BIGINT,
address TEXT,
purchase DOUBLE
)
WRAPPER snowflake_fdw
OPTIONS
(
ACCOUNT_NAME = 'my sf account',
DB_TABLE = 'my_customers',
USERNAME = 'JohnSmith',
PASSWORD = 'pa$$w0rD',
DATABASE = 'master',
SCHEMA = 'public',
SF_WAREHOUSE = 'my_sf_warehouse'
);
Joining Blue and Snowflake Tables¶
SELECT
*
FROM
snowflake_table sft
JOIN table1 t1 ON sft.id = t1.id
WHERE
sft.date >= '2022-01-01'
AND t1.status = 'active';
Copying Data Into a Snowflake Table¶
COPY
t TO
WRAPPER
snowflake_fdw
OPTIONS
(
ACCOUNT_NAME = 'my sf account',
DB_TABLE = 'my_customers',
USERNAME = 'JohnSmith',
PASSWORD = 'pa$$w0rD',
DATABASE = 'master',
SCHEMA = 'public',
SF_WAREHOUSE = 'my_sf_warehouse',
NEW_TABLE = TRUE
);
Copying Data Into a Blue Table¶
COPY
customers
FROM
WRAPPER
snowflake_fdw
OPTIONS
(
ACCOUNT_NAME = 'my sf account',
USERNAME = 'JohnSmith',
PASSWORD = 'pa$$w0rD',
SF_WAREHOUSE = 'my_sf_warehouse',
SCHEMA = 'public',
DATABASE = 'master',
DB_TABLE = 'my_customers'
);