idea - proposal - defining own psql commands - Mailing list pgsql-hackers

From Pavel Stehule
Subject idea - proposal - defining own psql commands
Date
Msg-id CAFj8pRBzrf+uZ=e_MNu9oeFqEzA=jv1CC7jYzVWvSkrX_vpUzg@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi

long time we are think how to allow add some custom commands in psql. I had a following idea

1. psql can has special buffer for custom queries. This buffer can be filled by special command \gdefq. This command will have two parameters - name and number of arguments.

some like

select * from pg_class where relname = :'_first' \gdefcq m1 1
select * from pg_class where relnamespace = :_first::regnamespace and rename = :'_second' \gdefcq m1 2

the custom queries can be executed via doubled backslash like

\\m1 pg_proc
\\m1 pg_catalog pg_proc

the runtime will count number of parameters and chose variant with selected name and same number of arguments. Next, it save parameters to variables like _first, _second. Last step is query execution.

What do you think about this?

Regards

Pavel

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Adding percentile metrics to pg_stat_statements module
Next
From: Mark Dilger
Date:
Subject: Re: RFC: split OBJS lines to one object per line