Vertica, describe table

Opperix picture Opperix · Oct 16, 2014 · Viewed 10.6k times · Source

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?

Answer

Guillaume picture Guillaume · Oct 16, 2014

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.