generate_links_table_stats.sh 920 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. set -e
  3. source env.sh
  4. OUTPUT="logs/links_table_stats.log"
  5. echo "📊 Genereerin statistika kõigile links_* tabelitele skeemis ${destination_schema}" | tee "$OUTPUT"
  6. QUERY=$(psql ${CONNECTION_NAME} -d ${destination_dbname} -tA -c "
  7. SELECT string_agg(
  8. format(
  9. 'SELECT %L AS table_name, COUNT(*) AS total_rows, COUNT(DISTINCT ST_AsText(geom)) AS unique_geoms,
  10. (COUNT(*) - COUNT(DISTINCT ST_AsText(geom))) AS diff_rows FROM %I.%I',
  11. tablename, '${destination_schema}', tablename
  12. ),
  13. ' UNION ALL '
  14. )
  15. FROM pg_tables
  16. WHERE schemaname = '${destination_schema}'
  17. AND tablename LIKE 'links_%'
  18. AND tablename NOT IN ('links_vertices', 'links')
  19. AND tablename ~ '^links_[0-9]+$';
  20. ")
  21. #echo -e "\nKäivitan SQL-i:\n$QUERY\n" | tee -a "$OUTPUT"
  22. psql ${CONNECTION_NAME} -d ${destination_dbname} -c "$QUERY" | tee -a "$OUTPUT"
  23. echo -e "\n✅ Tulemused salvestatud faili: $OUTPUT"