pgcli.slt 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. # this file contains queries that are used by pgcli
  10. # this query returns 150+ rows and could be subject to frequent change
  11. # rather than executing QUERY TTTTBT, just make sure that it does not fail
  12. statement OK
  13. SELECT
  14. nsp.nspname AS schema_name,
  15. cls.relname AS table_name,
  16. att.attname AS column_name,
  17. att.atttypid::REGTYPE::STRING AS type_name,
  18. att.atthasdef AS has_default,
  19. pg_catalog.pg_get_expr(def.adbin, def.adrelid, true) AS default
  20. FROM
  21. pg_catalog.pg_attribute AS att
  22. INNER JOIN pg_catalog.pg_class AS cls ON att.attrelid = cls.oid
  23. INNER JOIN pg_catalog.pg_namespace AS nsp ON cls.relnamespace = nsp.oid
  24. LEFT JOIN pg_attrdef AS def ON
  25. def.adrelid = att.attrelid AND def.adnum = att.attnum
  26. WHERE
  27. cls.relkind = ANY (ARRAY['r', 'p', 'f'])
  28. AND NOT att.attisdropped
  29. AND att.attnum > 0
  30. ORDER BY
  31. 1, 2, att.attnum