FME Transformers: 2024.2
FME Transformers: 2024.2
SQLCreator
Generates FME features and/or schemas from the results of a SQL query executed 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.
A single schema feature may also be produced if supported by the database.
Examples
Example: Creating features from a SELECT statement
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.
Usage Notes
- If the database supports spatial predicates, spatial queries may be used.
- The SchemaScanner may also be useful as an alternative for producing schemas.
- 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).
Joining Transformers Comparison
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
<Schema>
If requested in parameters and supported by the database, schema features are output here.
An attribute called fme_query
is added to schema features containing the associated SQL.
Result
Features that result from the SQL queries.
<Rejected>
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
Database
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. |
General
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.
|
Schema/Data Features
Features to Read |
Select the type of features to read and output:
|
Editing Transformer Parameters
Transformer parameters can be set by directly entering values, using expressions, or referencing other elements in the workspace such as attribute values or user parameters. Various editors and context menus are available to assist. To see what is available, click beside the applicable parameter.
How to Set Parameter Values
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.
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.
Content Types
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. |
Dialog Options - Tables
Table Tools
Transformers with table-style parameters have additional tools for populating and manipulating values.
Row Reordering
|
Enabled once you have clicked on a row item. Choices include:
|
Cut, Copy, and Paste
|
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers. |
Filter
|
Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output. |
Import
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
Reset/Refresh
|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers. |
Note: Not all tools are available in all transformers.
For more information, see Transformer Parameter Menu Options.
Reference
Processing Behavior |
Not applicable |
Feature Holding |
Not applicable |
Dependencies | Format-dependent - may require third-party drivers for some formats |
Aliases | |
History |
FME Community
The FME Community has a wealth of FME knowledge with over 20,000 active members worldwide. Get help with FME, share knowledge, and connect with users globally.
Search for all results about the SQLCreator on the FME Community.
Examples may contain information licensed under the Open Government Licence – Vancouver, Open Government Licence - British Columbia, and/or Open Government Licence – Canada.