orms.td 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. $ set-regex match=s\d+ replacement=<SID>
  10. > CREATE TABLE t (i bigint, t text);
  11. > CREATE DEFAULT INDEX ON t;
  12. > SELECT i.relname as relname, ix.indisunique, ix.indexprs, a.attname, a.attnum, c.conrelid, ix.indkey::varchar, ix.indoption::varchar, i.reloptions, am.amname, pg_get_expr(ix.indpred, ix.indrelid), NULL as indnkeyatts
  13. FROM pg_class t
  14. JOIN pg_index ix on t.oid = ix.indrelid
  15. JOIN pg_class i on i.oid = ix.indexrelid
  16. LEFT OUTER JOIN pg_attribute a on t.oid = a.attrelid and a.attnum = ANY(ix.indkey)
  17. LEFT OUTER JOIN pg_constraint c on (ix.indrelid = c.conrelid and ix.indexrelid = c.conindid and c.contype in ('p', 'u', 'x'))
  18. LEFT OUTER JOIN pg_am am on i.relam = am.oid
  19. WHERE t.relkind IN ('r', 'v', 'f', 'm', 'p') and t.oid = 't'::regclass and ix.indisprimary = 'f'
  20. ORDER BY t.relname, i.relname;
  21. t_primary_idx false <null> i 1 <null> "1 2" "0 0" <null> <null> <null> <null>
  22. t_primary_idx false <null> t 2 <null> "1 2" "0 0" <null> <null> <null> <null>
  23. # Check how expressions are serialized with `{}`
  24. > CREATE INDEX complex_index ON t (t::varchar, i::string);
  25. > SELECT ix.indexprs
  26. FROM pg_class t
  27. JOIN pg_index ix ON t.oid = ix.indrelid
  28. WHERE t.oid = 't'::regclass AND ix.indexrelid = 'complex_index'::regclass;
  29. "{t::[<SID> AS pg_catalog.varchar]}, {i::[<SID> AS pg_catalog.text]}"