title: Inserting data in a table in PySpark Sql
body: <p>I am trying to insert a dataframe in a table. the dataframe what i have gives me output like this _</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Field</th>
  <th>Value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>id</td>
  <td>95</td>
  </tr>
  <tr>
  <td>name</td>
  <td>N04</td>
  </tr>
  <tr>
  <td>parentId</td>
  <td>702</td>
  </tr>
  <tr>
  <td>parentExternalId</td>
  <td>N7</td>
  </tr>
  <tr>
  <td>description</td>
  <td>WAT..</td>
  </tr>
  <tr>
  <td>metadata</td>
  <td>{_replir...</td>
  </tr>
  <tr>
  <td>source</td>
  <td>https://github.co...</td>
  </tr>
  <tr>
  <td>Id</td>
  <td>43636</td>
  </tr>
  <tr>
  <td>createdTime</td>
  <td>2021-10-13 11:58:...</td>
  </tr>
  <tr>
  <td>lastUpdatedTime</td>
  <td></td>
  </tr>
  <tr>
  <td>rootId</td>
  <td>6978</td>
  </tr>
  <tr>
  <td>agregates</td>
  <td>null</td>
  </tr>
  <tr>
  <td>dataset</td>
  <td>null</td>
  </tr>
  <tr>
  <td>labels</td>
  <td>null</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And I have multiple rows here. Now I am trying to insert this data in one of the table which has columns as (PointID, Name, PointParentID, desc). I would like to insert Id column in PointID, name in Name, parentID in PointParentId and description in desc. How can I do this using pyspark sql. I tried below command and it works in inserting a single data in a table with a single column.</p>
  <pre class="lang-py prettyprint-override"><code>df = spark.sql(&quot;Insert into `Utilities_66_Demo`.`UtilityProduct` values('Hi')&quot;)
  df = spark.sql(&quot;Select * from `Utilities_66_Demo`.`UtilityProduct`&quot;)
  df.show()
  </code></pre>
  <p>Same way I have table with 4 columns defined above and a dataframe where I need to insert data to.
  But how can i insert a data completely in single call from the dataframe whose output I have shown above. the dataframe I got is from this code:</p>
  <pre class="lang-py prettyprint-override"><code>dfSourceAssets = spark.read.format(&quot;xyz.spark.v1&quot;) \
     .option(&quot;type&quot;, &quot;assets&quot;) \
     .option(&quot;tokenUri&quot;, sourceTokenURI) \
     .option(&quot;clientId&quot;, sourceClientID) \
     .option(&quot;clientSecret&quot;, sourceClientSecret) \
     .option(&quot;baseUrl&quot;, sourceBaseURL) \
     .option(&quot;project&quot;, sourceProject) \
     .option(&quot;scopes&quot;, sourceScopes) \
     .load()
  </code></pre>