Home Machine Learning ChatGPT Does not Perceive SQL All of the Time However This Python Instrument Does | by Christopher Tao | Jan, 2024 | In the direction of Information Science

ChatGPT Does not Perceive SQL All of the Time However This Python Instrument Does | by Christopher Tao | Jan, 2024 | In the direction of Information Science

0
ChatGPT Does not Perceive SQL All of the Time However This Python Instrument Does | by Christopher Tao | Jan, 2024 | In the direction of Information Science

[ad_1]

SQLGlot — A one-stop SQL parsing and manipulation Python Library

In case you are a developer or analyst working with knowledge day-to-day, SQL queries can be one of many important abilities for a lot of totally different roles. Once I was a tutor at Uni, a scholar complained that SQL was the worst programming language. Properly, whether or not SQL is a “programming language” I assume might be controversial. Nevertheless, it’s little doubt that it’s fairly structured and inflexible by way of its syntax. Due to this fact, it will likely be comparatively simpler to implement such a software to totally perceive its which means. No, we don’t want ChatGPT 🙂

On this article, I’m going to introduce a library that helps us parse SQL queries and even construct a question programmatically. Should you don’t know why we want to take action, meaning it could be much more necessary to learn by the remainder of the content material.

Picture by AndreasAux from Pixabay

Boring half as standard, however I’ve to have this part anyway. To put in this library, simply merely run the next.

pip set up sqlglot

Moreover, if you’re in a extra versatile surroundings akin to your laptop computer, it’s endorsed to put in the package deal along with its Rust tokenizer. This can make the parsing course of extra environment friendly.

pip3 set up "sqlglot[rs]"

Then, in our Python code, we must always import the library earlier than use. For all my examples on this article, I’ll use the alias sg for the library sqlglot, as we have to use a number of totally different capabilities on this package deal. If you wish to run my examples, please don’t neglect to run the road of code under.

import sqlglot as sg
Picture by Joe from Pixabay

That is the primary use case that this library will supply for in the present day. I’ll offer you a…

[ad_2]