0001 ---
0002 layout: global
0003 title: DESCRIBE QUERY
0004 displayTitle: DESCRIBE QUERY
0005 license: |
0006 Licensed to the Apache Software Foundation (ASF) under one or more
0007 contributor license agreements. See the NOTICE file distributed with
0008 this work for additional information regarding copyright ownership.
0009 The ASF licenses this file to You under the Apache License, Version 2.0
0010 (the "License"); you may not use this file except in compliance with
0011 the License. You may obtain a copy of the License at
0012
0013 http://www.apache.org/licenses/LICENSE-2.0
0014
0015 Unless required by applicable law or agreed to in writing, software
0016 distributed under the License is distributed on an "AS IS" BASIS,
0017 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0018 See the License for the specific language governing permissions and
0019 limitations under the License.
0020 ---
0021
0022 ### Description
0023
0024 The `DESCRIBE QUERY` statement is used to return the metadata of output
0025 of a query. A shorthand `DESC` may be used instead of `DESCRIBE` to
0026 describe the query output.
0027
0028 ### Syntax
0029
0030 ```sql
0031 { DESC | DESCRIBE } [ QUERY ] input_statement
0032 ```
0033
0034 ### Parameters
0035
0036 * **QUERY**
0037 This clause is optional and may be omitted.
0038
0039 * **input_statement**
0040
0041 Specifies a result set producing statement and may be one of the following:
0042
0043 * a `SELECT` statement
0044 * a `CTE(Common table expression)` statement
0045 * an `INLINE TABLE` statement
0046 * a `TABLE` statement
0047 * a `FROM` statement`
0048
0049 Please refer to [select-statement](sql-ref-syntax-qry-select.html)
0050 for a detailed syntax of the query parameter.
0051
0052 ### Examples
0053
0054 ```sql
0055 -- Create table `person`
0056 CREATE TABLE person (name STRING , age INT COMMENT 'Age column', address STRING);
0057
0058 -- Returns column metadata information for a simple select query
0059 DESCRIBE QUERY SELECT age, sum(age) FROM person GROUP BY age;
0060 +--------+---------+----------+
0061 |col_name|data_type| comment|
0062 +--------+---------+----------+
0063 | age| int|Age column|
0064 |sum(age)| bigint| null|
0065 +--------+---------+----------+
0066
0067 -- Returns column metadata information for common table expression (`CTE`).
0068 DESCRIBE QUERY WITH all_names_cte
0069 AS (SELECT name from person) SELECT * FROM all_names_cte;
0070 +--------+---------+-------+
0071 |col_name|data_type|comment|
0072 +--------+---------+-------+
0073 | name| string| null|
0074 +--------+---------+-------+
0075
0076 -- Returns column metadata information for an inline table.
0077 DESC QUERY VALUES(100, 'John', 10000.20D) AS employee(id, name, salary);
0078 +--------+---------+-------+
0079 |col_name|data_type|comment|
0080 +--------+---------+-------+
0081 | id| int| null|
0082 | name| string| null|
0083 | salary| double| null|
0084 +--------+---------+-------+
0085
0086 -- Returns column metadata information for `TABLE` statement.
0087 DESC QUERY TABLE person;
0088 +--------+---------+----------+
0089 |col_name|data_type| comment|
0090 +--------+---------+----------+
0091 | name| string| null|
0092 | age| int| Agecolumn|
0093 | address| string| null|
0094 +--------+---------+----------+
0095
0096 -- Returns column metadata information for a `FROM` statement.
0097 -- `QUERY` clause is optional and can be omitted.
0098 DESCRIBE FROM person SELECT age;
0099 +--------+---------+----------+
0100 |col_name|data_type| comment|
0101 +--------+---------+----------+
0102 | age| int| Agecolumn|
0103 +--------+---------+----------+
0104 ```
0105
0106 ### Related Statements
0107
0108 * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html)
0109 * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html)
0110 * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html)