From a16c467898f5579f4961bdfe6db5dd3c52e5820a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Tue, 8 Jul 2025 19:23:00 +0100
Subject: [PATCH 3/3] Add tab completion for large object OIDs

For GRANT, REVOKE, \lo_unlink and \lo_export.

This is less useful than names, but might still be handy.
---
 src/bin/psql/tab-complete.in.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 922895d0d0f..227747d9897 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -978,6 +978,11 @@ static const SchemaQuery Query_for_trigger_of_table = {
 	.refnamespace = "c1.relnamespace",
 };
 
+static SchemaQuery Query_for_list_of_large_objects = {
+	.catname = "pg_catalog.pg_largeobject_metadata lom",
+	.result = "lom.oid::pg_catalog.text",
+};
+
 
 /*
  * Queries to get lists of names of various kinds of things, possibly
@@ -4552,6 +4557,9 @@ match_previous_words(int pattern_id,
 		else
 			COMPLETE_WITH("FROM");
 	}
+	else if (TailMatches("GRANT|REVOKE", MatchAny, "ON", "LARGE", "OBJECT") ||
+			 TailMatches("REVOKE", "GRANT", "OPTION", "FOR", MatchAny, "ON", "LARGE", "OBJECT"))
+		COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(Query_for_list_of_large_objects);
 
 	/*
 	 * Complete "GRANT/REVOKE ... TO/FROM" with username, PUBLIC,
@@ -5406,6 +5414,8 @@ match_previous_words(int pattern_id,
 	}
 	else if (TailMatchesCS("\\l*") && !TailMatchesCS("\\lo*"))
 		COMPLETE_WITH_QUERY(Query_for_list_of_databases);
+	else if (TailMatchesCS("\\lo_unlink|\\lo_export"))
+		COMPLETE_WITH_SCHEMA_QUERY_VERBATIM(Query_for_list_of_large_objects);
 	else if (TailMatchesCS("\\password"))
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 	else if (TailMatchesCS("\\pset"))
-- 
2.50.0

