SQLCreator
Generates FME features from the results of a SQL query executed once against a database. One FME feature is created for each row of the results of the SQL query.
Typical Uses
- Extract database records as FME features according to a SQL statement
- Add features from a database mid-translation
- Execute a database join
How does it work?
The SQLCreator executes a SQL statement against a database. It has no input ports, and so (unlike the SQLExecutor) is not reliant on incoming features to trigger the statement - rather, the query is run one time only.
SQL statements are constructed within the transformer, using the appropriate syntax for the database in use. Spatial queries are supported if the database supports spatial predicates.
One feature is output for each row of the query results, via the Result port.
In this example, we will create a set of features by querying a PostGIS database, which has a table containing addresses with point geometry. We will use a SELECT statement that extracts a subset of the data based on postal code.
A SQLCreator is placed in the workspace.
In the parameters dialog, the Database Connection is selected (or defined, if not previously saved).
A SQL statement is constructed in the SQL Statement parameter, using the built-in editor. The syntax matches the database being used.
There is a convenient shortcut in the editor - by right-clicking on a table (or column) name under Database Tables, you can create a quick statement based on SELECT and more to start editing from.
In this case, we are selecting all of the records in the PostalAddress table that have a postal code starting with V6E.
By default, the output has hidden attributes. Choose the ones you wish to include in the Attributes to Expose parameter.
The query results are extracted, including geometry. Note that only attributes which were exposed are visible in the Table View.
Usage Notes
- If the database supports spatial predicates, spatial queries may be used.
- The SQLCreator can only be used on SQL-enabled data sources. To use SQL with non-SQL data, consider the InlineQuerier.
- If all the data to be queried already exists in a SQL-capable data source, it is generally most efficient to use the SQLCreator or SQLExecutor, as the queries and filtering of the data is executed directly by the database before it enters the FME environment.
- For simple joins of one database table to features, the DatabaseJoiner may be more efficient (if the key field(s) are indexed). The DatabaseJoiner does not require knowledge of SQL.
Choosing a Feature Joining Method
Many transformers can perform data joining based on matching attributes, expressions and/or geometry. When choosing one for a specific joining task, considerations include the complexity of the join, data format, indexing, conflict handling, and desired results. Some transformers use SQL syntax, and some access external databases directly. They may or may not support list attribute reading and creation.
Generally, choosing the one that is most specific to the task you need to accomplish will provide the optimal performance results. If there is more than one way to do it (which is frequently the case), time spent on performance testing alternate methods may be worthwhile. Performance may vary greatly depending on the existence of key indexes when reading external tables (as opposed to features already in the workspace).
Transformer |
Match By |
Uses SQL Statements |
Can Create List |
Input Type |
Notable |
Description |
---|---|---|---|---|---|---|
FeatureJoiner | Attributes | No | No | Features |
|
Joins features by combining the attributes and/or geometry of features based on common key attribute values. Performs the equivalent of Inner, Left, and Full SQL joins. |
FeatureMerger | Attributes | No | Yes | Features |
|
Merges the attributes and/or geometry of one set of features onto another set of features, based on matching key attribute values and expressions. |
ListBasedFeatureMerger | List Attribute to Single Attribute | No | Yes | Features |
|
Merges the attributes and/or geometry of one set of features onto another set of features, based on matching list attribute values with key attribute values and expressions. |
InlineQuerier | SQL query | Yes | No | Features |
|
Creates a set of SQLite database tables from incoming features, executes SQL queries against them, and outputs the results as features. |
SQLCreator | SQL query | Yes | No | External DB |
|
Generates FME features from the results of a SQL query executed once against a database. One FME feature is created for each row of the results of the SQL query. |
SQLExecutor | SQL query | Yes | No | External DB |
|
Executes SQL queries against a database. One query is issued to the database for each initiating feature that enters the transformer. Both the initiating features and the results of the query may be output as features. |
DatabaseJoiner | Attributes | No | Yes | External DB and Features |
|
Joins attributes from an external table to features already in a workspace, based on a common key or keys. SQL knowledge not required. Non-blocking transformer. |
Matcher | Geometry and/or Attributes | No | Yes | Features |
|
Detects features that are matches of each other. Features are declared to match when they have matching geometry, matching attribute values, or both. A list of attributes which must differ between the features may also be specified. If matching on attributes only (not geometry), using the FeatureMerger or another method will give better performance. |
Configuration
Input Ports
The SQLCreator has no input ports.
Output Ports
Features that result from the SQL queries.
On reader errors, outputs a feature with the _reader_error attribute which contains the last error message from the reader.
Rejected Feature Handling: can be set to either terminate the translation or continue running when it encounters a rejected feature. This setting is available both as a default FME option and as a workspace parameter.
Parameters
Format | Select a database format. |
Dataset/Connection | According to chosen format, select a dataset or use/configure a database connection. |
Parameters | Format-specific parameters |
Coord. System |
The coordinate system of the database being connected to, as well as the coordinate system of the Result output features. Leave as default (Read from source) or use a selection from the Coordinate System Gallery. |
SQL Statement |
Specify the SQL query using the text editor. Multiple SQL commands can be delimited by a character specified using the keyword FME_SQL_DELIMITER, embedded at the very beginning of the SQL statement. The single character immediately following this keyword will be used to split the SQL which will then be sent to the database for execution. (Note: Include a space before the character.) An individual statement may be preceded with a single hyphen, indicating that errors should be ignored. Note: Some database formats support comments with /* ... */ or double hyphens (--). The following example contains two SQL commands where errors from the first command will be ignored: FME_SQL_DELIMITER ; -SELECT * FROM TABLEA; SELECT * FROM TABLEB; |
Attributes to Expose |
Enter the names of attributes to expose on the features created by the query. The attributes will be output in the same sequence as specified in the list. Note: By default, the attributes of the resulting features are hidden. You can specify which attributes to expose by entering the attribute names. Click the browse button next to the Attributes to Expose parameter. You can also use a SQL statement to populate the list by pressing “Populate from SQL Query…” and entering a SQL query. The columns from the first matching feature will be used to populate the attributes list. |
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Defining Values
There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.
Using the Text Editor
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
Using the Arithmetic Editor
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Conditional Values
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Content
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
These functions manipulate and format strings. | |
Special Characters |
A set of control characters is available in the Text Editor. |
Math functions are available in both editors. | |
Date/Time Functions | Date and time functions are available in the Text Editor. |
These operators are available in the Arithmetic Editor. | |
These return primarily feature-specific values. | |
FME and workspace-specific parameters may be used. | |
Creating and Modifying User Parameters | Create your own editable parameters. |
Reference
Processing Behavior |
Not applicable |
Feature Holding |
Not applicable |
Dependencies | Format-dependent - may require third-party drivers for some formats |
FME Licensing Level | FME Professional Edition and above |
Aliases | |
History | |
Categories |
FME Community
The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.
Search for all results about the SQLCreator on the FME Community.
Examples may contain information licensed under the Open Government Licence – Vancouver