Programmatically get column lengths using vertica_python driver

Hi there,

Is it possible to run commands like "\d schema.table_name;" through vertica_python? I run into the following error indicating it doesn't like the leading backslash:

 

vertica_python.errors.VerticaSyntaxError: Severity: ERROR, Message: Syntax error at or near "\", Sqlstate: 42601, Position: 1, Routine: base_yyerror, File: /scratch_a/release/svrtar9988/vbuild/vertica/Parser/scan.l, Line: 1043, SQL: '\\d schema.table_name;'

 

I'm essentially trying to get the lengths of a few VARCHAR columns in my program. I could always put the command in a file, run "vertica -f my_file > out_file" and parse the out_file but I'm lookng for a better way.

Comments

  • Hi!

     

    Example:

     

    >>> import hp_vertica_client as connector
    >>> db = connector.connect(database='test')
    >>> cursor = db.cursor()
    >>> cursor.execute("select 'abc'::varchar(66), 'vertica'::varchar(123)")
    >>> result = cursor.fetchall()
    >>> result
    [('abc', 'vertica')]
    >>> cursor.description
    (column(name='?column?', type_code=9, display_size=None, internal_size=66, precision=None, scale=None, null_ok=True), column(name='?column?', type_code=9, display_size=None, internal_size=123, precision=None, scale=None, null_ok=True))
    >>> cursor.execute("select 'abc'::varchar(66) as col_01, 'vertica'::varchar(123) as col_02")
    >>> cursor.description
    (column(name='col_01', type_code=9, display_size=None, internal_size=66, precision=None, scale=None, null_ok=True), column(name='col_02', type_code=9, display_size=None, internal_size=123, precision=None, scale=None, null_ok=True))
    >>> cursor.description[1].internal_size
    123

     

     

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file