> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# insert_records_from_query

<div className="kinetica-pydoc">
  <div className="dl py method">
    <div className="dt sig sig-object py" id="gpudb.GPUdb.insert_records_from_query"> <span className="sig-name descname"><span className="pre">insert\_records\_from\_query</span></span><span className="sig-paren">(</span><span className="em sig-param"><span className="n"><span className="pre">table\_name</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">None</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">remote\_query</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">None</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">modify\_columns</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">{"{"}{"}"}</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">create\_table\_options</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">{"{"}{"}"}</span></span></span>, <span className="em sig-param"><span className="n"><span className="pre">options</span></span><span className="o"><span className="pre">=</span></span><span className="default_value"><span className="pre">{"{"}{"}"}</span></span></span><span className="sig-paren">)</span><a href="https://github.com/kineticadb/kinetica-api-python/blob/master/gpudb/gpudb.py#L35258"><span className="viewcode-link"><span className="pre">\[source]</span></span></a></div>

    <div className="dd">
      <p>Computes remote query result and inserts the result data into a new or existing table.</p>
      <p><strong>Parameters</strong></p>

      <div className="blockquote">
        <div>
          <div className="dl">
            <div className="dt">table\_name (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Name of the table into which the data will be inserted, in \[schema\_name.]table\_name format, using standard <a className="reference external" href="/content/concepts/tables/#table-name-resolution">name resolution rules</a>. If the table does not exist, the table will be created using either an existing <span className="em">type\_id</span> or the type inferred from the remote query, and the new table name will have to meet standard <a className="reference external" href="/content/concepts/tables/#table-naming-criteria">table naming criteria</a>.</p>
            </div>

            <div className="dt">remote\_query (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Query for which result data needs to be imported.</p>
            </div>

            <div className="dt">modify\_columns (<span className="em">dict of str to dicts of str to str</span>) –</div>

            <div className="dd">
              <p>Not implemented yet. The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>

            <div className="dt">create\_table\_options (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Options used when creating the target table. Allowed keys are:</p>

              <ul>
                <li>
                  <p><strong>type\_id</strong> – ID of a currently registered <a className="reference external" href="/content/concepts/types/">type</a>. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>no\_error\_if\_exists</strong> – If <span className="em">true</span>, prevents an error from occurring if the table already exists and is of the given type. If a table with the same ID but a different type exists, it is still an error. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>is\_replicated</strong> – Affects the <a className="reference external" href="/content/concepts/tables/#distribution">distribution scheme</a> for the table’s data. If <span className="em">true</span> and the given type has no explicit <a className="reference external" href="/content/concepts/tables/#shard-key">shard key</a> defined, the table will be <a className="reference external" href="/content/concepts/tables/#replication">replicated</a>. If <span className="em">false</span>, the table will be <a className="reference external" href="/content/concepts/tables/#sharding">sharded</a> according to the shard key specified in the given <span className="em">type\_id</span>, or <a className="reference external" href="/content/concepts/tables/#random-sharding">randomly sharded</a>, if no shard key is specified. Note that a type containing a shard key cannot be used to create a replicated table. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>foreign\_keys</strong> – Semicolon-separated list of <a className="reference external" href="/content/concepts/tables/#foreign-keys">foreign keys</a>, of the format ‘(source\_column\_name \[, …]) references target\_table\_name(primary\_key\_column\_name \[, …]) \[as foreign\_key\_name]’.</p>
                </li>

                <li>
                  <p><strong>foreign\_shard\_key</strong> – Foreign shard key of the format ‘source\_column references shard\_by\_column from target\_table(primary\_key\_column)’.</p>
                </li>

                <li>
                  <p><strong>partition\_type</strong> – <a className="reference external" href="/content/concepts/tables/#partitioning">Partitioning</a> scheme to use. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>RANGE</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-range">range partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>INTERVAL</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-interval">interval partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>LIST</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>HASH</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-hash">hash partitioning</a>.</p>
                    </li>

                    <li>
                      <p><strong>SERIES</strong> – Use <a className="reference external" href="/content/concepts/tables/#partitioning-by-series">series partitioning</a>.</p>
                    </li>
                  </ul>
                </li>

                <li>
                  <p><strong>partition\_keys</strong> – Comma-separated list of partition keys, which are the columns or column expressions by which records will be assigned to partitions defined by <span className="em">partition\_definitions</span>.</p>
                </li>

                <li>
                  <p><strong>partition\_definitions</strong> – Comma-separated list of partition definitions, whose format depends on the choice of <span className="em">partition\_type</span>. See <a className="reference external" href="/content/concepts/tables/#partitioning-by-range">range partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-interval">interval partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitioning</a>, <a className="reference external" href="/content/concepts/tables/#partitioning-by-hash">hash partitioning</a>, or <a className="reference external" href="/content/concepts/tables/#partitioning-by-series">series partitioning</a> for example formats.</p>
                </li>

                <li>
                  <p><strong>is\_automatic\_partition</strong> – If <span className="em">true</span>, a new partition will be created for values which don’t fall into an existing partition. Currently only supported for <a className="reference external" href="/content/concepts/tables/#partitioning-by-list">list partitions</a>. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>ttl</strong> – Sets the <a className="reference external" href="/content/concepts/ttl/">TTL</a> of the table specified in input parameter <span className="em">table\_name</span>.</p>
                </li>

                <li>
                  <p><strong>chunk\_size</strong> – Indicates the number of records per chunk to be used for this table.</p>
                </li>

                <li>
                  <p><strong>is\_result\_table</strong> – Indicates whether the table is a <a className="reference external" href="/content/concepts/tables_memory_only/">memory-only table</a>. A result table cannot contain columns with text\_search <a className="reference external" href="/content/concepts/types/#data-handling">data-handling</a>, and it will not be retained if the server is restarted. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>strategy\_definition</strong> – The <a className="reference external" href="/content/rm/concepts/#tier-strategies">tier strategy</a> for the table and its columns.</p>
                </li>

                <li>
                  <p><strong>compression\_codec</strong> – The default <a className="reference external" href="/content/concepts/column_compression/">compression codec</a> for this table’s columns.</p>
                </li>
              </ul>

              <p>The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>

            <div className="dt">options (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Optional parameters. Allowed keys are:</p>

              <ul>
                <li>
                  <p><strong>bad\_record\_table\_name</strong> – Name of a table to which records that were rejected are written. The bad-record-table has the following columns: line\_number (long), line\_rejected (string), error\_message (string). When error handling is Abort, bad records table is not populated.</p>
                </li>

                <li>
                  <p><strong>bad\_record\_table\_limit</strong> – A positive integer indicating the maximum number of records that can be written to the bad-record-table. Default value is 10000.</p>
                </li>

                <li>
                  <p><strong>batch\_size</strong> – Number of records per batch when inserting data.</p>
                </li>

                <li>
                  <p><strong>datasource\_name</strong> – Name of an existing external data source from which table will be loaded.</p>
                </li>

                <li>
                  <p><strong>error\_handling</strong> – Specifies how errors should be handled upon insertion. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>permissive</strong> – Records with missing columns are populated with nulls if possible; otherwise, the malformed records are skipped.</p>
                    </li>

                    <li>
                      <p><strong>skip</strong> – Malformed records are skipped.</p>
                    </li>

                    <li>
                      <p><strong>ignore\_bad\_records</strong> – Deprecated. Alias for <span className="em">skip</span>.</p>
                    </li>

                    <li>
                      <p><strong>abort</strong> – Stops current insertion and aborts entire operation when an error is encountered. Primary key collisions are considered abortable errors in this mode.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘abort’.</p>
                </li>

                <li>
                  <p><strong>pk\_conflict\_predicate\_higher</strong> – The record with higher value for the column resolves the primary-key insert conflict. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>pk\_conflict\_predicate\_lower</strong> – The record with lower value for the column resolves the primary-key insert conflict. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>ignore\_existing\_pk</strong> – Specifies the record collision error-suppression policy for inserting into a table with a <a className="reference external" href="/content/concepts/tables/#primary-keys">primary key</a>, only used when not in upsert mode (upsert mode is disabled when <span className="em">update\_on\_existing\_pk</span> is <span className="em">false</span>). If set to <span className="em">true</span>, any record being inserted that is rejected for having primary key values that match those of an existing table record will be ignored with no error generated. If <span className="em">false</span>, the rejection of any record for having primary key values matching an existing record will result in an error being reported, as determined by <span className="em">error\_handling</span>. If the specified table does not have a primary key or if upsert mode is in effect (<span className="em">update\_on\_existing\_pk</span> is <span className="em">true</span>), then this option has no effect. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>true</strong> – Ignore new records whose primary key values collide with those of existing records.</p>
                    </li>

                    <li>
                      <p><strong>false</strong> – Treat as errors any new records whose primary key values collide with those of existing records.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>ingestion\_mode</strong> – Whether to do a full load, dry run, or perform a type inference on the source data. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>full</strong> – Run a type inference on the source data (if needed) and ingest.</p>
                    </li>

                    <li>
                      <p><strong>dry\_run</strong> – Does not load data, but walks through the source data and determines the number of valid records, taking into account the current mode of <span className="em">error\_handling</span>.</p>
                    </li>

                    <li>
                      <p><strong>type\_inference\_only</strong> – Infer the type of the source data and return, without ingesting any data. The inferred type is returned in the response.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘full’.</p>
                </li>

                <li>
                  <p><strong>jdbc\_fetch\_size</strong> – The JDBC fetch size, which determines how many rows to fetch per round trip.</p>
                </li>

                <li>
                  <p><strong>jdbc\_session\_init\_statement</strong> – Executes the statement per each JDBC session before doing actual load. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>num\_splits\_per\_rank</strong> – Number of splits for reading data per rank. Default will be external\_file\_reader\_num\_tasks. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>num\_tasks\_per\_rank</strong> – Number of tasks for reading data per rank. Default will be external\_file\_reader\_num\_tasks.</p>
                </li>

                <li>
                  <p><strong>primary\_keys</strong> – Comma separated list of column names, to set as primary keys, when not specified in the type. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>shard\_keys</strong> – Comma separated list of column names, to set as shard keys, when not specified in the type. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>subscribe</strong> – Continuously poll the data source to check for new data and load it into the table. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>truncate\_table</strong> – If set to <span className="em">true</span>, truncates the table specified by input parameter <span className="em">table\_name</span> prior to loading the data. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>remote\_query</strong> – Remote SQL query from which data will be sourced.</p>
                </li>

                <li>
                  <p><strong>remote\_query\_order\_by</strong> – Name of column to be used for splitting the query into multiple sub-queries using ordering of given column. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>remote\_query\_filter\_column</strong> – Name of column to be used for splitting the query into multiple sub-queries using the data distribution of given column. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>remote\_query\_increasing\_column</strong> – Column on subscribed remote query result that will increase for new records (e.g., TIMESTAMP). The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>remote\_query\_partition\_column</strong> – Alias name for <span className="em">remote\_query\_filter\_column</span>. The default value is ‘’.</p>
                </li>

                <li>
                  <p><strong>truncate\_strings</strong> – If set to <span className="em">true</span>, truncate string values that are longer than the column’s type size. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>

                <li>
                  <p><strong>enable\_inplace\_updates</strong> – Applies only when upserting (when update\_on\_existing\_pk is true). If set to true (the default), an existing record matched by primary key is modified in place. If set to false, the matched record is updated by deleting it and inserting a replacement (delete and insert), which prevents the change from being reflected in dependent materialized views until they are refreshed. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p>true</p>
                    </li>

                    <li>
                      <p>false</p>
                    </li>
                  </ul>

                  <p>The default value is ‘true’.</p>
                </li>

                <li>
                  <p><strong>update\_on\_existing\_pk</strong> – Specifies the record collision policy for inserting into a table with a <a className="reference external" href="/content/concepts/tables/#primary-keys">primary key</a>. If set to <span className="em">true</span>, any existing table record with primary key values that match those of a record being inserted will be replaced by that new record (the new data will be “upserted”). If set to <span className="em">false</span>, any existing table record with primary key values that match those of a record being inserted will remain unchanged, while the new record will be rejected and the error handled as determined by <span className="em">ignore\_existing\_pk</span> and <span className="em">error\_handling</span>. If the specified table does not have a primary key, then this option has no effect. Allowed values are:</p>

                  <ul className="simple">
                    <li>
                      <p><strong>true</strong> – Upsert new records when primary keys match existing records.</p>
                    </li>

                    <li>
                      <p><strong>false</strong> – Reject new records when primary keys match existing records.</p>
                    </li>
                  </ul>

                  <p>The default value is ‘false’.</p>
                </li>
              </ul>

              <p>The default value is an empty dict ( {"{"}{"}"} ).</p>
            </div>
          </div>
        </div>
      </div>

      <p><strong>Returns</strong></p>

      <div className="blockquote">
        <div>
          <p>A dict with the following entries–</p>

          <div className="dl simple">
            <div className="dt">table\_name (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>Value of input parameter <span className="em">table\_name</span>.</p>
            </div>

            <div className="dt">type\_id (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>ID of the currently registered table structure <a className="reference external" href="/content/concepts/types/">type</a> for the target table.</p>
            </div>

            <div className="dt">type\_definition (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>A JSON string describing the columns of the target table.</p>
            </div>

            <div className="dt">type\_label (<span className="em">str</span>) –</div>

            <div className="dd">
              <p>The user-defined description associated with the target table’s structure.</p>
            </div>

            <div className="dt">type\_properties (<span className="em">dict of str to lists of str</span>) –</div>

            <div className="dd">
              <p>A mapping of each target table column name to an array of column properties associated with that column.</p>
            </div>

            <div className="dt">count\_inserted (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>Number of records inserted into the target table.</p>
            </div>

            <div className="dt">count\_skipped (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>Number of records skipped, when not running in <span className="em">abort</span> error handling mode.</p>
            </div>

            <div className="dt">count\_updated (<span className="em">long</span>) –</div>

            <div className="dd">
              <p>\[Not yet implemented] Number of records updated within the target table.</p>
            </div>

            <div className="dt">info (<span className="em">dict of str to str</span>) –</div>

            <div className="dd">
              <p>Additional information.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
