Re: How to add a new psql command ?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Quentin Di-Fant <quentin(dot)difant(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to add a new psql command ?
Date: 2019-02-07 11:02:16
Message-ID: CAFj8pRBc_k40EndNSb3J5SfM_whwP3wfqUS0Uc0nM=AH9m6HzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

čt 7. 2. 2019 v 11:40 odesílatel Quentin Di-Fant <quentin(dot)difant(at)gmail(dot)com>
napsal:

> Hello,
>
> I was wondering : is it possible to add directly a new psql command which
> can be run anytime in our PostgreSQL interpreter like any other normal psql
> commands ?
>
> I explain myself : in the PostgreSQL interpreter, when the command "\h" or
> "\help" is written in the shell, we can see all the commands we have at our
> disposal. We can also of course write our proper functions, in python
> scripts for example, and run them direclty in one of our databases. But I
> was wondering if it was possible to add directly a command, like \copy,
> \select, .... For example, let's say I create a new command called \resume
> which will call my own-made python script, and I would want this command to
> be part of the list of commands we see when we type \h.
>
> Is it even possible ? And if it's possible, how can I achieve that ?
>
> Thanks for your attention and I thank you in advance for all the
> informations you will possibly give me.
>

It is not possible. psql is not designed to be enhanced.

you can use psql variables for this purpose partially

postgres=# \set x 'select 1;'
postgres=# :x
┌──────────┐
│ ?column? │
╞══════════╡
│ 1 │
└──────────┘
(1 row)

> Cordially.
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Wampler 2019-02-07 16:28:59 Odd messages on reloading DB table
Previous Message Quentin Di-Fant 2019-02-07 10:39:38 How to add a new psql command ?