Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- import teradata
- def print_coltypes(sql):
- csr.execute(sql)
- fmt = '{:20} | {:28} | {:38} | {:6} | {:6} | {:6} | {:6} | {:6}'
- print(fmt.format('name','csr type','val type','dsize','isize','prec','scale','null'))
- print(fmt.format(*['-----']*8))
- desc = list(csr.description)
- for e, col in enumerate(csr.fetchone()):
- line = [desc[e][0], desc[e][1], type(col)] + list(desc[e][2:])
- print(fmt.format(*[str(c) for c in line]))
- with teradata.tdrest.connect(host='hhhhhhh', system='ssssss', username='uuuuu', password='ppppp') as conn:
- with conn.cursor() as csr:
- print_coltypes("""\
- select cast('abc' as char(5)) As Col_Char5
- , cast('abc' as varchar(5)) As Col_VarChar5
- , cast(123456 as integer) As Col_Int
- , cast(1234567890123 as bigint) As Col_BigInt
- , cast(1234 as smallint) As Col_SmallInt
- , cast(123 as byteint) As Col_ByteInt
- , cast(123.56 as decimal(5,2)) As Col_Dec52
- , cast(123.56 as decimal(38,4)) As Col_Dec384
- , current_date As Col_Date
- , current_time As Col_time
- , Current_timestamp(0) As Col_timestamp0
- , Current_timestamp(6) As Col_timestamp6
- , interval '05:06' hour to minute As Col_HourToMin
- , interval '03 05' day to hour As Col_DayToMin
- , interval '05-11' year to month As Col_YearToMonth
- , cast('{"ABC":[1,2]}' as json) As Col_JsonObj
- , cast('[1,2]' as json) As Col_JsonArray
- -- , cast('<a/>' as xml) As Col_xml""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement