Re: psql: add \create_function command - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: psql: add \create_function command
Date
Msg-id CAFj8pRBApmd8KYj-puwde+A-2A2fQ5W8okCWEki8SFMeN6MrsA@mail.gmail.com
Whole thread Raw
In response to psql: add \create_function command  (Steve Chavez <steve@supabase.io>)
Responses Re: psql: add \create_function command
Re: psql: add \create_function command
List pgsql-hackers
Hi

pá 26. 1. 2024 v 19:41 odesílatel Steve Chavez <steve@supabase.io> napsal:
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.

looks a little bit obscure - why do you need to do it from psql? And how frequently do you do it?

I think so this is fix on wrong place - you should to fix linters, not psql - more without header you cannot do correct linting

Regards

Pavel

 

Best regards,
Steve Chavez

pgsql-hackers by date:

Previous
From: Steve Chavez
Date:
Subject: psql: add \create_function command
Next
From: "David E. Wheeler"
Date:
Subject: Re: Patch: Improve Boolean Predicate JSON Path Docs