Question

How to populate an attribute using the results of an SQL query?

  • 19 August 2021
  • 3 replies
  • 50 views

I've created a new Output Attribute in AttributeManager and I want to populate this based on the results of a (rather lengthy) SQL query.

However, the SQL will be looking at attribute values from the reader and not a database, which I think rules out SQLCreator and SQLExecutor.

Does anybody have any suggestions as to how I might manage this?


3 replies

Userlevel 5
Badge +25

The InlineQuerier is probably what you need. It'll build an in-memory database from the input features upon which you can run SQL queries.

The InlineQuerier is probably what you need. It'll build an in-memory database from the input features upon which you can run SQL queries.

Thanks, that looks like it might do the job! Just got to work out how to use it now!! 😉

Userlevel 3
Badge +17

I have a workbench that does something like this with the SQLExecutor:

 

SELECT "id","start_date" FROM "activities" WHERE "ORDER BY "id" DESC LIMIT 1 OFFSET @Value(Offset)

 

If the Offset Attribute is 10 then this query selects the 10th last inserted record. I use this to query an API to get all records that are after the start_date of that record. This way I can check the last records for changes and get all the new records. Within the SQLExecutor you then Expose the id and start_date Attributes.

 

The workbench also has a lot of DatabaseJoiners. Those test if records exist without downloading all the data in those records. If Joined do A else do B.

 

The InlineQuerier creates a new database from the Features you put in (that probably are already in a database) and then you can preform SQLite queries on that database to get new features out. This could be a fast way to process your features, but mainly if A, the features are not from a database, or B, the database has a very slow CPU/Memory comparing to the CPU/Memory of FME.

Reply