martin icon indicating copy to clipboard operation
martin copied to clipboard

Table sources, support WHERE conditions

Open artyomb opened this issue 1 year ago • 3 comments

That would be very useful to have "where" in table sources:

  tables:
    tab_filtered:
      layer_id: table_source

      # Table name (required)
      table: table_source
      
      # SQL where conditions
      where: (TYPE = 'A') and (Pop > 100)

artyomb avatar Dec 05 '24 12:12 artyomb

Even better I guess:

  tables:
    tab_filtered:
      layer_id: table_source
      table_sql: SELECT * FROM table WHERE ...

artyomb avatar Dec 11 '24 09:12 artyomb

There has been some conversations about this type of capability. Fundamentally there is nothing stopping us from doing this, with the possible exception that this, by definition, is a subset of functionality already available with SQL functions - so we need to clearly understand why we want to duplicate it... that said, this is indeed simpler than writing a full sql function. This also requires some somewhat unsafe SQL manipulation, but nothing too dangerous - i.e. config author can now write DROP TABLE in that statement, but i guess we have to trust config file.

I don't think we want the second table_sql variant, as it creates more problems -- we would need to evaluate the statement, see which columns are returned, check that exactly one of them is a gis column, match it up with the rest of the table configuration, ... - not worth it. Adding where config value on the other hand seems like a good path.

In short - PRs welcome, should be fairly simple to add.

nyurik avatar Dec 11 '24 15:12 nyurik

If this ends up working with auto_publish, that could do things functions can't. If you try to handle a whole schema of geodata in a function, you'll need to EXECUTE FORMAT ... and the hard parses can kill your performance.

david-morris avatar Jul 22 '25 08:07 david-morris