0% found this document useful (0 votes)
262 views2 pages

SnowSQL Script

1. The document outlines steps for querying data from Snowflake using SnowSQL including connecting, setting the warehouse, database and role, inserting sample data, using variables for filtering queries, and outputting results to files. 2. Sample queries are run on a BUSINESSES table to filter by city variable and output the first 5 rows to text and CSV files. 3. The script connects to Snowflake, creates a BUSINESSES table, inserts sample data, runs queries with and without variable substitution, and checks session queries and results.

Uploaded by

Ajay Kumar Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
262 views2 pages

SnowSQL Script

1. The document outlines steps for querying data from Snowflake using SnowSQL including connecting, setting the warehouse, database and role, inserting sample data, using variables for filtering queries, and outputting results to files. 2. Sample queries are run on a BUSINESSES table to filter by city variable and output the first 5 rows to text and CSV files. 3. The script connects to Snowflake, creates a BUSINESSES table, inserts sample data, runs queries with and without variable substitution, and checks session queries and results.

Uploaded by

Ajay Kumar Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Steps:

1. how to connect to snowflake using snowsql


2. use snowsql -a -u
OR
2. open config file and set the parameters for default settings
3. set the context: WH, DB, Role
4. query tables
5. Variables - !set variable_subtitution=true;
6. query with variables
7. IO through SnowSQL
!spool - !spool off.

--------------------------Script:------------------------------
use warehouse instructor_wh;

use database instructor_db;

select current_role();
show databases;

create or replace TABLE BUSINESSES (


BUSINESS_ID VARCHAR(100),
NAME VARCHAR(100),
CITY VARCHAR(50),
STATE VARCHAR(2),
REVIEW_COUNT NUMBER(38,4),
STARS NUMBER(38,4)
);

INSERT INTO BUSINESSES VALUES


('QNcv3mwnHJ5w4YB4giqkWw','Preferred Veterinary Care','Pittsburgh','PA',4,3.5),
('oZG8sxDL54ki9pmDfyL7rA','Not My Dog','Toronto','ON',9,3.5),
('S06JfRM3ICESOHc1pr3LOA','Chase Bank','Las Vegas','NV',3,5.0),
('NL_BfZ4BkQXJSYAFouJqsQ','24 hr lockouts','Las Vegas','NV',3,1.0),
('AnUyv2zHq_35gCeHr8555w','Soma Restaurant','Las Vegas','NV',12,3.0),
('jjBTBObnHrY87qQIMybjzQ','Blue Jade','Cleveland','OH',24,3.5),
('PhL85G9Y6OstQzThDIllMQ','Animalerie Little Bear','Westmount','QC',9,4.0),
('SkRqx-hxVPLgV4K5hxNa9g','Parkview Dental Associates','Sun Prairie','WI',4,3.0),
('tWX7j4Qg4cXofQqmoNKH3A','Sir Hobbs','Sun Prairie','WI',35,3.0),
('4a9Rypytzdz9NZuGMS2ZYw','Rogue Bar','Scottsdale','AZ',80,3.5),
('oYWy-hOTCOF7h8DCAZ_Mxw','Cool Girl','Toronto','ON',48,3.5),
('AMxxi7jyxhcdNF7FIRbUVA','Remington''s Restaurant','Scottsdale','AZ',103,3.0),
('d01d-w7pxHrMCX5mDwaaHQ','D Liche','Montréal','QC',89,4.5),
('66DKb6APF96InEKrUVIbZw','Allo Inde','Montréal','QC',3,3.5);

!define cityName='Las Vegas'


!set variable_substitution=true
select * from businesses where city='&cityName';

!set variable_substitution=false
select * from businesses where city='&cityName';

!define partialName='Las '


!set variable_substitution=true
select * from businesses where city='&{partialName}Vegas';

-- Get the list of all variables


!variables

!spool .\.snowsql\results.txt
select * from businesses limit 5;
!spool off

!set output_format=csv
!set header=false
!set timing=false
!spool .\.snowsql\results.csv
select * from businesses limit 5;
!spool off

!queries session
!result <query_id>

!quit

You might also like