psql: add \create_function command

From: Steve Chavez <steve(at)supabase(dot)io>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: psql: add \create_function command
Date: 2024-01-26 18:41:05
Message-ID: CAGRrpzZnoWY-kK_0qK-OY=-e0eDqhc5kdFSkuxN0mxe9iuiz0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello hackers,

Currently a function definition must include its body inline. Because of
this, when storing function definitions in files, linters and syntax
highlighters for non-SQL languages (python, perl, tcl, etc) won't work. An
example can be seen on:

https://github.com/postgres/postgres/blob/5eafacd2797dc0b04a0bde25fbf26bf79903e7c2/src/pl/plpython/sql/plpython_test.sql#L15-L24

To solve the above issue, this patch adds a psql command to create a
function and obtain its body from another file. It is used as:

\create_function from ./data/max.py max(int,int) returns int LANGUAGE
plpython3u

Its design is similar to the `\copy` command, which is a frontend version
of the COPY statement.

This patch is at an initial stage but includes tests with plpython3u,
pltcl, plperl and tab completion.

Any feedback is welcomed.

Best regards,
Steve Chavez

Attachment Content-Type Size
0001-psql-add-create_function-command.patch text/x-patch 14.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2024-01-26 18:51:48 Re: psql: add \create_function command
Previous Message Robert Haas 2024-01-26 18:37:41 Re: cleanup patches for incremental backup