exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

exchange_do_create_partitioned_table.sql (1610B)


      1 --
      2 -- This file is part of TALER
      3 -- Copyright (C) 2014--2022 Taler Systems SA
      4 --
      5 -- TALER is free software; you can redistribute it and/or modify it under the
      6 -- terms of the GNU General Public License as published by the Free Software
      7 -- Foundation; either version 3, or (at your option) any later version.
      8 --
      9 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11 -- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 --
     13 -- You should have received a copy of the GNU General Public License along with
     14 -- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 --
     16 
     17 
     18 CREATE OR REPLACE FUNCTION create_partitioned_table(
     19    IN table_definition TEXT -- SQL template for table creation
     20   ,IN table_name TEXT -- base name of the table
     21   ,IN main_table_partition_str TEXT -- declaration for how to partition the table
     22   ,IN partition_suffix TEXT DEFAULT NULL -- NULL: no partitioning, 0: yes partitioning, no sharding, >0: sharding
     23 )
     24 RETURNS VOID
     25 LANGUAGE plpgsql
     26 AS $$
     27 BEGIN
     28   IF (partition_suffix IS NULL)
     29   THEN
     30     -- no partitioning, disable option
     31     main_table_partition_str = '';
     32   ELSE
     33     IF (partition_suffix::int > 0)
     34     THEN
     35       -- sharding, add shard name
     36       table_name=table_name || '_' || partition_suffix;
     37     END IF;
     38   END IF;
     39   EXECUTE FORMAT(
     40     table_definition,
     41     table_name,
     42     main_table_partition_str
     43   );
     44 END $$;
     45 
     46 COMMENT ON FUNCTION create_partitioned_table
     47   IS 'Generic function to create a table that is partitioned or sharded.';