public inbox for [email protected]help / color / mirror / Atom feed
[PATCH v2 1/1] Add descriptions for psql's large object backslash commands. 10+ messages / 6 participants [nested] [flat]
* [PATCH v2 1/1] Add descriptions for psql's large object backslash commands. @ 2022-06-02 21:35 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Nathan Bossart @ 2022-06-02 21:35 UTC (permalink / raw) These should be mostly self-explanatory, but they are the only backslash commands lacking individual short descriptions. Author: Thibaud W. Reviewed by: Nathan Bossart Description: https://postgr.es/m/43f0439c-df3e-a045-ac99-af33523cc2d4%40dalibo.com --- src/bin/psql/help.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 49eb116f33..54580ac928 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -321,10 +321,10 @@ slashUsage(unsigned short int pager) fprintf(output, "\n"); fprintf(output, _("Large Objects\n")); - fprintf(output, _(" \\lo_export LOBOID FILE\n" - " \\lo_import FILE [COMMENT]\n" - " \\lo_list[+]\n" - " \\lo_unlink LOBOID large object operations\n")); + fprintf(output, _(" \\lo_export LOBOID FILE export large object to file\n" + " \\lo_import FILE [COMMENT] import large object from file\n" + " \\lo_list[+] list large objects\n" + " \\lo_unlink LOBOID delete a large object\n")); ClosePager(output); } -- 2.25.1 --/04w6evG8XlLl3ft-- ^ permalink raw reply [nested|flat] 10+ messages in thread
* not fully correct error message @ 2026-01-01 07:10 Pavel Stehule <[email protected]> 0 siblings, 1 reply; 10+ messages in thread From: Pavel Stehule @ 2026-01-01 07:10 UTC (permalink / raw) To: PostgreSQL Hackers <[email protected]> Hi I tested one use case, and maybe I found little bit possible error message create procedure test() as $$ begin vacuum; end; $$ language plpgsql; (2026-01-01 08:04:05) postgres=# call test(); ERROR: 25001: VACUUM cannot be executed from a function CONTEXT: SQL statement "vacuum" PL/pgSQL function test() line 3 at SQL statement LOCATION: PreventInTransactionBlock, xact.c:3695 (2026-01-01 08:09:18) postgres=# should be "VACUUM cannot be executed from a function or a procedure" instead ? Regards Pavel ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-01 10:05 jian he <[email protected]> parent: Pavel Stehule <[email protected]> 0 siblings, 1 reply; 10+ messages in thread From: jian he @ 2026-01-01 10:05 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> On Thu, Jan 1, 2026 at 3:10 PM Pavel Stehule <[email protected]> wrote: > > Hi > > I tested one use case, and maybe I found little bit possible error message > > create procedure test() > as $$ > begin > vacuum; > end; > $$ language plpgsql; > > (2026-01-01 08:04:05) postgres=# call test(); > ERROR: 25001: VACUUM cannot be executed from a function > CONTEXT: SQL statement "vacuum" > PL/pgSQL function test() line 3 at SQL statement > LOCATION: PreventInTransactionBlock, xact.c:3695 > (2026-01-01 08:09:18) postgres=# > > should be "VACUUM cannot be executed from a function or a procedure" instead ? > hi. "VACUUM cannot be executed from a function or a procedure" looks good to me. similarly, in ExecWaitStmt we have: ereport(ERROR, errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("WAIT FOR must be only called without an active or registered snapshot"), errdetail("WAIT FOR cannot be executed from a function or a procedure or within a transaction with an isolation level higher than READ COMMITTED.")); PreventInTransactionBlock is used in so many places, but this error message: `` (errmsg("%s cannot be executed from a function", stmtType))); `` only appears once in the regress tests. maybe we can add some dummy tests for it. ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 06:34 Pavel Stehule <[email protected]> parent: jian he <[email protected]> 0 siblings, 2 replies; 10+ messages in thread From: Pavel Stehule @ 2026-01-03 06:34 UTC (permalink / raw) To: jian he <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> Hi čt 1. 1. 2026 v 11:05 odesílatel jian he <[email protected]> napsal: > On Thu, Jan 1, 2026 at 3:10 PM Pavel Stehule <[email protected]> > wrote: > > > > Hi > > > > I tested one use case, and maybe I found little bit possible error > message > > > > create procedure test() > > as $$ > > begin > > vacuum; > > end; > > $$ language plpgsql; > > > > (2026-01-01 08:04:05) postgres=# call test(); > > ERROR: 25001: VACUUM cannot be executed from a function > > CONTEXT: SQL statement "vacuum" > > PL/pgSQL function test() line 3 at SQL statement > > LOCATION: PreventInTransactionBlock, xact.c:3695 > > (2026-01-01 08:09:18) postgres=# > > > > should be "VACUUM cannot be executed from a function or a procedure" > instead ? > > > > hi. > "VACUUM cannot be executed from a function or a procedure" > looks good to me. > > similarly, in ExecWaitStmt we have: > ereport(ERROR, > errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), > errmsg("WAIT FOR must be only called without an active > or registered snapshot"), > errdetail("WAIT FOR cannot be executed from a function > or a procedure or within a transaction with an isolation level higher > than READ COMMITTED.")); > > PreventInTransactionBlock is used in so many places, but this error > message: > `` > (errmsg("%s cannot be executed from a function", stmtType))); > `` > only appears once in the regress tests. > maybe we can add some dummy tests for it. > here is a patch (with small regress test) Regards Pavel Attachments: [text/x-patch] 0001-VACUUM-cannot-be-executed-inside-a-function-or-a-pro.patch (2.6K, ../../CAFj8pRBoybDsAZdQJ3nz=E1uCSu3Buoa+VXM8wnwy6ixKqzYxA@mail.gmail.com/3-0001-VACUUM-cannot-be-executed-inside-a-function-or-a-pro.patch) download | inline diff: From aa57e3a80e5ee7bce121addc607d198e67941fc7 Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Sat, 3 Jan 2026 07:32:26 +0100 Subject: [PATCH] VACUUM cannot be executed inside a function or a procedure --- src/backend/access/transam/xact.c | 2 +- .../plpgsql/src/expected/plpgsql_transaction.out | 13 +++++++++++++ src/pl/plpgsql/src/sql/plpgsql_transaction.sql | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 842faa44232..5cf85e2f35c 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3695,7 +3695,7 @@ PreventInTransactionBlock(bool isTopLevel, const char *stmtType) ereport(ERROR, (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION), /* translator: %s represents an SQL statement name */ - errmsg("%s cannot be executed from a function", stmtType))); + errmsg("%s cannot be executed from a function or a procedure", stmtType))); /* If we got past IsTransactionBlock test, should be in default state */ if (CurrentTransactionState->blockState != TBLOCK_DEFAULT && diff --git a/src/pl/plpgsql/src/expected/plpgsql_transaction.out b/src/pl/plpgsql/src/expected/plpgsql_transaction.out index adff10fa6d6..bcdf7958823 100644 --- a/src/pl/plpgsql/src/expected/plpgsql_transaction.out +++ b/src/pl/plpgsql/src/expected/plpgsql_transaction.out @@ -736,6 +736,19 @@ SELECT * FROM test1; 2 | (2 rows) +-- VACUUM cannot be executed inside a function or a procedure +CREATE PROCEDURE vacuum_inside_procedure() +LANGUAGE plpgsql AS $$ +BEGIN + VACUUM; +END; +$$; +-- error +CALL vacuum_inside_procedure(); +ERROR: VACUUM cannot be executed from a function or a procedure +CONTEXT: SQL statement "VACUUM" +PL/pgSQL function vacuum_inside_procedure() line 3 at SQL statement +DROP PROCEDURE vacuum_inside_procedure(); DROP TABLE test1; DROP TABLE test2; DROP TABLE test3; diff --git a/src/pl/plpgsql/src/sql/plpgsql_transaction.sql b/src/pl/plpgsql/src/sql/plpgsql_transaction.sql index c73fca7e03e..5e8da3ec4c4 100644 --- a/src/pl/plpgsql/src/sql/plpgsql_transaction.sql +++ b/src/pl/plpgsql/src/sql/plpgsql_transaction.sql @@ -631,6 +631,20 @@ $$; SELECT * FROM test1; +-- VACUUM cannot be executed inside a function or a procedure + +CREATE PROCEDURE vacuum_inside_procedure() +LANGUAGE plpgsql AS $$ +BEGIN + VACUUM; +END; +$$; + +-- error +CALL vacuum_inside_procedure(); + +DROP PROCEDURE vacuum_inside_procedure(); + DROP TABLE test1; DROP TABLE test2; DROP TABLE test3; -- 2.52.0 ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 11:35 Andreas Karlsson <[email protected]> parent: Pavel Stehule <[email protected]> 1 sibling, 0 replies; 10+ messages in thread From: Andreas Karlsson @ 2026-01-03 11:35 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; jian he <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]> On 1/3/26 7:34 AM, Pavel Stehule wrote: > here is a patch (with small regress test) Looks like a good change to me since the obvious question many people would ask themselves after seeing this error is if running it in a procedure would work instead and it does not. And this error message changes saves those people time which is a great thing. Tried out this patch and it worked and, as expected, also improved the error for other commands like CREATE DATABASE and REINDEX CONCURRENTLY so when this is commit the commit message should make it clear this is not just about VACUUM. A small suggestion is to change the message from: "%s cannot be executed from a function or a procedure" to: "%s cannot be executed from a function or procedure" I am not a native speaker but I think the second flows better. Andreas ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 12:22 Marcos Pegoraro <[email protected]> parent: Pavel Stehule <[email protected]> 1 sibling, 2 replies; 10+ messages in thread From: Marcos Pegoraro @ 2026-01-03 12:22 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; +Cc: jian he <[email protected]>; PostgreSQL Hackers <[email protected]> Em sáb., 3 de jan. de 2026 às 03:35, Pavel Stehule <[email protected]> escreveu: > here is a patch (with small regress test) > An anonymous block doesn't accept vacuum too. Wouldn't it be better to specify what kind of block you are running instead of function, procedure or anonymous block ? regards Marcos ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 12:34 Pavel Stehule <[email protected]> parent: Marcos Pegoraro <[email protected]> 1 sibling, 0 replies; 10+ messages in thread From: Pavel Stehule @ 2026-01-03 12:34 UTC (permalink / raw) To: Marcos Pegoraro <[email protected]>; +Cc: jian he <[email protected]>; PostgreSQL Hackers <[email protected]> so 3. 1. 2026 v 13:23 odesílatel Marcos Pegoraro <[email protected]> napsal: > Em sáb., 3 de jan. de 2026 às 03:35, Pavel Stehule < > [email protected]> escreveu: > >> here is a patch (with small regress test) >> > > An anonymous block doesn't accept vacuum too. > Wouldn't it be better to specify what kind of block you are running > instead of > function, procedure or anonymous block ? > It is correct, but maybe too long. Generally, there is a term "routine" as a synonym for "function, procedure or any stored procedure code", but I am not sure how much is accepted by the community > regards > Marcos > ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 12:39 Andreas Karlsson <[email protected]> parent: Marcos Pegoraro <[email protected]> 1 sibling, 1 reply; 10+ messages in thread From: Andreas Karlsson @ 2026-01-03 12:39 UTC (permalink / raw) To: Marcos Pegoraro <[email protected]>; Pavel Stehule <[email protected]>; +Cc: jian he <[email protected]>; PostgreSQL Hackers <[email protected]> On 1/3/26 1:22 PM, Marcos Pegoraro wrote: > Em sáb., 3 de jan. de 2026 às 03:35, Pavel Stehule > <[email protected] <mailto:[email protected]>> escreveu: > > here is a patch (with small regress test) > > > An anonymous block doesn't accept vacuum too. > Wouldn't it be better to specify what kind of block you are running > instead of > function, procedure or anonymous block ? Maybe out of some kind of correctness, but it seems less useful to me since the obvious question an end user would ask after trying to run VACUUM in a function is if they can do so in a procedure instead so we may as well tell them right away. A potential third option would be to take your solution but to add a HINT about that it needs to run as a top-level statement outside any transactions, but I kinda liked how simple the original patch was. Andreas ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 18:03 Tom Lane <[email protected]> parent: Andreas Karlsson <[email protected]> 0 siblings, 1 reply; 10+ messages in thread From: Tom Lane @ 2026-01-03 18:03 UTC (permalink / raw) To: Andreas Karlsson <[email protected]>; +Cc: Marcos Pegoraro <[email protected]>; Pavel Stehule <[email protected]>; jian he <[email protected]>; PostgreSQL Hackers <[email protected]> Andreas Karlsson <[email protected]> writes: > On 1/3/26 1:22 PM, Marcos Pegoraro wrote: >> Em sáb., 3 de jan. de 2026 às 03:35, Pavel Stehule >> <[email protected] <mailto:[email protected]>> escreveu: >>> here is a patch (with small regress test) >> An anonymous block doesn't accept vacuum too. >> Wouldn't it be better to specify what kind of block you are running >> instead of function, procedure or anonymous block ? I don't think PreventInTransactionBlock has ready access to that information. > A potential third option would be to take your solution but to add a > HINT about that it needs to run as a top-level statement outside any > transactions, but I kinda liked how simple the original patch was. Yeah, I like just adding "or procedure" and calling it good. I do not think we need a regression test, either ... Poking around, I also found this: src/backend/commands/wait.c: errdetail("WAIT FOR cannot be executed from a function or a procedure or within a transaction with an isolation level higher than READ COMMITTED.")); which is also not great grammar. What do you think of "WAIT FOR cannot be executed from a function or procedure, nor within a transaction with an isolation level higher than READ COMMITTED." ? regards, tom lane ^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: not fully correct error message @ 2026-01-03 18:44 Andreas Karlsson <[email protected]> parent: Tom Lane <[email protected]> 0 siblings, 0 replies; 10+ messages in thread From: Andreas Karlsson @ 2026-01-03 18:44 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: Marcos Pegoraro <[email protected]>; Pavel Stehule <[email protected]>; jian he <[email protected]>; PostgreSQL Hackers <[email protected]> On 1/3/26 7:03 PM, Tom Lane wrote: > Andreas Karlsson <[email protected]> writes: >> A potential third option would be to take your solution but to add a >> HINT about that it needs to run as a top-level statement outside any >> transactions, but I kinda liked how simple the original patch was. > > Yeah, I like just adding "or procedure" and calling it good. > I do not think we need a regression test, either ... Yeah, let's keep it simple. > Poking around, I also found this: > > src/backend/commands/wait.c: errdetail("WAIT FOR cannot be executed from a function or a procedure or within a transaction with an isolation level higher than READ COMMITTED.")); > > which is also not great grammar. What do you think of "WAIT FOR > cannot be executed from a function or procedure, nor within a > transaction with an isolation level higher than READ COMMITTED." ? Much better! Andreas ^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2026-01-03 18:44 UTC | newest] Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-06-02 21:35 [PATCH v2 1/1] Add descriptions for psql's large object backslash commands. Nathan Bossart <[email protected]> 2026-01-01 07:10 not fully correct error message Pavel Stehule <[email protected]> 2026-01-01 10:05 ` Re: not fully correct error message jian he <[email protected]> 2026-01-03 06:34 ` Re: not fully correct error message Pavel Stehule <[email protected]> 2026-01-03 11:35 ` Re: not fully correct error message Andreas Karlsson <[email protected]> 2026-01-03 12:22 ` Re: not fully correct error message Marcos Pegoraro <[email protected]> 2026-01-03 12:34 ` Re: not fully correct error message Pavel Stehule <[email protected]> 2026-01-03 12:39 ` Re: not fully correct error message Andreas Karlsson <[email protected]> 2026-01-03 18:03 ` Re: not fully correct error message Tom Lane <[email protected]> 2026-01-03 18:44 ` Re: not fully correct error message Andreas Karlsson <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox