Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions content/references/objects/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ weight: 70
Create function allows creating user-defined functions.
Functions can help you to encapsulate common logic that can be reused.

The body of a SQL function is a `select` statement of the form `select <expression>`, matching PostgreSQL's syntax for SQL-language functions.
SQL functions must return the result of one scalar expression and cannot reference tables or subqueries.

```sql
create function times_two(x int) returns int language sql as
'x * 2';
'select x * 2';

create function cowsay(t text) returns text language sql as $$
' ' || repeat('_', length(t) + 2) || E'\n' ||
select ' ' || repeat('_', length(t) + 2) || E'\n' ||
'< ' || t || E' >\n' ||
' ' || repeat('-', length(t) + 2) || E'\n' ||
E' \\ ^__^\n' ||
Expand Down
Loading