<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amulya Kumar panda on Medium]]></title>
        <description><![CDATA[Stories by Amulya Kumar panda on Medium]]></description>
        <link>https://medium.com/@amulyapanda?source=rss-fe4a78246bee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f08wCSPK0SY5VgPKM0pQ3w.jpeg</url>
            <title>Stories by Amulya Kumar panda on Medium</title>
            <link>https://medium.com/@amulyapanda?source=rss-fe4a78246bee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:05:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amulyapanda/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Some Easy approaches to removing duplicate records from a table in Snowflake?]]></title>
            <link>https://medium.com/@amulyapanda/some-easy-approaches-to-removing-duplicate-records-from-a-table-in-snowflake-53059ff00d6a?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/53059ff00d6a</guid>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 07:05:40 GMT</pubDate>
            <atom:updated>2024-06-22T07:09:37.340Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UrJ1ZuypAYzKL_bdke6Lvw.png" /></figure><p>We are encountering a significant challenge in managing duplicate records in our Snowflake table, especially when dealing with high data volume and sensitive production data.</p><p>Again, we have a challenge with data movement because we extract distinct records from the source table, store them in another temporary table, delete the original table records, and then copy from the temporary table.</p><p>This snowflake function has an overwrite feature; we don’t need to create an extra table or perform any data movement.</p><blockquote>OVERWRITE<br>Specifies that the target table should be truncated before inserting the values into the table. Note that specifying this option does not affect the access control privileges on the table.<br>To use the OVERWRITE option on INSERT, you must use a role that has DELETE privilege on the table because OVERWRITE will delete the existing records in the table.</blockquote><p>For this demo, I have created a Snowflake table with some sample records to demonstrate how it works.</p><p>Here are the details to create a student table with some sample data:</p><p><em>CREATE OR REPLACE TABLE STUDENT (<br>STUDENT_ID NUMBER(6,0),<br>FIRST_NAME VARCHAR2(20),<br>LAST_NAME VARCHAR2(20),<br>AGE NUMBER(3,0),<br>ADDRESS VARCHAR2(100),<br>PHONE_NUMBER VARCHAR2(20),<br>GRADE VARCHAR2(10)<br>);</em></p><p>INSERT INTO STUDENT(STUDENT_ID, FIRST_NAME, LAST_NAME, AGE, ADDRESS, PHONE_NUMBER, GRADE) VALUES<br>(1, ‘Amulya’, ‘Panda’, 18, ‘Anantapur, City’, ‘123–456–7777’, ‘C’),<br>(1, ‘Amulya’, ‘Panda’, 18, ‘Anantapur, City’, ‘123–456–7777’, ‘C’),<br>(2, ‘Namita’, ‘Panda’, 17, ‘Soro, Town’, ‘987–654–5555’, ‘B’),<br>(2, ‘Namita’, ‘Panda’, 17, ‘Soro, Town’, ‘987–654–5555’, ‘B’),<br>(2, ‘Namita’, ‘Panda’, 17, ‘Soro, Town’, ‘987–654–5555’, ‘B’),<br>(3, ‘Tukulu’, ‘Panda’, 16, ‘Bls, Village’, ‘456–123–9999’, ‘A’),<br>(3, ‘Tukulu’, ‘Panda’, 16, ‘Bls, Village’, ‘456–123–9999’, ‘A’),<br>(4, ‘Amar’, ‘Panda’, 18, ‘Kup, County’, ‘789–123–4444’, ‘A’);</p><p>Duplicate Data in this table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M2TFjnmQIUmFiU5LdKidHw.png" /></figure><p>INSERT OVERWRITE INTO STUDENT SELECT<br> STUDENT_ID,FIRST_NAME,LAST_NAME,AGE,ADDRESS,PHONE_NUMBER,GRADE<br>FROM (<br> SELECT<br> STUDENT_ID,<br> FIRST_NAME,<br> LAST_NAME,<br> AGE,<br> ADDRESS,<br> PHONE_NUMBER,<br> GRADE,<br> ROW_NUMBER() OVER (PARTITION BY STUDENT_ID, FIRST_NAME, LAST_NAME, AGE, ADDRESS, PHONE_NUMBER, GRADE ORDER BY STUDENT_ID ) AS ROW_NUMBER<br> FROM STUDENT<br>) AS subquery<br>WHERE ROW_NUMBER = 1;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_nE-ogQ_ux1GJXOp_9Hlg.png" /></figure><p>Another below two approach is to use the DISTINCT function and group by all to remove duplicate records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYrySkh8FlrYc7oDSPvTzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7q_ZWzfLpXGK4v8Z2zAlRQ.png" /></figure><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><p>If you require a complete code, please send me a message and I will assist you. Let me know how I can be of help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53059ff00d6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load file in Snowflake using Jupyter Notebook.]]></title>
            <link>https://medium.com/@amulyapanda/load-file-in-snowflake-using-jupyter-notebook-c37796feb449?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/c37796feb449</guid>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 13:03:09 GMT</pubDate>
            <atom:updated>2024-04-02T13:03:09.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*FjczFAx2FqHAL--WCZm7KA.png" /><figcaption>Load file in Snowflake using Jupyter Notebook</figcaption></figure><h4>How to connect snowflake to Jupyter notebook ?</h4><p>For this we need to first install panda, python and snowflake in your machine, after that we need import below three command in jupyter notebook.</p><ol><li>import pandas as pd</li><li>import snowflake.connector</li><li>from snowflake.connector.pandas_tools import write_pandas</li></ol><h4>We need passed snowflake connection details.</h4><p>cnn = snowflake.connector.connect(user=’*******’,</p><p>password=’**********’,</p><p>account=’rj73271.ap-south-1&#39;,</p><p>WAREHOUSE=’compute_wh’,</p><p>DATABASE=’DEMO_DB’,</p><p>SCHEMA=’PUBLIC’,</p><p>STAGE=’data_stage’)</p><p><em>Note:- Change user, password, account, warehouse,schema, stage as per your requirement</em></p><p>Now I have passed the local file path with a file name</p><p>df=pd.read_csv(‘C:/Users/USER/OneDrive/Documents/Book1.csv’, sep=’,’, header=0, index_col=False)</p><p>###Change file path and file name as per your requirement</p><p>#<a href="https://www.linkedin.com/feed/hashtag/?keywords=use">hashtag#Use</a> below command:-</p><p>df.reset_index(drop=True, inplace=True)</p><p>cs=cnn.cursor()</p><p>cs.execute(‘use database demo_db’)</p><p>cs.execute(‘use schema public’)</p><p>cs.execute(‘delete from comment_data’)</p><p>success, nchunks, nrows, _ = write_pandas(cnn, df, ‘comment_data’,quote_identifiers=False)</p><p>print(str(success) + ‘,’ +str(nchunks) + ‘,’ +str(nrows))</p><blockquote>How to read data from Snowflake using the fetch pandas all function?</blockquote><p>cs=cnn.cursor()</p><p>sql=’select * from demo_db.public.comment_data’</p><p>cs.execute(sql)</p><p>df=cs.fetch_pandas_all()</p><p>cs.close()</p><p>cnn.close()</p><p>df</p><p>Try the above code and solve your data load issue in snowflake, if you are facing any issues please let me know………………….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c37796feb449" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing complex hierarchies and relationships can be challenging, but Snowflake makes using…]]></title>
            <link>https://medium.com/@amulyapanda/managing-complex-hierarchies-and-relationships-can-be-challenging-but-snowflake-makes-using-ce507b011541?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce507b011541</guid>
            <category><![CDATA[connect-by]]></category>
            <category><![CDATA[snowsql]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[cloud-data-warehouse]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 15:48:28 GMT</pubDate>
            <atom:updated>2024-01-07T15:48:28.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bFVpo74XAFnIZWWjoPABZw.png" /></figure><p><strong>Managing complex hierarchies and relationships can be challenging, but Snowflake makes using CONNECT BY incredibly easy.</strong></p><p>Joins a table to itself to process hierarchical data in the table. The CONNECT BY subclause of the FROM clause iterates to process the data.</p><p>If we planned to implement complex hierarchies or relationships, then we would be writing multiple CTEs with complex logic. But Snowflake connects by easy for doing the same task.</p><p><strong>CONNECT BY Usage Notes:</strong></p><p>A CONNECT BY clause always joins a table to itself, not to another table.<br>Some variations within the projection clause are valid. Although the syntax shows level_expression occurring after the column_list, the level expression(s) can occur in any order.<br>The keyword PRIOR should occur exactly once in each CONNECT BY expression. PRIOR can occur on either the left-hand side or the right-hand side of the expression, but not on both.<br><strong>A query with CONNECT BY may also contain one or both of the following:</strong><br>Filters in a WHERE clause.<br>JOINs (which may be in either a FROM clause or a WHERE clause).<br><strong>The order of evaluation is:</strong><br>&gt;JOINs (regardless of whether specified in the WHERE clause or the FROM clause). &gt;Connect by. &gt;Filter (other than Join filters)<br>Snowflake supports the function SYS_CONNECT_BY_PATH when used with the CONNECT BY clause. SYS_CONNECT_BY_PATH returns a string that contains the path from the root to the current element.<br>Snowflake supports the CONNECT_BY_ROOT operator when used with the CONNECT BY clause. The CONNECT_BY_ROOT operator allows the current level to use information from the root level of the hierarchy, even if the root level is not the immediate parent of the current level.</p><p>More Details Please visit: <a href="https://docs.snowflake.com/en/sql-reference/constructs/connect-by">https://docs.snowflake.com/en/sql-reference/constructs/connect-by</a></p><p>I have inserted some records for the demo. Please take note of this information. Created one table of employees and inserted some records. Please find below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hq6nvQMd-YdZPmTdtPwkTg.png" /></figure><p>After that trigger the query using <em>START WITH title = ‘President’ and connect with </em>employee_id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qQaeTdmHMRAFZhQ8sSXTA.png" /></figure><p>This example uses the SYS_CONNECT_BY_PATH function to show the hierarchy from the President down to the current employee:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l7jW8l6_zHo5rcqPRz2utw.png" /></figure><p>This example uses the CONNECT_BY_ROOT keyword to display information from the top of the hierarchy in each row of output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XTb7OAzrR41DpcWC2e0Gw.png" /></figure><p>The Snowflake implementation of CONNECT BY is mostly compatible with the Oracle implementation; however, <em>Snowflake does not support</em>:<br>1-NOCYCLE<br>2-CONNECT_BY_ISCYCLE<br>3-CONNECT_BY_ISLEAF</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce507b011541" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Task scheduling and triggered tasks both perform the same function in Snowflake, but task…]]></title>
            <link>https://blog.devgenius.io/task-scheduling-and-triggered-tasks-both-perform-the-same-function-in-snowflake-but-task-b709929e97f2?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/b709929e97f2</guid>
            <category><![CDATA[triggered-tasks]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[snowflake-data-cloud]]></category>
            <category><![CDATA[snowflake-tasks]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 18:03:24 GMT</pubDate>
            <atom:updated>2024-01-05T18:20:43.797Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTtx9w_-PiXgbL8HQMiYrA.png" /></figure><h4>Task scheduling and triggered tasks both perform the same function in Snowflake, but task scheduling can be more resource-intensive and costly.</h4><p>Triggered tasks execute when a stream has data. They were originally set to run every minute with SCHEDULE=’1 minute’ and WHEN system$stream_has_data(‘my_stream_name’).</p><p>Scheduling tasks in this way often results in tasks running constantly, even when performing no work.</p><p>Triggered tasks eliminate the need to schedule tasks to run constantly.</p><p>To create a triggered task, omit the SCHEDULE parameter from the task as shown:</p><blockquote><strong>Support for this feature is currently not in production and is available only to selected accounts.</strong></blockquote><pre>CREATE TASK triggeredTask WAREHOUSE = my_warehouse<br> WHEN system$stream_has_data(‘my_stream’)<br> AS<br> INSERT INTO my_downstream_table<br> SELECT * FROM my_stream;</pre><h4>Triggered tasks:</h4><p>Only execute the associated stream when changes are made to the table, and run the stream shortly after the data change is committed (usually within a few seconds).</p><h4>Benefits of Triggered Tasks:</h4><p>Task execution is made simple and automatic through data change triggers. Tasks are triggered automatically when data is available in the stream, eliminating the need for schedules. This approach reduces cloud service charges and load, freeing up resources for other tasks that perform useful work instead of simply polling for work.</p><p>Faster triggered tasks can execute every 15 seconds by modifying the USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS parameter. By default, triggered tasks execute at most every 30 seconds.</p><ul><li>Once when the task is first resumed, to consume any data already in the stream. For example, a stream created with the SHOW_INITIAL_ROWS = true.<br>• Once every 12 hours. if not previously triggered during that time period. If there is no data in the stream, the run will be skipped, and no compute resources will be used.</li></ul><h4>Differences between Triggered Tasks and Scheduled Tasks:</h4><p>Triggered task differ from scheduled tasks, in that scheduled tasks specify the SCHEDULE parameter. Triggered tasks generally behave the same way as scheduled tasks in most respects, with the following exceptions:</p><p>In SHOW TASKS / DESC TASK output, the SCHEDULE property displays NULL for triggered tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NkBAmU-wabFw9LLTTUW2Bw.png" /></figure><p>If the stream or table that the stream is tracking is dropped (including CREATE OR REPLACE, which drops it and creates a new one of the same name), the triggered task will no longer be able to trigger and will automatically suspend. Essentially the result is the same as if you ran ALTER TASK &lt;task_name&gt; SUSPEND. After the table and/or stream are re-created, the user can run ALTER TASK &lt;task_name&gt; RESUME to resume triggered processing.<br>WHEN conditions such as NOT stream_has_data(‘my_stream’) and stream_has_data(‘my_stream’) = false are not allowed; triggered tasks are only supported on data changing, and not data remaining the same.AND/OR conditions are allowed, such as stream_has_data(‘stream’) OR stream_has_data(‘stream2’) will trigger when either of the streams have data. This can result in a skipped task if an AND condition is used and only one of the streams has data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mS4UhoBWbC-tIk6GyEJgVA.png" /></figure><h4><strong>Please follow the steps below for the demo:</strong></h4><p><strong>Create a master table or target table:-</strong></p><p>CREATE OR REPLACE TABLE TASK_TRIGGER_MASTER_TABLE(ID INT,NAME VARCHAR,ADDRESS VARCHAR,DATA_ENTRY_TIME TIMESTAMP_NTZ)</p><p><strong>Create stage table or raw table:-</strong></p><p>create or replace TRANSIENT TABLE TASK_MASTER_STAGING (ID INT,NAME VARCHAR,ADDRESS VARCHAR,DATA_ENTRY_TIME TIMESTAMP_NTZ);</p><p><strong>Create stream on top of staging table/raw table:-</strong></p><p>create or replace stream TASK_MASTER_STREAM on table TASK_MASTER_STAGING append_only = true;</p><p><strong>First, create task with a schedule time:</strong></p><pre>CREATE or REPLACE TASK triggeredTask<br>SCHEDULE = ‘5 minute’<br>WAREHOUSE = compute_wh<br>WHEN system$stream_has_data(‘TASK_MASTER_STREAM’)<br>AS INSERT INTO TASK_TRIGGER_MASTER_TABLE SELECT * FROM TASK_MASTER_STAGING;</pre><p><strong>Check task was created or not:</strong></p><p>show tasks like ‘triggeredTask%’</p><p><strong>After that, if your task is resumed then suspend or directly trigger the second query:</strong></p><p>ALTER TASK triggeredTask SUSPEND;</p><p>ALTER TASK triggeredTask UNSET SCHEDULE;</p><p>ALTER TASK triggeredTask RESUME;</p><p><strong>After that insert the below query:</strong></p><p>INSERT INTO TASK_MASTER_STAGING VALUES(2,’Amulya’,’ANANTAPUR’,current_date())</p><p>Within 30 seconds data available in the master table:</p><p>select * from TASK_TRIGGER_MASTER_TABLE</p><p>select * from TASK_MASTER_STAGING</p><h4><strong>Triggered Task Limitations:</strong></h4><blockquote>Serverless tasks (tasks that don’t specify a WAREHOUSE) are not supported.<br>Streams on views, directory tables, and external tables are not supported.<br>Replication is not supported.</blockquote><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><p>If you require a complete code, please send me a message and I will assist you. Let me know how I can be of help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b709929e97f2" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/task-scheduling-and-triggered-tasks-both-perform-the-same-function-in-snowflake-but-task-b709929e97f2">Task scheduling and triggered tasks both perform the same function in Snowflake, but task…</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changes and Stream are working the same type in Snowflake.]]></title>
            <link>https://blog.devgenius.io/changes-and-stream-are-working-the-same-type-in-snowflake-2abe64dd8073?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/2abe64dd8073</guid>
            <category><![CDATA[snowflake-changes]]></category>
            <category><![CDATA[snowflake-streaming-data]]></category>
            <category><![CDATA[data-ware-housing]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[stream]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Wed, 03 Jan 2024 16:16:05 GMT</pubDate>
            <atom:updated>2024-01-05T18:11:02.622Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-9WvYVoYznR3ZMc5zfj5A.png" /></figure><p><strong>CHANGES</strong><br>The CHANGES clause enables querying the change tracking metadata for a table or view within a specified interval without creating a stream with an explicit transactional offset. Multiple queries can retrieve the change tracking metadata between transactional start and endpoints.</p><p>Change tracking must be enabled on the source table or the source view and its underlying tables.</p><p>Change tracking data to return below type:</p><p><strong>DEFAULT</strong><br>This feature enables the tracking of all changes made to an object in the database, including inserts, updates, and deletes, as well as table truncates. This type of change tracking compares the rows that were inserted and deleted in the change set to provide the row-level difference. As a result, for instance, a row that is inserted and then deleted in a table between two transactional points of time is not included in the delta (i.e. it will not appear in the query results).</p><p><strong>APPEND_ONLY</strong><br>Returns appended rows only. As a result, querying append-only changes can be much more performant than querying standard (default) changes.</p><p><strong>Usage Notes:</strong><br>The CHANGES clause is not supported when querying for changes (which are resolved using change-tracking metadata) for directory tables or external tables.<br>Change tracking is enabled on the table (using ALTER TABLE … CHANGE_TRACKING = TRUE).<br>A stream is created for the table (using CREATE STREAM).<br>Both options add hidden columns to the table that store change tracking metadata. The columns consume a small amount of storage.<br>The AT | BEFORE clause is required and sets the current offset for the change tracking metadata.<br>The optional END clause sets the end timestamp for the change interval. If no END value is specified, the current timestamp is used as the end of the change interval.<br>The value for TIMESTAMP or OFFSET must be a constant expression.<br>The smallest time resolution for TIMESTAMP is milliseconds.<br>If requested data is beyond the Time Travel retention period (default is 1 day), the statement fails.<br>In addition, if the requested data is within the Time Travel retention period but no historical data is available (e.g. if the retention period was extended), the statement fails.</p><p><strong>Examples</strong></p><p>I created a table called MASTER_TABLE_CHANGE_TRAC and inserted two records. Before inserting a record, set CHANGE_TRACKING to True.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEuXSWBjl62DwhYxOsZ0qQ.png" /></figure><p>Now I have set the current timestamp. after that, I inserted one row, updated one row, and deleted one record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmWLxWNezQkLuWCyzqxAgw.png" /></figure><p>Same thing I have implemented in the stream and got the same result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQ6otSsduObiAJXVh0SOrQ.png" /></figure><p>The above example uses the current offset for a stream on the source table as the start point in time for populating the new table with change data from the source table. Because a stream is created on the source object, you do not need to explicitly enable change tracking on the object.</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><p>If you require a complete code, please send me a message and I will assist you. Let me know how I can be of help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2abe64dd8073" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/changes-and-stream-are-working-the-same-type-in-snowflake-2abe64dd8073">Changes and Stream are working the same type in Snowflake.</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[We insert and update data directly in the Snowflake table from the blob stage without using an…]]></title>
            <link>https://medium.com/@amulyapanda/write-data-directly-loaded-in-snowflake-from-azure-blob-84f16bdc71f2?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/84f16bdc71f2</guid>
            <category><![CDATA[code-optimization]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[azure-snowflake]]></category>
            <category><![CDATA[copy]]></category>
            <category><![CDATA[azure-blob]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Mon, 13 Nov 2023 19:17:03 GMT</pubDate>
            <atom:updated>2023-11-14T15:32:49.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*goUaA0ALq9bHuN6ld79mSQ.png" /></figure><h4>We insert and update data directly in the Snowflake table from the blob stage without using an intermediate stage.</h4><p>We can load data from the Azure blob stage to the Snowflake table without any intermediate stage and we can also update and insert in the target table means merge data. without any intermediate stage.</p><p>For this process, I have followed the below steps.</p><p>Step 1:- Create file format, for this demo, I am trying to load multiple JSON files.</p><blockquote>CREATE OR REPLACE FILE FORMAT my_json_format<br>TYPE = JSON<br>STRIP_OUTER_ARRAY=TRUE<br>STRIP_NULL_VALUES=TRUE<br>ALLOW_DUPLICATE=FALSE<br>IGNORE_UTF8_ERRORS=TRUE</blockquote><p>Step 2:- Create an external stage because every time we do not copy the blob stage path. for this need to create an integration stage and that name you can pass when you create an external stage.</p><blockquote>externalStageParams (for Microsoft Azure) ::=<br> URL = ‘azure://&lt;account&gt;.blob.core.windows.net/&lt;container&gt;[/&lt;path&gt;/]’<br> [ { STORAGE_INTEGRATION = &lt;integration_name&gt; } | { CREDENTIALS = ( [ AZURE_SAS_TOKEN = ‘&lt;string&gt;’ ] ) } ]<br> [ ENCRYPTION = ( [ TYPE = ‘AZURE_CSE’ ] [ MASTER_KEY = ‘&lt;string&gt;’ ] | [ TYPE = ‘NONE’ ] ) ]</blockquote><p>Step 3:- We need to create a stored procedure that merges code with the target table and directly calls the blob stage path (folder). The goal is to load all data under that folder.</p><blockquote>CREATE OR REPLACE PROCEDURE TESTING()<br>RETURNS VARCHAR(500)<br>LANGUAGE SQL<br>EXECUTE AS OWNER<br>AS ‘BEGIN<br> MERGE INTO &lt;target table&gt; USING (<br> select<br> $1:Col1<br> <br> ,$1:col100<br> ,$1:col101<br> <br> from <a href="http://twitter.com/external_stage/blob_folder">@external_stage/blob_folder</a>/ <br> (<br> file_format =&gt; JSON_FORMAT<br> );<br> ON target table.ID=source.id<br>WHEN MATCHED THEN UPDATE SET( source.col1=source.col1,<br>source.col2=target.col2<br>….<br>source.col100=target.col100)</blockquote><blockquote>WHEN NOT MATCHED THEN INSERT ( col1,col2….col100<br> <br>) VALUES (<br>source.col1,<br>source.col2,<br>..<br>source.col100 <br>);</blockquote><blockquote>END’;</blockquote><p>In this approach, I have used this in my one project and tried to process a 500 million record with 398 columns and use an x-small warehouse.</p><p><strong>Advantage:-</strong> To optimize performance and storage space, we have adopted an approach where we avoid storing data in the intermediate stage. Storing 500 million records in the copy stage takes around 2 hours in an x-small warehouse and requires significant storage space. Instead, we directly read data from the blob stage and merge it with the target table. If a new record is found, we insert it, otherwise, we update the record. We are able to complete all process within 2hour. that means you are saved compute cost with storage cost.</p><p><strong>Disadvantage</strong>:-Processing a stored procedure for the first time can optimize your computer’s memory and storage cost. However, when you re-process the same stored procedure, it captures all the data again, meaning it picks up all the files from the folder or path and tries to process them. This does not result in the insertion of duplicate records because the code is merged based on a key.</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><p>If you require a complete code, please send me a message and I will assist you. Let me know how I can be of help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84f16bdc71f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ADD and DROP a column in the ALTER TABLE in a snowflake.]]></title>
            <link>https://medium.com/@amulyapanda/add-and-drop-a-column-in-the-alter-table-in-a-snowflake-54df8262b763?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/54df8262b763</guid>
            <category><![CDATA[snowpark]]></category>
            <category><![CDATA[add-column]]></category>
            <category><![CDATA[alter-table]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[drop]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Wed, 25 Oct 2023 05:37:41 GMT</pubDate>
            <atom:updated>2023-10-25T05:37:41.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uh_3SY09CgXicBkQq620Vw.png" /></figure><h4>ALTER TABLE: Support for IF [NOT] EXISTS with ADD COLUMN and DROP COLUMN.</h4><p>To add or drop a column in an existing table in Snowflake, you can use the ALTER TABLE command. This command allows you to modify the structure of the table by adding or removing columns.</p><blockquote>The ALTER TABLE command now supports the keywords IF NOT EXISTS with ADD COLUMN and IF EXISTS with DROP COLUMN:<br>When adding a column, you can specify IF NOT EXISTS to add the column only if no column with that name exists.</blockquote><p>For the demo, I have created a TEST table and added two columns, now I need to add one more column PHONE_NUMBER.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*Adq5fRmB2J2BB2BJvYwvWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzmZ8PDB5B5m9-cUMvbbqA.png" /></figure><p>If a PHONE_NUMBER column already exists, the statement does not return an error, and the existing column is left unchanged.</p><blockquote>When dropping a column, you can specify IF EXISTS to drop the column only if a column with that name exists.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ql912DNFn_30u7hSFV24kg.png" /></figure><p>Now I am thinking no need PHONE_NMBER column in this table, need to drop this column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_5Ad_wGcbke-TpWlytcHw.png" /></figure><p>If the PHONE_NUMBER column does not exist, the statement does not return an error.</p><blockquote>I am able to add a column to the end of the table, but I cannot add a column where I want it. Specifically, when I add the ‘phone_number’ column to the ‘test’ table, it is added as the last column, whereas I need it to be added after the ‘name’ column. Unfortunately, this is not possible at the moment.</blockquote><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54df8262b763" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic tables compared to streams and tasks.]]></title>
            <link>https://medium.com/@amulyapanda/dynamic-tables-compared-to-streams-and-tasks-7dca6d0ed69e?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dca6d0ed69e</guid>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[tasks]]></category>
            <category><![CDATA[snowpark]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[dynamic-table]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Sat, 21 Oct 2023 14:31:21 GMT</pubDate>
            <atom:updated>2023-10-21T14:31:21.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rn0pjhVgbkK8LUXsTRF6xQ.png" /></figure><p>Like streams and tasks, dynamic tables provide a way to transform data in your pipeline.</p><h4>Dynamic tables compared to streams and tasks:</h4><p>Although dynamic tables serve a similar purpose compared to tasks, there are important differences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*0uErj7ZPbwzgpNkXkETfXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*8UgL9XS8VnjIhJOfWTSoIA.png" /></figure><blockquote><strong>Difference between Streams and Tasks vs Dynamic Table</strong></blockquote><blockquote><strong>Streams and Tasks:</strong><br>Tasks use an imperative approach: You write procedural code to transform data from base tables.<br><strong>Dynamic Tables:</strong><br>Dynamic tables use a declarative approach: You write a query that specifies the result you want, and data is retrieved and transformed from the base tables used in the query.<br><strong>Streams and Tasks:</strong><br>You define a schedule for executing the code that transforms the data.<br><strong>Dynamic Tables:</strong><br>An automated refresh process determines the schedule for performing refreshes. The process schedules these refreshes to meet the specified target level of freshness.<br><strong>Streams and Tasks:</strong><br>The procedural code can contain calls to non-deterministic code, stored procedures, and other tasks. The procedural code can contain calls to UDFs and external functions<br><strong>Dynamic Tables:</strong><br>Although the SELECT statement for a dynamic table can contain joins, aggregations, window functions, and other SQL functions and constructions, the statement cannot contain calls to stored procedures and tasks. Currently, the SELECT statement also cannot contain calls to external functions.<br>This limitation is due to the way in which dynamic tables are refreshed. To refresh the data, an automated process analyzes the SELECT statement for the dynamic table in order to determine the best approach to refresh the data. The automated process cannot determine this for certain types of queries.<br><strong>Streams and Tasks:</strong><br>Tasks can use streams to refresh data in target tables incrementally. You can schedule these tasks to run on a regular basis.<br><strong>Dynamic Tables:</strong><br>An automated refresh process performs incremental refreshes of dynamic tables on a regular basis. The process determines the schedule based on the target “freshness” of the data that you specify.</blockquote><p><strong>Dynamic table limitations:</strong><br>Dynamic tables differ from traditional tables in that certain query constructs and functions are not allowed. Additionally, search optimization, clustering, and the query acceleration service (QAS) are not supported.</p><p><strong>Understanding the costs of dynamic tables:</strong><br><strong>Storage:</strong> Dynamic tables require storage as other tables do. Storage cost is based on a flat rate per terabyte (TB).<br><strong>Cloud services compute:</strong> Dynamic tables use cloud services compute to trigger refreshes when an underlying base object has changed. Cloud services compute cost is subject to the constraint that Snowflake only bills if the daily cloud services cost is greater than 10% of the daily warehouse cost for the account.<br><strong>Virtual warehouse computes</strong>: Dynamic tables require a virtual warehouse to run the queries against base objects when they are initially populated and later when they are continuously refreshed. As data in the underlying base objects changes, changes are applied to the associated dynamic tables. Snowflake bills your account credits based on virtual warehouse usage as a result of these operations.</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dca6d0ed69e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Column aliases for aggregates and the GROUP BY ALL clause.]]></title>
            <link>https://medium.com/@amulyapanda/column-aliases-for-aggregates-and-the-group-by-all-clause-0061438ed087?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/0061438ed087</guid>
            <category><![CDATA[snowflake-cloud]]></category>
            <category><![CDATA[group-by-all]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[snowpark]]></category>
            <category><![CDATA[aggregates]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 16:30:43 GMT</pubDate>
            <atom:updated>2023-10-19T16:30:43.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W6K1PsTVOAIgpvmg1zjSbA.png" /></figure><p>Previously, if a SELECT statement with a <a href="https://docs.snowflake.com/en/sql-reference/constructs/group-by.html#label-group-by-all">GROUP BY ALL</a> clause defined and referred to a column alias for an <a href="https://docs.snowflake.com/en/sql-reference/functions-aggregation">aggregate</a>, the statement would fail with the error not a valid group by expression.</p><p>For example, the following statement has a GROUP BY ALL clause, defines the column alias total for an aggregate, and refers to that alias (ROUND(total)):</p><p><em>SELECT … , SUM(my_column) AS total, ROUND(total) FROM Demo_table GROUP BY ALL;</em></p><p>This statement would fail with the following error message:</p><p><em>Error Code: 000979<br> Error Message: SQL compilation error:<br> [SUM(MYTABLE.MY_COLUMN)] is not a valid group by expression</em></p><blockquote>This issue has been fixed, and these types of statements no longer fail with not a valid group by expression errors.</blockquote><p>For the demo, I have created a DEMO_TABLE table and inserted five records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfhD1x07zqWSXNJXrOtILA.png" /></figure><p>Now, I have an aggregated column and alias column passed in the group by clause, and it is giving the proper output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDiJO71yzzs5DSNi1_7yGQ.png" /></figure><p>This function simplifies complex calculations and resolves lengthy code logic.</p><p>I have used these approaches in my project, Please try to implement them in your project and let me know if you found any other feature in the function.</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0061438ed087" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference between DIV0 and DIV0NULL in Snowflake.]]></title>
            <link>https://medium.com/@amulyapanda/difference-between-div0-and-div0null-in-snowflake-ea03df959ed6?source=rss-fe4a78246bee------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea03df959ed6</guid>
            <category><![CDATA[div0-vs-div0null]]></category>
            <category><![CDATA[cloud-data-warehouse]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[div0null]]></category>
            <category><![CDATA[div0]]></category>
            <dc:creator><![CDATA[Amulya Kumar panda]]></dc:creator>
            <pubDate>Wed, 18 Oct 2023 17:47:07 GMT</pubDate>
            <atom:updated>2023-10-18T17:47:07.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlWVFwDjMWJwmfqSd1tXgg.png" /></figure><p>Div0 and Div0null is an interesting arithmetic function in Snowflake.</p><p><strong>DIV0</strong><br>Performs division like the division operator (/), but returns 0 when the divisor is 0 (rather than reporting an error).</p><blockquote><strong>Syntax</strong><br>DIV0( &lt;dividend&gt; , &lt;divisor&gt; )<br><strong>Arguments</strong><br><strong>dividend</strong><br>Numeric expression that evaluates to the value that you want to divide.<br><strong>divisor</strong><br>Numeric expression that evaluates to the value that you want to divide by.<br><strong>Returns</strong><br>The quotient. If the divisor is 0, the function returns 0.</blockquote><p><strong>Examples</strong><br>As shown in the following example, the DIV0 function performs division like the division operator (/):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aolu94T25-AfiLeHqz05Mw.png" /></figure><p>Not able to execute (1/0) showing <strong>Division by zero but if we used DIV0 return 0.000 output.</strong></p><p><strong>DIV0NULL</strong><br>Performs division like the division operator (/), but returns 0 when the divisor is 0 or NULL (rather than reporting an error or returning NULL).</p><blockquote><strong>Syntax</strong><br>DIV0NULL( &lt;dividend&gt; , &lt;divisor&gt; )<br><strong>Arguments</strong><br><strong>dividend</strong><br>Numeric expression that evaluates to the value that you want to divide.<br><strong>divisor</strong><br>Numeric expression that evaluates to the value that you want to divide by.<br><strong>Returns</strong><br>The quotient. If the divisor is 0 or NULL, the function returns 0.</blockquote><p><strong>Examples</strong><br>As shown in the following example, the DIV0NULL function performs division like the division operator (/):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oTeoGZfyORWKIVGPbs57cw.png" /></figure><blockquote>The only difference I found returned a null in <strong>DIV0 but DIV0NULL returned zero.</strong></blockquote><p>I have used these approaches in my project, Please try to implement them in your project and let me know if you found any other differences, Please comment here.</p><p>Thanks for taking the time to read this blog. Let me know if you have any questions or comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea03df959ed6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>