2

How can I create an query on an existing query? I tried multiple versions.

SELECT * FROM {{q_....}}

does not works

Marco
  • 91
  • 4

2 Answers2

0

For security reasons, templated values in SQL queries must be wrapped in special helpers.

In the example above, you would need to use the schema and table helpers to ensure that only pre-approved table names are templated in. This prevents accidental (or malicious) access to undesired tables.

For example something like:

SELECT column1 FROM {{schema someSchemaName 'allowedSchemaName1' 'allowedSchemaName2'}}.{{table someTableName 'allowedTableName1'}};

Please see the official docs for more details on this.

Ryan Norris
  • 151
  • 1
  • 3
0

This query pattern doesn't exist in Slate. You can use Partials to reuse parts of query logic across multiple queries or formulate your query logic in a function, but you can't "query" the results of an existing query.

Postgres will use some caching strategies automatically so that if you're running similar queries in succession you'll see some improved performance.

Logan Rhyne
  • 581
  • 2
  • 5
  • So i has to work with functions... :-/ – Marco Jul 11 '22 at 07:35
  • To clarify, I meant that you can use Slate javascript (front-end) functions to dynamically generate your SQL to avoid code duplication NOT that you _have to_ use Typescript (backend) Functions and the Ontology API to access your data (though I still recommend that pattern in most cases). – Logan Rhyne Jul 11 '22 at 13:16
  • yes, i understood. But SQL is much easier than javascript. e.g. sort, sum, filter etc... – Marco Jul 12 '22 at 09:34