Example representation: Data model with a custom SQL element

This is an example representation of a data model, created using the get a data model representation endpoint. Representations like this one can be used to create a data model from code using the create a data model from a representation endpoint. Each page in this example library includes the code representation of the data model and step-by-step instructions to create it in the Sigma UI.

Consult this example and others in the Data model representation example library to:

  • Troubleshoot the formatting of a particular feature in code representation
  • Relate a feature from the Sigma UI to its representation in code
  • Provide context to AI tools used to create data models from code
🚧

This example representation cannot be used as-is. All identifying details, such as IDs, names, and URLs, have been replaced with randomized ID values or generic substitutions. The format of these contents, like the length of ID values, is preserved for demonstrative purposes. However, this representation cannot be directly used without modification to the base URL, connection details, and more. For more information, see Create and manage data models from code.

System and user requirements

To complete the steps in this example, you must meet the user requirements listed below for creating the data model in the UI and creating it from code.

The ability to create this data model in the Sigma UI requires the following:

  • You must be assigned an account type with the Create, edit, and publish data models and Write SQL permissions enabled.
  • To run custom SQL, you must be granted Can use access for an entire connection. See Manage access to data and connections.
  • You must have connection-level access to at least one connection in your organization to view the SQL editor.

The ability to create a data model from code requires the following:

This example uses a table from the Sigma Sample Connection. Your organization might have disabled access to the Sigma sample connection. If so, you can contact an admin to enable it, or use a table from another connection to follow along with this example.

Create the example data model in the Sigma UI

This example shows a simple data model with a single custom SQL element.

To create this data model in the Sigma UI:

  1. Go to the Home page.

  2. Select Create New > Data model.

    A new data model opens.

  3. From the Add element bar, select Data > Table.

  4. In the Select source modal, select SQL.

  5. In the Select a connection dropdown, select Sigma Sample Database

  6. In the query editor, enter the following SQL:

SELECT * 
FROM FUN.BIKES.TRIP
WHERE START_STATION_NAME like '%City Hall%'
  1. Select Run to execute the query.

  2. Select Toggle SQL editor to hide the query editor.

    The query results appear as a table in the data model.

  3. Select the caret () in the document header to open the document menu, then select File > Rename.

  4. Rename the data model to Bikes - Custom SQL.

  5. Select Publish.

Get a JSON representation of this data model

To get a JSON representation of this data model, follow the steps in Get the code representation of a data model.

The JSON representation of this data model appears like the following:

JSON representation
{
  "dataModelId": "481d8ce4-da9a-4b50-a534-b762f15d7cd8",
  "name": "custom-sql",
  "url": "https://aws-api.sigmacomputing.com/org-name/data-model/custom-sql-3aqZwMZa3AjJls03Xqf8by",
  "documentVersion": 2,
  "latestDocumentVersion": 2,
  "ownerId": "fOsrWKBxSMe8HqLmT0nXESkGLpkIc",
  "folderId": "fcb10706-125c-4a83-83d1-2977c8d963a0",
  "createdBy": "fOsrWKBxSMe8HqLmT0nXESkGLpkIc",
  "updatedBy": "fOsrWKBxSMe8HqLmT0nXESkGLpkIc",
  "createdAt": "2025-11-21T21:18:59.906Z",
  "updatedAt": "2026-01-22T17:58:41.986Z",
  "schemaVersion": 1,
  "pages": [
    {
      "id": "bZLodXC93v",
      "name": "Page 1",
      "elements": [
        {
          "id": "jRVqpPXsmw",
          "kind": "table",
          "source": {
            "connectionId": "9ad28df9-5f5f-4bae-8985-bb12d25829de",
            "statement": "SELECT * \nFROM FUN.BIKES.TRIP\nWHERE START_STATION_NAME like '%City Hall%'",
            "kind": "sql"
          },
          "columns": [
            {
              "id": "KD62PqK5AL",
              "formula": "[Custom SQL/ID]"
            },
            {
              "id": "vPlGzl6LD6",
              "formula": "[Custom SQL/DURATION]"
            },
            {
              "id": "Z6oWaYZzTx",
              "formula": "[Custom SQL/START_DATE]"
            },
            {
              "id": "hHvbGrcnBN",
              "formula": "[Custom SQL/START_STATION_NAME]"
            },
            {
              "id": "7ceavUlb7O",
              "formula": "[Custom SQL/START_STATION_ID]"
            },
            {
              "id": "EKSFC6aVfs",
              "formula": "[Custom SQL/END_DATE]"
            },
            {
              "id": "TZ2q21a8gS",
              "formula": "[Custom SQL/END_STATION_NAME]"
            },
            {
              "id": "moYF0pw0bH",
              "formula": "[Custom SQL/END_STATION_ID]"
            },
            {
              "id": "NSOGB3M09S",
              "formula": "[Custom SQL/BIKE_ID]"
            },
            {
              "id": "PfMR5y3VNg",
              "formula": "[Custom SQL/SUBSCRIPTION_TYPE]"
            },
            {
              "id": "ZX4VS6KORL",
              "formula": "[Custom SQL/ZIP_CODE]"
            }
          ],
          "order": [
            "KD62PqK5AL",
            "vPlGzl6LD6",
            "Z6oWaYZzTx",
            "hHvbGrcnBN",
            "7ceavUlb7O",
            "EKSFC6aVfs",
            "TZ2q21a8gS",
            "moYF0pw0bH",
            "NSOGB3M09S",
            "PfMR5y3VNg",
            "ZX4VS6KORL"
          ]
        }
      ]
    }
  ]
}

Representing custom SQL

The custom SQL element is represented by the following object in the elements array:

Custom SQL element representation
...
{
  "id": "jRVqpPXsmw",
  "kind": "table",
  "source": {
    "connectionId": "9ad28df9-5f5f-4bae-8985-bb12d25829de",
    "statement": "SELECT * \nFROM FUN.BIKES.TRIP\nWHERE START_STATION_NAME like '%City Hall%'",
    "kind": "sql"
  },
  "columns": [
    {
      "id": "KD62PqK5AL",
      "formula": "[Custom SQL/ID]"
    },
    {
      "id": "vPlGzl6LD6",
      "formula": "[Custom SQL/DURATION]"
    },
    {
      "id": "Z6oWaYZzTx",
      "formula": "[Custom SQL/START_DATE]"
    },
    {
      "id": "hHvbGrcnBN",
      "formula": "[Custom SQL/START_STATION_NAME]"
    },
    {
      "id": "7ceavUlb7O",
      "formula": "[Custom SQL/START_STATION_ID]"
    },
    {
      "id": "EKSFC6aVfs",
      "formula": "[Custom SQL/END_DATE]"
    },
    {
      "id": "TZ2q21a8gS",
      "formula": "[Custom SQL/END_STATION_NAME]"
    },
    {
      "id": "moYF0pw0bH",
      "formula": "[Custom SQL/END_STATION_ID]"
    },
    {
      "id": "NSOGB3M09S",
      "formula": "[Custom SQL/BIKE_ID]"
    },
    {
      "id": "PfMR5y3VNg",
      "formula": "[Custom SQL/SUBSCRIPTION_TYPE]"
    },
    {
      "id": "ZX4VS6KORL",
      "formula": "[Custom SQL/ZIP_CODE]"
    }
  ],
  "order": [
    "KD62PqK5AL",
    "vPlGzl6LD6",
    "Z6oWaYZzTx",
    "hHvbGrcnBN",
    "7ceavUlb7O",
    "EKSFC6aVfs",
    "TZ2q21a8gS",
    "moYF0pw0bH",
    "NSOGB3M09S",
    "PfMR5y3VNg",
    "ZX4VS6KORL"
  ]
}
...

The representation treats the custom SQL element as a table, and the source of the table as a SQL query. When searching for details like the query that generated the table, look for the source object in the element representation, and look for the statement property within that object. In this case, the source object appears like the following:

SQL Source object
...
"source":
    {
      "connectionId": "3i6h1g0f-9e8d-7c6b-5a4d-3e2f1a0b9c8d",
      "statement": "SELECT * \nFROM FUN.BIKES.TRIP\nWHERE START_STATION_NAME like '%City Hall%'",
      "kind": "sql",
    },
...

The source object above corresponds to the SQL query shown in step 6 of the section Create this data model in the Sigma UI:

SQL query
SELECT * 
FROM FUN.BIKES.TRIP
WHERE START_STATION_NAME like '%City Hall%'