Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

Default value:  [None]

Snap type:

Write

Description:

This Snap executes a SQL update with the given properties. Keys from the document will be used as the columns to update and their values will be the updated value in the column.

Prerequisites:

[None]

Support and limitations:
Account: 

This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See MySQL Account for information on setting up this type of account.

Views:


InputThis Snap has exactly one document input view.
OutputThis Snap has at most one document output view. If an output view is available, then the original document that was used to create the statement will be output with the status of the update executed.
Error

This Snap has at most one document error view and produces zero or more documents in the view.
Note: Database write Snaps output all records of a batch (as configured in your account settings) to the error view if the write fails during batch processing.


Settings

Label

Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

Schema name



The database schema name. In case it is not defined, then the suggestion for the Table Name will retrieve all tables names of all schemas. The property is suggestable and will retrieve available database schemas during suggest values.

Note

The values can be passed using the pipeline parameters but not the upstream parameter.

ExampleSYS
Default value:  [None]

Table name

Required. The name of the table to execute the update operation on.

Note

The values can be passed using the pipeline parameters but not the upstream parameter.

Examplepeople

Default value:  [None]

Update condition

Required. Specify the SQL WHERE clause of the update statement. You can define specific values or columns to update (Set condition) in the upstream Snap, such as Mapper Snap, and then use the WHERE clause to apply these conditions on the columns sourced from the upstream Snap. For instance, here is a sample of an Update SQL query:

UPDATE table_name
SET column1 = value1, column2 = value2,
WHERE condition;

Info

If the Update Condition field is left blank, the condition is applied on all the records of the target table. 

Multiexcerpt include macro
nameOriginal structure_for_primary_key
pageOracle - Update

Refer to the example to understand how to use the Update Condition.

Examples

Without using expressions

Using expressions

  • "EMPNO=$EMPNO and ENAME=$EMPNAME"

  • email = $email 

  • emp=$emp

  • "emp='" + $emp + "'"

  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"

Warning
titleCaution

Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and is hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled. 


Number of retries

Specifies the maximum number of attempts to be made to receive a response. The request is terminated if the attempts do not result in a response.

Example: 3

Default value: 0

Multiexcerpt include macro
nameretries
pageFile Reader

Retry interval (seconds)

Specifies the time interval between two successive retry requests. A retry happens only when the previous attempt resulted in an exception. 

Example:  10

Default value: 1

Multiexcerpt include macro
nameSnap Execution
pageSOAP Execute

Multiexcerpt include macro
nameExecution_Detail_Write
pageSOAP Execute


Example


 In this example, we will use the well-known Northwind sample database. 

Following is a selection from the "Customers" table: 

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1
 
Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4
 
Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
 


 Assume we wish to update the customer "Alfreds Futterkiste" with a new contact person and city. 

Enter Customers in the Table name property and CustomerName='Alfreds Futterkiste' in the Update condition property. 

Assume that the Update Snap receives a Map data in the input view as following:


Code Block
 {
        "ContactName" :  "Alfred Schmidt",
        "City"  :  "Hamburg" } 


When you save and execute the pipeline, the Snap internally formats a standard SQL UPDATE statement as following:

UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
 

and submit the request to the database server.
 
The selection from the "Customers" table will now look like this:
 

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1
 
Alfreds FutterkisteAlfred SchmidtObere Str. 57Hamburg12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4
 
Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden
 


Be careful when updating records. If we had omitted the Update condition property, in the example above, the "Customers" table would have looked like this: 
 

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1
 
Alfreds FutterkisteAlfred SchmidtObere Str. 57Hamburg12209Germany
2Ana Trujillo Emparedados y heladosAlfred SchmidtAvda. de la Constitución 2222Hamburg05021Mexico
3Antonio Moreno TaqueríaAlfred SchmidtMataderos 2312Hamburg05023Mexico
4
 
Around the HornAlfred Schmidt120 Hanover Sq.HamburgWA1 1DPUK
5Berglunds snabbköpAlfred SchmidtBerguvsvägen 8HamburgS-958 22Sweden
 


Example


In this pipeline, the MySQL Update Snap, updates the record in a table.  

 The CSV Generator Snap passes the values to be updated to a record on the MySQl Database table. The value for command is set to 2.



The Mapper Snap maps the record PersonID to be updated.

The MySQL Snap updates the table, `pqadb`.`TAM_SAMPLE_PERSONS`. Give an update condition if a specific record needs to be updated only after fulfilling the given condition.

The successful execution of the pipeline displays the below output preview:




Insert excerpt
MySQL Snap Pack
MySQL Snap Pack
nopaneltrue