SHOW PARTITIONS

Description

The SHOW PARTITIONS statement is used to list partitions of a table. An optional partition spec may be specified to return the partitions matching the supplied partition spec.

Syntax

  1. SHOW PARTITIONS table_identifier [ partition_spec ]

Parameters

  • table_identifier

    Specifies a table name, which may be optionally qualified with a database name.

    Syntax: [ database_name. ] table_name

  • partition_spec

    An optional parameter that specifies a comma separated list of key and value pairs for partitions. When specified, the partitions that match the partition specification are returned.

    Syntax: PARTITION ( partition_col_name = partition_col_val [ , ... ] )

Examples

  1. -- create a partitioned table and insert a few rows.
  2. USE salesdb;
  3. CREATE TABLE customer(id INT, name STRING) PARTITIONED BY (state STRING, city STRING);
  4. INSERT INTO customer PARTITION (state = 'CA', city = 'Fremont') VALUES (100, 'John');
  5. INSERT INTO customer PARTITION (state = 'CA', city = 'San Jose') VALUES (200, 'Marry');
  6. INSERT INTO customer PARTITION (state = 'AZ', city = 'Peoria') VALUES (300, 'Daniel');
  7. -- Lists all partitions for table `customer`
  8. SHOW PARTITIONS customer;
  9. +----------------------+
  10. | partition|
  11. +----------------------+
  12. | state=AZ/city=Peoria|
  13. | state=CA/city=Fremont|
  14. |state=CA/city=San Jose|
  15. +----------------------+
  16. -- Lists all partitions for the qualified table `customer`
  17. SHOW PARTITIONS salesdb.customer;
  18. +----------------------+
  19. | partition|
  20. +----------------------+
  21. | state=AZ/city=Peoria|
  22. | state=CA/city=Fremont|
  23. |state=CA/city=San Jose|
  24. +----------------------+
  25. -- Specify a full partition spec to list specific partition
  26. SHOW PARTITIONS customer PARTITION (state = 'CA', city = 'Fremont');
  27. +---------------------+
  28. | partition|
  29. +---------------------+
  30. |state=CA/city=Fremont|
  31. +---------------------+
  32. -- Specify a partial partition spec to list the specific partitions
  33. SHOW PARTITIONS customer PARTITION (state = 'CA');
  34. +----------------------+
  35. | partition|
  36. +----------------------+
  37. | state=CA/city=Fremont|
  38. |state=CA/city=San Jose|
  39. +----------------------+
  40. -- Specify a partial spec to list specific partition
  41. SHOW PARTITIONS customer PARTITION (city = 'San Jose');
  42. +----------------------+
  43. | partition|
  44. +----------------------+
  45. |state=CA/city=San Jose|
  46. +----------------------+