aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/exchange_do_comment_partitioned_table.sql
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-06-03 21:14:03 +0200
committerChristian Grothoff <christian@grothoff.org>2024-07-29 12:18:42 +0200
commit5686dd370a535cd2fc4d03ed3fee2c590343cc6f (patch)
treed0121f222200777927e6684d866dd8059f861e88 /src/exchangedb/exchange_do_comment_partitioned_table.sql
parent34e461f8233f416b10ca55a10951e799a6f74943 (diff)
fix DB init for v5
Diffstat (limited to 'src/exchangedb/exchange_do_comment_partitioned_table.sql')
-rw-r--r--src/exchangedb/exchange_do_comment_partitioned_table.sql40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/exchangedb/exchange_do_comment_partitioned_table.sql b/src/exchangedb/exchange_do_comment_partitioned_table.sql
new file mode 100644
index 000000000..cfde7ef4f
--- /dev/null
+++ b/src/exchangedb/exchange_do_comment_partitioned_table.sql
@@ -0,0 +1,40 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION comment_partitioned_table(
+ IN table_comment TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON TABLE %s IS %s'
+ ,table_name
+ ,quote_literal(table_comment)
+ );
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_table
+ IS 'Generic function to create a comment on table that is partitioned.';