Snowflake Data Unloading into Json Format

Pre-Requisites:

Snowflake account details

username

password

account name

Step-1:Create database and schema.

Syntax:

create or replace database DATA_UNLOADING;

USE DATABASE DATA_UNLOADING;

USE SCHEMA PUBLIC

Step-2 :creating table and insert the records into it as shown below:

Syntax:

create or replace table EMPLOYEE(Empid number,empname string,region string,contact string);

insert into employee values (1,'sai','EU','sai@123'),(2,'hiteesh','EU','hiteesh@123'),(3,'rishi','EU','rishi@123'),(4,'jaypal','EU','jaypal@123'),(5,'karthik','EU','karthik@123'),

(6,'easwar','EU','easwar@123'),(7,'yasin','EU','yasin@123'),(8,'bhanu','EU','bhanu@123'),(9,'praneeth','EU','praneeth@123'),(10,'sagar','EU','sagar@123'); 

Step-3:create a file format, which file format we want to load the data like csv,json ..etc...….....

Syntax:

create or replace  file format FILE_FORMAT_JSON

type='JSON';

Step-4:Create a Internal stage 

syntax:

create or replace stage my_internal_unload_stage

file_format =FILE_FORMAT_JSON;


Step-5:Retrieve the records by using select statement
Syntax:
select * from employee;



Step-6:Here we can perform copy command as shown below
Syntax:

copy into @my_internal_unload_stage
from (select object_construct('EMPID',Empid,'EmpName',empname,'Region',region,'Contact',contact) from Employee)
file_format = (type =json);
  

Note:object_construct:The object construct is inbuilt function of snowflake ,which is going to construct the relational data into snowflake and then export same data into the json file.



Step-7:Here we can get the file to downloaded our local machine as shown below
syntax:
get @my_internal_unload_stage/file://C:\Users\roopsaik\Desktop\dataunloading;


Step-8:Here I have to showcase the file where exactly place our local machine.




Step-9:Here is the output for json format ,which we unload the data into our local machine.



Conclusion: By Performing above Steps/Queries we can unload the data into Json Format.










Comments

Popular posts from this blog

Loading JSON data from Amazon S3 into Snowflake Using Copy Command