How to Run SQL Queries in Python

How to Use Python to Run SQL Queries in Trino (Presto)

**This will only work on Windows PC Devices and Microsoft Outlook email client**

Why you should use Python to Automate SQL Queries in Trino (Presto)

In the world of big data, SQL is a critical tool for managing and analyzing large datasets. Many data analysts find themselves in the same cycle:

Run SQL, Copy and Paste Results into Excel, Format Report, and Repeat.

This process of writing and executing SQL queries can be time-consuming and tedious. That’s where automation comes in, and Python is the perfect language for automating SQL tasks. In this article, we’ll show you how to use Python to run SQL in Trino (formerly Presto), a distributed SQL query engine that’s particularly well-suited to handling big data.

We recommend running this in a Jupyter Notebook, so you can easily run each code block, section by section.


First, import the prestodb package

import prestodb

Next, Gather details about your database and credentials.

Next, you’ll need to connect to Presto using Python. You can do this using the prestodb package which allows you to automate SQL queries by connecting to Presto via Python. You’ll need to specify the Presto coordinator URL and any necessary authentication details.

Need Help Finding Database Details?

Assuming you already have a successful connection in another SQL platform, you can find details on your host url, port in your connection settings.

Finally, you’re ready to run!

Input a test SQL query in the code above and run! It should return your SQL output as a dataframe.

import pandas as pd
    
query = f'''
    select * from table
'''

conn=prestodb.dbapi.connect(
    host='HOST URL HERE',
    port= 1234,
    user='YOUR_USERNAME_HERE'
    catalog='CATALOG HERE',
    schema='SCHEMA HERE',
    http_scheme='https',
    auth=prestodb.auth.BasicAuthentication('YOUR_USERNAME_HERE','YOUR_PASSWORD_HERE'),)

cur = conn.cursor()
cur.execute(query)
conn.commit()
query_results = cur.fetchall()
    
#returns result as dataframe
df = pd.DataFrame.from_records(query_results, columns = [i[0] for i in cur.description])
print(df)

Comments

476 responses to “How to Use Python to Run SQL Queries in Trino (Presto)”

  1. Howdy wopuld yyou mind lettiing mee know which web host you’re utilizing?
    I’ve loaded youur bog in 3 diferent interneet browsers and
    I must say thiks bblog loads a loot quiicker tuen most. Can youu recomjmend a goiod
    hosing prrovider at a honsst price? Thanbk you, I appreciazte it!

  2. Buy Drugs

  3. Pornstar

  4. Porn site

  5. Pornstar

  6. Pornstar

  7. WONDERFUL Post.thanks for share..more wait .. ?

  8. Porn site

  9. Buy Drugs

  10. Buy Drugs

  11. Porn site

  12. Pornstar

  13. Buy Drugs

  14. Buy Drugs

  15. Porn site

  16. Porn site

  17. Pornstar

  18. Pornstar

  19. Buy Drugs

  20. Porn site

  21. Thanks for the tips you have discussed here. In addition, I believe there are several factors that keep your car insurance premium down. One is, to contemplate buying autos that are in the good listing of car insurance providers. Cars which are expensive are definitely more at risk of being lost. Aside from that insurance is also depending on the value of the car, so the higher priced it is, then higher the particular premium you have to pay.

  22. Pornstar

  23. This site is known as a walk-through for all the information you needed about this and didn抰 know who to ask. Glimpse right here, and also you抣l definitely uncover it.

  24. Porn site

  25. Buy Drugs

  26. Pornstar

  27. Pornstar

  28. Buy Drugs

  29. Porn site

  30. Pornstar

  31. Pornstar

  32. Porn site

  33. Pornstar

  34. Pornstar

  35. Buy Drugs

  36. Pornstar

  37. Porn site

  38. Buy Drugs

  39. Porn site

  40. Porn site

  41. Buy Drugs

  42. Buy Drugs

  43. Buy Drugs

  44. Buy Drugs

  45. Pornstar

  46. Pornstar

  47. Pornstar

  48. Pornstar

  49. Pornstar

  50. Porn site

  51. Buy Drugs

  52. Buy Drugs

  53. Porn site

  54. Pornstar

  55. Pornstar

  56. Porn site

  57. Buy Drugs

  58. Pornstar

  59. Porn site

  60. Porn site

  61. Buy Drugs

  62. Buy Drugs

  63. Buy Drugs

  64. Buy Drugs

  65. Porn site

  66. Porn site

  67. Porn site

  68. Pornstar

  69. I am really impressed together with your writing abilities and also with the layout in your blog. Is that this a paid theme or did you customize it your self? Anyway keep up the nice high quality writing, it is rare to look a great weblog like this one nowadays..

  70. Porn site

  71. Pornstar

  72. Porn site

  73. Buy Drugs

  74. Daman game is a nice colour trading website

  75. Daman game is a nice colour trading website

  76. Best colour trading app

  77. Colour prediction app daman game

  78. Best colour trading app

  79. Porn site

  80. Buy Drugs

  81. Pornstar

  82. Buy Drugs

  83. Pornstar

  84. Pornstar

  85. Colour prediction app NN games

  86. Best colour trading app

  87. Colour prediction app 91club

  88. 51 game is a nice colour trading website

  89. Best colour trading app

  90. Best colour trading app

  91. Try 91 app now

  92. 91 club lottery is a nice colour trading website

  93. Colour prediction app 91club game

  94. Try 91club lottery now

  95. Colour prediction app 91 club app

  96. Try 91 club apk now.

  97. Try 91 club apk now.

  98. Hey there, I appreciate you posting great content covering that topic with full attention to details and providing updated data. I believe it is my turn to give back, check out my website Webemail24 for additional resources about Replicas.

  99. Having read your blog, you obviously know what you are talking about. I’m sure visiting my page Seoranko about Blogging will be worth your time!

  100. Buy Drugs

  101. Buy Drugs

  102. Buy Drugs

  103. Buy Drugs

  104. Buy Drugs

  105. Pornstar

  106. Pornstar

  107. It appears that you know a lot about this topic. I expect to learn more from your upcoming updates. Of course, you are very much welcomed to my website Article Sphere about Blogging.

  108. Porn site

  109. Porn site

  110. Pornstar

  111. Pornstar

  112. Buy Drugs

  113. Porn site

  114. Porn site

  115. Porn site

  116. Pornstar

  117. Buy Drugs

  118. Porn site

  119. Pornstar

  120. Pornstar

  121. Buy Drugs

  122. Pornstar

  123. Buy Drugs

  124. Buy Drugs

  125. Buy Drugs

  126. Pornstar

  127. Buy Drugs

  128. Buy Drugs

  129. Porn site

  130. Pornstar

  131. Your posts in this blog really shine! Glad to gain some new insights, which I happen to also cover on my page. Feel free to visit my webpage FQ6 about Cosmetics and any tip from you will be much apreciated.

  132. Hey there, I love all the points you made on that topic. There is definitely a great deal to know about this subject, and with that said, feel free to visit my blog ZH5 to learn more about Thai-Massage.

  133. Hello, Neat post. There is an issue together with your web site in web explorer,
    would test this? IE still is the marketplace chief and a good component of other people will omit your fantastic
    writing due to this problem.

  134. I just couldn’t go away your website prior to suggesting that I actually loved
    the standard information an individual supply to your visitors?

    Is gonna be again regularly in order to investigate cross-check new
    posts

  135. I came across your site wanting to learn more and you did not disappoint. Keep up the terrific work, and just so you know, I have bookmarked your page to stay in the loop of your future posts. Here is mine at 63U about Cosmetic Treatment. Have a wonderful day!

  136. fuck porn sites

  137. hentai porn download

  138. hentai porn download

  139. Buy Drugs

  140. Pornstar

  141. Buy Drugs

  142. Porn site

  143. Buy Drugs

Leave a Reply

Your email address will not be published. Required fields are marked *