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

# Create a Stored Procedure

> Create a new stored procedure within a database schema

# Create a Stored Procedure

Create a new stored procedure within a database schema.

## Body Parameters

**name** `string` *required*

Name of the stored procedure. Must be unique within the parent database schema.

**databaseSchema** `string` *required*

Fully qualified name of the parent DatabaseSchema, for example `snowflake_prod.analytics.public`.

**storedProcedureCode** `object`

The source code and language of the stored procedure.

**properties**

**code** `string`

The source code of the stored procedure.

**language** `string`

Programming language of the code, for example `SQL`, `JavaScript`, `Python`.

**displayName** `string`

Human-readable display name for the stored procedure.

**description** `string`

Description of the stored procedure in Markdown format.

**owners** `array`

Array of owner references (users or teams) to assign to the stored procedure.

**properties**

**id** `string`

UUID of the owner entity.

**type** `string`

Type of owner entity, for example `user`, `team`.

**name** `string`

Name of the owner entity.

**domains** `array`

Fully qualified names of the domains to assign for governance purposes.

**tags** `array`

Array of classification tags to apply to the stored procedure.

**properties**

**tagFQN** `string` *required*

Fully qualified name of the tag.

**labelType** `string`

Type of label, for example `Manual`, `Derived`, `Propagated`.

**state** `string`

State of the tag, for example `Suggested`, `Confirmed`.

**extension** `object`

Custom property values defined by your organization's metadata schema.

```python POST /v1/storedProcedures theme={null}
from metadata.sdk import configure
from metadata.sdk.entities import StoredProcedures
from metadata.generated.schema.api.data.createStoredProcedure import CreateStoredProcedureRequest

configure(
    host="https://your-company.open-metadata.org/api",
    jwt_token="your-jwt-token"
)

request = CreateStoredProcedureRequest(
    name="usp_refresh_analytics",
    displayName="Refresh Analytics",
    databaseSchema="snowflake_prod.analytics.public",
    description="Refreshes materialized analytics views nightly",
    storedProcedureCode={
        "code": "CREATE OR REPLACE PROCEDURE usp_refresh_analytics() ...",
        "language": "SQL"
    }
)

stored_procedure = StoredProcedures.create(request)
print(f"Created: {stored_procedure.fullyQualifiedName.root}")
```

```java POST /v1/storedProcedures theme={null}
import org.openmetadata.schema.api.data.CreateStoredProcedure;
import org.openmetadata.schema.entity.data.StoredProcedure;
import org.openmetadata.schema.api.data.StoredProcedureCode;
import org.openmetadata.schema.type.StoredProcedureLanguage;

// client is an initialized OpenMetadataClient.

CreateStoredProcedure request = new CreateStoredProcedure()
    .withName("usp_refresh_analytics")
    .withDisplayName("Refresh Analytics")
    .withDatabaseSchema("snowflake_prod.analytics.public")
    .withDescription("Refreshes materialized analytics views nightly")
    .withStoredProcedureCode(new StoredProcedureCode()
        .withCode("CREATE OR REPLACE PROCEDURE usp_refresh_analytics() ...")
        .withLanguage(StoredProcedureLanguage.SQL));

StoredProcedure storedProcedure = client.storedProcedures().create(request);
```

```bash POST /v1/storedProcedures theme={null}
curl -X POST "{base_url}/api/v1/storedProcedures" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "calculate_average",
    "databaseSchema": "sample_data.ecommerce_db.shopify",
    "description": "Procedure to calculate average",
    "storedProcedureCode": {
      "code": "CREATE OR REPLACE PROCEDURE calculate_average(numbers INT ARRAY) RETURNS FLOAT NOT NULL LANGUAGE SQL AS $$DECLARE sum_val INT = 0;count_val INT = 0;average_val FLOAT;BEGIN\n  FOR num IN ARRAY numbers DO sum_val := sum_val + num;\n  count_val := count_val + 1;\nEND FOR;\nIF count_val = 0 THEN\n  average_val := 0.0;\nELSE\n  average_val := sum_val / count_val;\nEND IF;\nRETURN average_val;\nEND;$$;"
    }
  }'
```

```json Response theme={null}
{
  "id": "d02b24fa-a246-4563-adf1-9ad21f251c0e",
  "name": "calculate_average",
  "fullyQualifiedName": "sample_data.ecommerce_db.shopify.calculate_average",
  "description": "Procedure to calculate average",
  "storedProcedureCode": {
    "code": "CREATE OR REPLACE PROCEDURE calculate_average(numbers INT ARRAY) RETURNS FLOAT NOT NULL LANGUAGE SQL AS $$DECLARE sum_val INT = 0;count_val INT = 0;average_val FLOAT;BEGIN\n  FOR num IN ARRAY numbers DO sum_val := sum_val + num;\n  count_val := count_val + 1;\nEND FOR;\nIF count_val = 0 THEN\n  average_val := 0.0;\nELSE\n  average_val := sum_val / count_val;\nEND IF;\nRETURN average_val;\nEND;$$;"
  },
  "version": 0.1,
  "updatedAt": 1769982660822,
  "updatedBy": "admin",
  "storedProcedureType": "StoredProcedure",
  "href": "http://localhost:8585/api/v1/storedProcedures/d02b24fa-a246-4563-adf1-9ad21f251c0e",
  "databaseSchema": {
    "id": "4dd30184-009c-4792-b296-9562eaed651f",
    "type": "databaseSchema",
    "name": "shopify",
    "fullyQualifiedName": "sample_data.ecommerce_db.shopify",
    "description": "This **mock** database contains schema related to shopify sales and orders with related dimension tables.",
    "displayName": "shopify",
    "deleted": false,
    "href": "http://localhost:8585/api/v1/databaseSchemas/4dd30184-009c-4792-b296-9562eaed651f"
  },
  "database": {
    "id": "0be090de-0941-48c4-af49-a6157c91cda0",
    "type": "database",
    "name": "ecommerce_db",
    "fullyQualifiedName": "sample_data.ecommerce_db",
    "description": "This **mock** database contains schemas related to shopify sales and orders with related dimension tables.",
    "displayName": "ecommerce_db",
    "deleted": false,
    "href": "http://localhost:8585/api/v1/databases/0be090de-0941-48c4-af49-a6157c91cda0"
  },
  "serviceType": "BigQuery",
  "deleted": false,
  "owners": [],
  "tags": [],
  "domains": [],
  "processedLineage": false,
  "entityStatus": "Unprocessed"
}
```

***

## Returns

Returns the created stored procedure object with all specified properties and system-generated fields.

## Response

**id** `string`

Unique identifier for the stored procedure (UUID format).

**name** `string`

Stored procedure name.

**fullyQualifiedName** `string`

Fully qualified name in format `service.database.schema.storedProcedure`.

**displayName** `string`

Human-readable display name.

**description** `string`

Description of the stored procedure in Markdown format.

**databaseSchema** `object`

Reference to the parent database schema.

**properties**

**id** `string`

UUID of the database schema.

**type** `string`

Type of entity (always `databaseSchema`).

**name** `string`

Name of the database schema.

**fullyQualifiedName** `string`

Fully qualified name of the database schema.

**storedProcedureCode** `object`

The source code and language of the stored procedure.

**properties**

**code** `string`

The source code of the stored procedure.

**language** `string`

Programming language of the code.

**serviceType** `string`

Type of database service, for example Snowflake, BigQuery, PostgreSQL.

**owners** `array`

List of owners assigned to the stored procedure.

**properties**

**id** `string`

UUID of the owner entity.

**type** `string`

Type of owner entity, for example `user`, `team`.

**name** `string`

Name of the owner entity.

**domains** `array`

Domain assignments for governance.

**tags** `array`

Classification tags applied to the stored procedure.

**properties**

**tagFQN** `string`

Fully qualified name of the tag.

**labelType** `string`

Type of label, for example `Manual`, `Derived`, `Propagated`.

**state** `string`

State of the tag, for example `Suggested`, `Confirmed`.

**extension** `object`

Custom property values defined by your organization's metadata schema.

**version** `number`

Version number for the entity (starts at 0.1).

***

## Create or Update (PUT)

Use `PUT /v1/storedProcedures` instead of `POST` to perform an upsert. If a stored procedure with the same `fullyQualifiedName` already exists, it will be updated; otherwise, a new stored procedure is created. The request body is the same as `POST`.

```bash theme={null}
curl -X PUT "{base_url}/api/v1/storedProcedures" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{ ... same body as POST ... }'
```

> [!NOTE]
>
> `PUT` will not return a `409` conflict error if the entity already exists -- it will update the existing entity instead.

***

## Bulk Create or Update (PUT)

Use `PUT /v1/storedProcedures/bulk` to create or update multiple stored procedures in a single request. The request body is an array of create request objects.

```bash theme={null}
curl -X PUT "{base_url}/api/v1/storedProcedures/bulk" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '[
    { "name": "proc_one", "databaseSchema": "service.db.schema" },
    { "name": "proc_two", "databaseSchema": "service.db.schema" }
  ]'
```

***

## Error Handling

| Code | Error Type | Description |
| - | - | - |
| `400` | `BAD_REQUEST` | Invalid request body or missing required fields |
| `401` | `UNAUTHORIZED` | Invalid or missing authentication token |
| `403` | `FORBIDDEN` | User lacks permission to create stored procedures |
| `409` | `ENTITY_ALREADY_EXISTS` | Stored procedure with same name already exists in schema (POST only) |


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