> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nx1cloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Call a rule from SQL

> Call a published business rule as a SQL function in Trino or Spark.

You can call a published business rule as a SQL function in Trino or Spark. This lets a query
use a rule's decision on every row without a separate call to the API.

## Prerequisites

Before starting this task, ensure you have the following:

* [A published version of a rule](https://docs.nx1cloud.com/documentation/data/tasks/business-rules/versions/publish-a-version.md).
  A newly published version can take about 30 seconds to appear in SQL.
* Access to Trino or Spark in NexusOne
* [`decisions_enabled`](https://docs.nx1cloud.com/documentation/getting-started/deployment/deployment-variables) variable set to `true`,
  which is the default

## Steps

Perform these steps to call a published rule from SQL:

1. Open a SQL editor that connects to Trino or Spark, such as SQL Lab in Superset.
   To open Superset, refer to [Launch Superset](https://docs.nx1cloud.com/documentation/tools/tasks/launch-superset.md).

2. Optional: To see which workspaces and rules you can call, run the following commands in Trino.

   ```sql theme={null}
   SHOW SCHEMAS FROM decisions;
   SHOW FUNCTIONS FROM decisions.<workspace-name>;
   ```

3. Call a rule as a function by running a query like the following:

   ```sql theme={null}
   SELECT decisions.<workspace-name>.<function-name>(<arguments>);
   ```

   Replace the placeholders with the following values:

   * **`<workspace-name>`**: The name of a workspace.
   * **`<function-name>`**: The key of a rule, which you entered when you created it.
   * **`<arguments>`**: The values that a rule needs, separated by commas.

## Additional resources

To publish a version, refer to [Publish a version](https://docs.nx1cloud.com/documentation/data/tasks/business-rules/versions/publish-a-version.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.