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 Jul 5, 2024
1 parent c9483bb commit 4704a7d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 16 deletions.
23 changes: 23 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,29 @@ SQL routine invocation works without the full path:
SELECT answer() + 5; -- 47
```

You can show SQL catalog routines stored in a specific catalog and schema. The
following example lists all routines in 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`. To ensure all routines with the same name and different parameters
are returned, parenthesis `()` are excluded.

```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 show the source code of the routine that
creates 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
40 changes: 36 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,52 @@

## Synopsis

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

## Description

Show the SQL statement that creates the specified function.
Show the definition of the SQL routine. The `function_name` parameter is the
name of the routine without `()` and any parameters.

## Examples

Show the SQL that can be run to create the `meaning_of_life` function:
The following example uses `SHOW CREATE FUNCTION` to display the definition of
the routine that created the `answer` function.

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

Example output:

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

The following example uses `SHOW CREATE FUNCTION` to display the definition of
the `answer` SQL routine found on the default SQL path or the current catalog
and schema:

```sql
SHOW create function example.default.answer;
```
SHOW CREATE FUNCTION example.default.meaning_of_life;

Example output:

```text
Create Function
---------------------------
CREATE FUNCTION answer()
RETURNS BIGINT
COMMENT 'meaning of life'
RETURN 42
```

## See also
Expand Down
22 changes: 10 additions & 12 deletions docs/src/main/sphinx/sql/show-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,25 @@ List all SQL routines and plugin functions in the `default` schema of the
SHOW FUNCTIONS FROM example.default;
```

List all functions with a name beginning with `array`:
Example output:

```sql
SHOW FUNCTIONS LIKE 'array%';
```text
Function | Return Type | Argument Types | Function Type | Deterministic | Description
----------+-------------+----------------+---------------+---------------+-----------------
answer | bigint | | scalar | true | meaning of life
```

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

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

Example output:

```text
Function | Return Type | Argument Types | Function Type | Deterministic | Description
------------------+-------------+----------------+---------------+---------------+-----------------------------------------
cf_getgroups | varchar | | scalar | true | Returns the current session's groups
cf_getprincipal | varchar | | scalar | true | Returns the current session's principal
cf_getuser | varchar | | scalar | true | Returns the current session's user
```
Function | Return Type | Argument Types | Function Type | Deterministic | Description
----------+-------------+----------------+---------------+---------------+-----------------
answer | bigint | | scalar | true | meaning of life

## See also

Expand Down

0 comments on commit 4704a7d

Please sign in to comment.