Inserting Data

Use the esp.sqlInsert function to insert records into the database.

resp = esp.sqlInsert(options)

In the function, options include the following fields:

  • conn is the name of the SQL connection to use.
  • table is the database table in which to insert data.
  • data contains one or more Python objects that contain the records to insert.
  • context is an optional value that specifies the Python context in which the connection exists.

If you are processing stock trades, then you could use a Python subscriber connector on the Source window to grab incoming trades and write them to a database:

<window-source name="trades" insert-only="true">
    <schema>
        <fields>
            <field key="true" name="id" type="int64"/>
            <field name="symbol" type="string"/>
            <field name="currency" type="int32"/>
            <field name="time" type="int64"/>
            <field name="msecs" type="int32"/>
            <field name="price" type="double"/>
            <field name="quant" type="int32"/>
            <field name="venue" type="int32"/>
            <field name="broker" type="int32"/>
            <field name="buyer" type="int32"/>
            <field name="seller" type="int32"/>
            <field name="buysellflg" type="int32"/>
        </fields>
    </schema>
    <connectors>
        <connector class="python" name="sub">
            <properties>
                <property name="type">sub</property>
                <property name="code"><![CDATA[
                    def subscribe(data):
                        response = esp.sqlInsert(conn="db",table="trades",data=data)
                        if (response.code == False):
                            print(str(response))
                  ]]></property>
            </properties>
        </connector>
    </connectors>
</window-source>

The return value from esp.sqlInsert is a Python object that contains the following fields:

  • code is the status of the insert: true for success and false for failure.
  • message contains information that is related to the failure when one occurs.
  • object is the data for the failed record when a failure occurs.
Last updated: August 18, 2026