Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import teradata
  4.  
  5. def print_coltypes(sql):
  6. csr.execute(sql)
  7.  
  8. fmt = '{:20} | {:28} | {:38} | {:6} | {:6} | {:6} | {:6} | {:6}'
  9.  
  10. print(fmt.format('name','csr type','val type','dsize','isize','prec','scale','null'))
  11. print(fmt.format(*['-----']*8))
  12.  
  13. desc = list(csr.description)
  14.  
  15. for e, col in enumerate(csr.fetchone()):
  16. line = [desc[e][0], desc[e][1], type(col)] + list(desc[e][2:])
  17. print(fmt.format(*[str(c) for c in line]))
  18.  
  19.  
  20. with teradata.tdrest.connect(host='hhhhhhh', system='ssssss', username='uuuuu', password='ppppp') as conn:
  21. with conn.cursor() as csr:
  22. print_coltypes("""\
  23. select cast('abc' as char(5)) As Col_Char5
  24. , cast('abc' as varchar(5)) As Col_VarChar5
  25.  
  26. , cast(123456 as integer) As Col_Int
  27. , cast(1234567890123 as bigint) As Col_BigInt
  28. , cast(1234 as smallint) As Col_SmallInt
  29. , cast(123 as byteint) As Col_ByteInt
  30.  
  31. , cast(123.56 as decimal(5,2)) As Col_Dec52
  32. , cast(123.56 as decimal(38,4)) As Col_Dec384
  33.  
  34. , current_date As Col_Date
  35. , current_time As Col_time
  36. , Current_timestamp(0) As Col_timestamp0
  37. , Current_timestamp(6) As Col_timestamp6
  38.  
  39. , interval '05:06' hour to minute As Col_HourToMin
  40. , interval '03 05' day to hour As Col_DayToMin
  41. , interval '05-11' year to month As Col_YearToMonth
  42.  
  43. , cast('{"ABC":[1,2]}' as json) As Col_JsonObj
  44. , cast('[1,2]' as json) As Col_JsonArray
  45. -- , cast('<a/>' as xml) As Col_xml""")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement