<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need to load the data from databricks to Snowflake table having ID,which automatically increment in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/need-to-load-the-data-from-databricks-to-snowflake-table-having/m-p/98709#M39812</link>
    <description>&lt;P&gt;&lt;SPAN&gt;To load data from a DataFrame into a Snowflake table with an autoincrement ID column, you can follow these steps:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL class="marker:text-textOff list-decimal pl-8"&gt;
&lt;LI&gt;&lt;SPAN&gt;First, ensure that your Snowflake table (test1) is created with an autoincrement ID column:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE TABLE test1 (
    ID INT AUTOINCREMENT START 1 INCREMENT 1,
    c1 VARCHAR,
    c2 VARCHAR,
    c3 VARCHAR
);​&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Then, use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;CODE&gt;write_pandas&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;method from the Snowflake Connector for Python to load the data from your DataFrame into the Snowflake table. Here's how you can do it:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="markup"&gt;import pandas as pd
from snowflake.connector.pandas_tools import write_pandas

# Assuming you have already established a connection to Snowflake
# and have a cursor object named 'cursor'

# Your DataFrame
df = pd.DataFrame({
    'c1': ['value1', 'value2', 'value3'],
    'c2': ['value4', 'value5', 'value6'],
    'c3': ['value7', 'value8', 'value9']
})

# Write the DataFrame to Snowflake
success, nchunks, nrows, _ = write_pandas(
    conn=cursor.connection,
    df=df,
    table_name='test1',
    database='your_database',
    schema='your_schema'
)

if success:
    print(f"Successfully loaded {nrows} rows into {nchunks} chunks")
else:
    print("Data load failed")&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 13 Nov 2024 18:42:07 GMT</pubDate>
    <dc:creator>Walter_C</dc:creator>
    <dc:date>2024-11-13T18:42:07Z</dc:date>
    <item>
      <title>Need to load the data from databricks to Snowflake table having ID,which automatically increments</title>
      <link>https://community.databricks.com/t5/data-engineering/need-to-load-the-data-from-databricks-to-snowflake-table-having/m-p/98334#M39699</link>
      <description>&lt;P&gt;I want to load the data from&amp;nbsp; df (say 3 columns c1,c2,c3) into the snowflake table say (test1) having columns (c1,c2,c3) and ID autoincrement column.&lt;/P&gt;&lt;P&gt;The df and snowflake table (test1) have same column definition and same datatypes. In the target table (test2) we have additional column say ID .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2024 13:50:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/need-to-load-the-data-from-databricks-to-snowflake-table-having/m-p/98334#M39699</guid>
      <dc:creator>ms_221</dc:creator>
      <dc:date>2024-11-11T13:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need to load the data from databricks to Snowflake table having ID,which automatically increment</title>
      <link>https://community.databricks.com/t5/data-engineering/need-to-load-the-data-from-databricks-to-snowflake-table-having/m-p/98709#M39812</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To load data from a DataFrame into a Snowflake table with an autoincrement ID column, you can follow these steps:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL class="marker:text-textOff list-decimal pl-8"&gt;
&lt;LI&gt;&lt;SPAN&gt;First, ensure that your Snowflake table (test1) is created with an autoincrement ID column:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE TABLE test1 (
    ID INT AUTOINCREMENT START 1 INCREMENT 1,
    c1 VARCHAR,
    c2 VARCHAR,
    c3 VARCHAR
);​&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Then, use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;CODE&gt;write_pandas&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;method from the Snowflake Connector for Python to load the data from your DataFrame into the Snowflake table. Here's how you can do it:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;LI-CODE lang="markup"&gt;import pandas as pd
from snowflake.connector.pandas_tools import write_pandas

# Assuming you have already established a connection to Snowflake
# and have a cursor object named 'cursor'

# Your DataFrame
df = pd.DataFrame({
    'c1': ['value1', 'value2', 'value3'],
    'c2': ['value4', 'value5', 'value6'],
    'c3': ['value7', 'value8', 'value9']
})

# Write the DataFrame to Snowflake
success, nchunks, nrows, _ = write_pandas(
    conn=cursor.connection,
    df=df,
    table_name='test1',
    database='your_database',
    schema='your_schema'
)

if success:
    print(f"Successfully loaded {nrows} rows into {nchunks} chunks")
else:
    print("Data load failed")&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 13 Nov 2024 18:42:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/need-to-load-the-data-from-databricks-to-snowflake-table-having/m-p/98709#M39812</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-11-13T18:42:07Z</dc:date>
    </item>
  </channel>
</rss>

