<?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: Set timestamp column to blank when inserting a record into delta table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3120#M292</link>
    <description>&lt;P&gt;You want to try lit(None) not list(None), did you try that?&lt;/P&gt;&lt;P&gt;I see you said below that youve managed to append the dataframe ehich was easier. I manaipulate dataframes as much as possible with pyspark until i need to do a join/upsert with an existing table. The pyspark method is easier to use python variables and there will be instances where you need to iterate through column names. &lt;A href="https://www.sparkbyexamples.com/pyspark" alt="https://www.sparkbyexamples.com/pyspark" target="_blank"&gt;https://www.sparkbyexamples.com/pyspark&lt;/A&gt; has been immensly helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know how it works out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2023 16:57:39 GMT</pubDate>
    <dc:creator>etsyal1e2r3</dc:creator>
    <dc:date>2023-06-14T16:57:39Z</dc:date>
    <item>
      <title>Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3115#M287</link>
      <description>&lt;P&gt;I am trying to insert a record into Delta table using notebook written in python. This record has a timestamp column that should be blank initially, later i have a plan to update the timestamp value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How am i inserting the record:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  stmt_insert_audit_record =  'insert into default.batch_run (task_name, start, end, status) values (\''+param_task_name+'\', \''+param_start+'\', \''+param_end+'\', \''+param_status+'\')'
  spark.sql(stmt_insert_audit_record)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Out of these columns, when i setup param_end as below, the insert statement works fine.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;param_end = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However I do not want to set an end date. Removing the column name from insert statement will give me an error, since spark will expect all the columns mentioned. I would get an exception as `Column end is not specified in INSERT`.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do i set the param_end value so that the Insert statement can consider a blank value?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 10:17:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3115#M287</guid>
      <dc:creator>naga_databricks</dc:creator>
      <dc:date>2023-06-14T10:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3116#M288</link>
      <description>&lt;P&gt;First I would recommend using a multiline f-string in spark.sql like this...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.sql(f'''
    insert into default.batch_run 
        (
        task_name, 
        start, 
        end, 
        status
        ) values (
        {param_task_name},
        {param_start},
        NULL,
        {param_status}
    ''')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are other options I havent tried if NULL doesnt work like &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;None&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;lit(None)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Let me know which works for you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 10:53:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3116#M288</guid>
      <dc:creator>etsyal1e2r3</dc:creator>
      <dc:date>2023-06-14T10:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3117#M289</link>
      <description>&lt;P&gt;i will certainly try out the f-string. thank you @Tyler Retzlaff​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Options i tried:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;With "None", it will not be able to concatenate with rest of the string. I get this error "can only concatenate str (not "NoneType") to str"&lt;/LI&gt;&lt;LI&gt;list(None) throws an error "Column is not iterable"&lt;/LI&gt;&lt;LI&gt;NULL - This will not work on spark, it will recognize it as an identifer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are there any other ways to specify blank?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 12:12:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3117#M289</guid>
      <dc:creator>naga_databricks</dc:creator>
      <dc:date>2023-06-14T12:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3118#M290</link>
      <description>&lt;P&gt;Enclose the SQL string in double quotes, assign an empty string to param_end, and on the SQL string, enclose the param_end in single quotes, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;param_end = ""&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;stmt_insert_audit_record =  "INSERT INTO default.batch_run (task_name, start, end, status) values ("+param_task_name+", " + param_start+ ", '"+ param_end+ "', " +param_status+ ")"
  
spark.sql(stmt_insert_audit_record)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This could help I believe. &lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 13:28:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3118#M290</guid>
      <dc:creator>Sandeep</dc:creator>
      <dc:date>2023-06-14T13:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3119#M291</link>
      <description>&lt;P&gt;When i tried enclosing the param_end with double quote, i get following error:&lt;/P&gt;&lt;P&gt;```org.apache.spark.SparkDateTimeException: [CAST_INVALID_INPUT] The value '' of the type "STRING" cannot be cast to "TIMESTAMP" because it is malformed. Correct the value as per the syntax, or change its target type. Use `try_cast` to tolerate malformed input and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I tried with cast function on the param_end to convert it to TIMESTAMP. This works now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively, i have managed to create a dataframe and append it to the delta table, instead of using the spark.sql(). This is much simpler.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 16:40:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3119#M291</guid>
      <dc:creator>naga_databricks</dc:creator>
      <dc:date>2023-06-14T16:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3120#M292</link>
      <description>&lt;P&gt;You want to try lit(None) not list(None), did you try that?&lt;/P&gt;&lt;P&gt;I see you said below that youve managed to append the dataframe ehich was easier. I manaipulate dataframes as much as possible with pyspark until i need to do a join/upsert with an existing table. The pyspark method is easier to use python variables and there will be instances where you need to iterate through column names. &lt;A href="https://www.sparkbyexamples.com/pyspark" alt="https://www.sparkbyexamples.com/pyspark" target="_blank"&gt;https://www.sparkbyexamples.com/pyspark&lt;/A&gt; has been immensly helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know how it works out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 16:57:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3120#M292</guid>
      <dc:creator>etsyal1e2r3</dc:creator>
      <dc:date>2023-06-14T16:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3121#M293</link>
      <description>&lt;P&gt;Hi @Naga Vaibhav Elluru​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Elevate our community by acknowledging exceptional contributions. Your participation in marking the best answers is a testament to our collective pursuit of knowledge&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 05:21:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3121#M293</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-15T05:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3122#M294</link>
      <description>&lt;P&gt;I actually meant to write as lit(None). Thanks for that page. I basically needed to cast the TIMESTAMP column when formulating the spark.sql input. &lt;/P&gt;&lt;P&gt;Like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;end_time = ""
stmt =  "INSERT INTO default.another(msg, end_time) values('"+msg+ "', cast('"+ end_time+ "' as TIMESTAMP))"
  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 11:37:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3122#M294</guid>
      <dc:creator>naga_databricks</dc:creator>
      <dc:date>2023-06-15T11:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Set timestamp column to blank when inserting a record into delta table</title>
      <link>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3123#M295</link>
      <description>&lt;P&gt;Good to know, glad you figured it out&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 11:39:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/set-timestamp-column-to-blank-when-inserting-a-record-into-delta/m-p/3123#M295</guid>
      <dc:creator>etsyal1e2r3</dc:creator>
      <dc:date>2023-06-15T11:39:19Z</dc:date>
    </item>
  </channel>
</rss>

