--- title: "Scripting Vs. SQL Vs. Expressions" --- # Scripting Vs. SQL Vs. Expressions > ```js title="Expression Language - Comment" > // The Expression Language uses double forward slashes. > ``` ## Expression Language & SQL Queries vs Scripting There are three major languages in Ignition, the [Expression language](platform\expression-language-and-syntax\expression-language-and-syntax.md), the [SQL Queries](platform/sql-in-ignition/sql-in-ignition.md), and [Python Scripting](platform/scripting/scripting.md). It is important to understand the differences between the three and to know where each is used. Scripting is used in the event handlers that are available all over Ignition, but Expressions and SQL are in the [Property Binding](ignition-modules\vision\binding-types-in-vision\property-bindings-in-vision\property-bindings-in-vision.md) locations shown here. ## Spot the Difference - Comments When starting out with Ignition, it can be difficult to know which syntax you should be using for a particular area of text. One little trick that may help is to be familiar with how each language handles comments, and then utilize the **Ctrl** + **/** command which automatically adds the characters that comments out a line of code in the language are you are typing in. Once you remember to use **Ctrl** + **/**, you simply need to be familiar with the characters that each language uses. ```js title="Expression Language - Comment" // The Expression Language uses double forward slashes. ``` ```sql title="SQL - Comment" -- Areas in Ignition that accept SQL syntax use double dashes. ``` ```python title="Python - Comment" # Python uses the pound/number/hash character. ``` In addition to comments, interfaces for each of the languages usually contain other signs or reminders about the language. These will be covered in their respective sections on this page. ## Python Scripts Python is featured prominently throughout Ignition and many different resources can contain a Python Script. ### How Can I Tell If I'm Writing a Python Script? Python Scripts typically use the words **Script** or **Event** in the interface. Additionally, Python requires a particular Event to be selected so if you see event Handlers on the left, you know you are looking at a Python script. ![](component-scripting.png) ### Where Are Python Scripts Used? Python Scripts are used all throughout Ignition. Some resources, such as components, even have multiple places to write scripts! Below are some common locations for scripts: * [Scripting in Vision](ignition-modules\vision\scripting-in-vision\scripting-in-vision.md) * [Extension Functions](ignition-modules\vision\scripting-in-vision\extension-functions\extension-functions.md) * [Tag Event Scripts](platform\tags\tag-event-scripts\tag-event-scripts.md) * [Client Event Scripts](ignition-modules\vision\scripting-in-vision\client-event-scripts\client-event-scripts.md) * [Gateway Event Scripts](../../scripting-in-ignition/gateway-event-scripts/gateway-event-scripts.md) ## SQL Queries The SQL language is used for selecting information from a database. It can be used in a variety of ways, but most of them will either make modifications to the database or return a set of values (with a few notable exceptions like Stored Procedures). The majority of users will be returning large chunks of data into a Table or Report in Ignition. This means a complete dataset will be returned based on a user selection, a time range, or any combination of factors. ### How Can I Tell If I Should Be Using SQL Syntax? Typically, the words **Query** and **Database** appear in the interface somewhere. Additionally, there is usually a way to specify a **Database Connection**. ![](query-binding.png) ### Where Is SQL Used in Ignition? Below is a reference of the most common areas in Ignition where SQL queries may be used. * [Vision SQL Query Bindings](ignition-modules\vision\binding-types-in-vision\sql-query-bindings-in-vision\sql-query-bindings-in-vision.md) * [Named Queries](platform/sql-in-ignition/named-queries/named-queries.md) * [Database Query Browser](platform\designer\designer-tools\database-query-browser\database-query-browser.md) * Reporting Data Source: * [SQL Query Data Source](ignition-modules/reporting/report-data/sql-query-data-source\sql-query-data-source.md) * [Basic SQL Query](ignition-modules\reporting\report-data\basic-sql-query\basic-sql-query.md) * [Query Tags](platform\tags\types-of-tags\types-of-tags.md) * Python Scripts - See the SQL in Python header below for more details ### SQL in Python **SQL** queries can be called from a **Python** script. There are several system functions in Ignition that allow a script to run a query against the database, such as [system.db.runPrepQuery](appendix/scripting-functions/system-db/system-db-runPrepQuery.md). This is a more advanced technique, as you need to adhere to both language's syntax. Furthermore, when typing a SQL query in a Python script interface, the syntax highlighting can not help with the SQL portions. The syntax highlighting in a Scripting Window is only looking for Python syntax, not SQL. In cases where you plan on calling a SQL query from a Python script, it is highly recommended to write the query in the **Database Query Browser** first (substituting parameters with static values for testing purposes), and then move the query over to the script once the query executes successfully on its own. This approach can save you some time troubleshooting, as there will be less ambiguity when an error occurs since you know the query runs. Below we see an example of calling a SQL query in a script. Line 5 creates a variable called "query", and assigns it a string consisting of a prepared statement (using SQL). The query is then executed with the [system.db.runPrepUpdate](appendix/scripting-functions/system-db/system-db-runPrepUpdate.md) function. For more examples of using a query in a Python Script, check out the [system.db.*](appendix/scripting-functions/system-db/system-db.md) functions. ![](scripting-overview-script.png) ## Expression Language The Expression Language is a simple programming language that we invented (very similar to many other existing expression languages), and is different from the Python scripting you will find in Ignition. The expression language is a very simple kind of language where everything is an expression - which is a single piece of code that returns a value. This means that there are no statements, and no variables, just operators, literals, and functions. The most common expression language that most people are familiar with is the one found in Microsoft Excel. You can have Excel calculated a cell's value dynamically by typing an expression like `=SUM(C5:C10)`. Our expression language has similar functionality, but different syntax. It is mainly used to define dynamic values for **Tags** and **component properties**. In Ignition's Expression Language, you will use component properties and functions like if(`{Root Container.type}`="Type C",True,False). ### How Can I Tell If I'm Writing an Expression? Typically interfaces that expect the Expression Language use the word **Expression**. Additionally, you'll commonly find the **Expression Function** button ![](function.png) towards the right side of the text area. ![](expression-binding.png) ### Where Is The Expression Language Used? Below is a list of resources that commonly utilize the Expression Language * [Expression Bindings](ignition-modules\vision\binding-types-in-vision\expression-binding-in-vision\expression-binding-in-vision.md) on Property Bindings and [Alarm Bindings](platform/alarming/configuring-alarms/configuring-alarms.md#alarm-property-bindings) * [Expression Tags](platform\tags\types-of-tags\types-of-tags.md#expression-tags) and [Derived Tags](platform\tags\types-of-tags\types-of-tags.md#derived-tags) * Several [Alarm Pipeline Blocks](ignition-modules\alarm-notification\alarm-notification-pipelines\pipeline-blocks\pipeline-blocks.md), including the [Expression Block](ignition-modules\alarm-notification\alarm-notification-pipelines\pipeline-blocks\pipeline-blocks.md#expression-block), [Switch Block](ignition-modules\alarm-notification\alarm-notification-pipelines\pipeline-blocks\pipeline-blocks.md#switch-block), and [Notification Blocks](ignition-modules\alarm-notification\alarm-notification-pipelines\pipeline-blocks\pipeline-blocks.md#notification-block). * [Expression Items](ignition-modules\sql-bridge-transaction-groups\item-types\item-types.md#expression-items) in Transaction Groups * [Parameters on Reports](ignition-modules/reporting/report-data/report-parameters/report-parameters.md) * [SFC Transitions](../../../../ignition-modules/sequential-function-charts/SFC-elements/SFC-elements.md#transition-element)