query_data
Run FedSQL SELECT queries against CAS or compute tables in SAS Viya and retrieve rows. Query both storage tiers with one SQL dialect, using paging and result limits.
Instructions
Run a FedSQL SELECT against CAS or compute data and return the rows.
One SQL surface over both storage tiers, so exploring a caslib table and a SAS library table use the same tool and the same dialect. The query runs in the reusable compute session; nothing is persisted — the result is materialised into session scratch, read back, and dropped.
Pick the tier with target — it selects the namespace, and the two
cannot be mixed in one statement (a caslib table and a libref table
cannot be joined; stage one side first with execute_sas_code):
target='cas'(default) — qualify ascaslib.table(e.g.Public.HMEQ); see list_caslibs / list_castables.target='compute'— qualify aslibref.table(e.g.WORK.SALES); see list_compute_libraries / list_compute_tables. Concatenated librefs — several directories under one name, which is what SASHELP and MAPS are — are invisible to FedSQL, because its BASE driver maps one schema to one directory. Copy such a table into WORK first (data work.cars; set sashelp.cars; run;) and queryWORK.CARS.
Dialect notes (FedSQL, not PROC SQL): joins (inner/left/right/full/
cross), subqueries, UNION, GROUP BY/HAVING/ORDER BY, and scalar functions
work. There is no WITH/CTE — use a derived table (select ...) "t"
— and no MERGE; express a merge as a join (a full join with COALESCE
gives upsert semantics). Double-quote identifiers that are reserved words
or contain spaces; SAS name literals ('x'n) are not FedSQL.
Row capping is done by this tool, not by your SQL: any LIMIT you write is
ignored in favour of limit (a malformed LIMIT is silently discarded by
CAS and would return the whole table). Add ORDER BY for stable paging.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum rows to return, 1..10000 (default 100). | |
| query | Yes | A single FedSQL SELECT statement. DDL/DML is refused — this tool only reads rows. | |
| start | No | Row offset for paging (default 0). | |
| target | No | Which tier the identifiers refer to — ``cas`` (default) or ``compute``. | cas |
| create_view_name | No | If set, the result includes ``create_view_sql`` — the ``CREATE VIEW <name> AS <query>`` text for this query. It is returned for you to run yourself, never executed here. | |
| compute_context_name | No | Compute context to run in; defaults to the server's configured execution context. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||