Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. sql_template="CREATE TABLE new_table (LIKE history INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES);
  2. SELECT create_hypertable('new_table', 'time', chunk_time_interval => interval ':day_num day', migrate_data => TRUE );
  3. INSERT INTO new_table SELECT * FROM :table_name;
  4. DROP TABLE :table_name;
  5. ALTER TABLE new_table RENAME TO :table_name"
  6.  
  7. declare -a sql_config=(("history" 2) ("history_uint" 2) ("trends" 14") ("trends_uint" 14))
  8. # proste pole poli, protoze bash nema asociativni pole (mapu)
  9. for config in sql_config; do
  10.    sql=${sql_template/:table_one/$config[0]}
  11.     sql=$(sql/:day_num/$config[1])
  12.     psql -U user -d db -c sql
  13. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement