Data Types and Functions in Snowflake
Jake Roach
Field Data Engineer
$$
Snowflake is used by more than 10,000 organizations globally
$$
Data Types
Manipulating Data
Advanced Techniques
Text data is one of the most popular data types in Snowflake
$$
-- Text data might be categorical 'Software Engineer'
-- Messages are also text data 'Hello, World!'
-- As well as phone numbers '931-663-0164'
-- And even things like this! 'Taylormade,Titleist,Ping'
CREATE TABLE TABLE_NAME (
message VARCHAR(100),
phone_number TEXT,
brands STRING
);
Define column with VARCHAR(...)
TEXT
STRING
message | phone_number | brands
--------------- | -------------- | ----------------------------
Hello, World! | 931-663-0164 | Taylormade, Titleist, Ping
Goodnight! | 617-256-3086 | Apple, Windows, Linux
Columns that store text data can look quite different!
DESCRIBE TABLE <SCHEMA>.<table_name>;
name
, type
, default
, ...$$
SELECT
<field>,
<another-field>,
-- Can be used in a SELECT
'<value>'
FROM SCHEMA.TABLE_NAME;
SELECT
*
FROM SCHEMA.TABLE_NAME
-- Can be used in a WHERE clause
WHERE FIELD = '<value>';
Text values can be used in different parts of a SQL query
SELECT
WHERE
CASE
$$
'...'
Single Quotes
Function | Description |
---|---|
LENGTH |
Find the number of characters in a text value. |
TRIM |
Remove a sequence of characters at the beginning or end of a string. |
RTRIM |
Same functionality as TRIM , only applied to right-side of the string. |
LTRIM |
Same functionality as TRIM , only applied to left-side of the string. |
SPLIT |
Split a string using some delimiter, like a comma. |
SEARCH |
Search a string for a certain value. |
CAST , :: |
Convert other data types into a VARCHAR data type. |
Data Types and Functions in Snowflake