Skip to content

Commit

Permalink
Add examples for SHOW CREATE FUNCTION statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessie212 committed May 24, 2024
1 parent c9483bb commit 730e25c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
20 changes: 20 additions & 0 deletions docs/src/main/sphinx/routines/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ SQL routine invocation works without the full path:
SELECT answer() + 5; -- 47
```

You can show SQL routines and plugin functions in a schema. This example uses
the `default` schema of the `example` catalog:

```sql
SHOW FUNCTIONS FROM example.default
```

Of the functions returned, find all that match a character pattern. This example
returns results with a name beginning with `ans`:

```sql
SHOW FUNCTIONS like 'ans%';
```

Show the SQL statement that created the function. In this example the function is `answer`:

```sql
SHOW CREATE FUNCTION answer;
```

## Declaration examples

The result of calling the routine `answer()` is always identical, so you can
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/sphinx/routines/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ In this scenario, the following commands can be used:
* [](/sql/create-function) to create and store a routine.
* [](/sql/drop-function) to remove a routine.
* [](/sql/show-functions) to display a list of routines in a catalog.
* [](/sql/show-create-function) to display the SQL statement that created the
specified function.

Catalog routines must use a name that combines the catalog name and schema name
with the routine name, such as `example.default.power` for the `power` routine
Expand Down
48 changes: 44 additions & 4 deletions docs/src/main/sphinx/sql/show-create-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,60 @@

## Synopsis

```text
```sql
SHOW CREATE FUNCTION function_name
```

## Description

Show the SQL statement that creates the specified function.
Shows the SQL statement that created the specified function.

## Examples

Show the SQL that can be run to create the `meaning_of_life` function:
List all SQL routines and plugin functions in the `default` schema of the
`brain_catalog`:

```sql
SHOW FUNCTIONS FROM brain_catalog.default
```

Example output:

```text
Function | Return Type | Argument Types | Function Type | Deterministic | Description
----------+-------------+----------------+---------------+---------------+-------------
answer | bigint | | scalar | true |
```
SHOW CREATE FUNCTION example.default.meaning_of_life;

List all functions with a name beginning with `ans`:

```sql
SHOW FUNCTIONS like 'ans%';
```

Example output:

```text
Function | Return Type | Argument Types | Function Type | Deterministic | Description
----------+-------------+----------------+---------------+---------------+-------------
answer | bigint | | scalar | true |
```

The following example uses `SHOW CREATE FUNCTION` to reveal the SQL statement
that created the `answer` function:

```sql
SHOW CREATE FUNCTION answer;
```

Example output:

```text
Create Function
--------------------------
CREATE FUNCTION answer()
RETURNS BIGINT
RETURN 42
```

## See also
Expand Down

0 comments on commit 730e25c

Please sign in to comment.