'Vertica, describe table
I have a vertica database and I need to describe some tables. In MySQL you use describe table_name
. And I know that in vertica it's \d table_name
.
Also I need to do it throw python, but when I make query:
cur.execute("\d table_name")
I get this problem:
vertica_python.errors.VerticaSyntaxError: Severity: ERROR, Message: Syntax error at or near "\", Sqlstate: 42601, Position: 1, Routine: base_yyerror, File: /scratch_a/release/vbuild/vertica/Parser/scan.l, Line: 1004, SQL: '\\d table_name'
Is there another way to get columns and columns type in vertica?
Solution 1:[1]
Why your query fails:
The \d
command is a specificity of vsql, this is not valid SQL you can use use via ODBC or JDBC for instance.
You have 3 options. First the one you already put in comment:
SELECT *
FROM v_catalog.columns
WHERE table_schema='schema'
AND table_name='table'
ORDER BY ordinal_position;`
The second option is to export the object, which will give you the full create statement, including projections:
SELECT export_objects('', 'schema.table');
The third option is to export the table, which only provides the table definition:
SELECT EXPORT_TABLES('', 'schema.table');
The first set of double quotes says to print the output on STDOUT, the second is the table (or schema or all the objects) you want to export.
Solution 2:[2]
you can use \d or get it using below dictionary table
select column_name, table_name
from v_catalog.columns
where column_name ilike '<column_name>'
and table_schema ilike '<table_name>'
order by column_name;
you can also add more attributes based on the required information that you need.
Solution 3:[3]
There are many ways to describe tables in vertica but easiest is like this:
\d table_name;
\dt tablw_name;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Josef Panerio |
Solution 3 | 100rabh |