pgsql.sql 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. DO $$
  2. DECLARE
  3. rec RECORD;
  4. max_id BIGINT;
  5. BEGIN
  6. FOR rec IN (
  7. SELECT
  8. t.table_name AS table_name,
  9. c.column_name AS column_name,
  10. regexp_replace(
  11. c.column_default,
  12. '^nextval\(''([^'']+)''::regclass\)$',
  13. '\1'
  14. ) AS seq_name
  15. FROM
  16. information_schema.columns c
  17. JOIN
  18. information_schema.tables t ON c.table_name = t.table_name
  19. WHERE
  20. t.table_type = 'BASE TABLE'
  21. AND c.column_default LIKE 'nextval(''%''::regclass)'
  22. AND t.table_schema = 'public'
  23. ) LOOP
  24. EXECUTE format('SELECT COALESCE(MAX(%I), 0) FROM %I', rec.column_name, rec.table_name)
  25. INTO max_id;
  26. EXECUTE format('SELECT setval(''%s'', %s)', rec.seq_name, max_id + 1);
  27. RAISE NOTICE '调整序列: % (表: %,字段: %),新值: %',
  28. rec.seq_name, rec.table_name, rec.column_name, max_id + 1;
  29. END LOOP;
  30. END $$;
  31. --
  32. CREATE INDEX idx_zt_searchindex_fts
  33. ON zt_searchindex
  34. USING gin(
  35. to_tsvector('pg_catalog.english',
  36. coalesce(title, '') || ' ' || coalesce(content, '')
  37. )
  38. );