Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertica, describe table

Tags:

python

vertica

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?

like image 533
Opperix Avatar asked Dec 12 '22 03:12

Opperix


1 Answers

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.

like image 81
Guillaume Avatar answered Dec 13 '22 17:12

Guillaume