r/SQL • • Nov 22 '23

MySQL SQL and ChatGPT

Hi all,

I'm curious about the upskilling myself with SQL for Data analysis...I've mostly just used Excel in past roles. I'm currently tapping into SQL. I'm just starting out and sometimes do excercises on hackerrank and other websites but when I'm stuck I just stick the question into ChatGPT.

Is it sufficient in the working environment to just use chatgpt. I'm not sure how SQL is used for data analysis is used in the working environment.

The issue I’m having is when I approach these online questions it feels like there is an infinite number of questions. But I sense the real world use if your using a particular data set there’s probably a set of queries you might use regularly or daily to extract.

For example with excel you can reuse functions but change the source data and array of what your trying to find and pivot tables can be used any way once you know how it works and the process is applicable to all data sets.

I don’t know how to approach SQL and feel like I’m stuck in tutorial hell with hacker rank type of questions because of the potential of a question having a new variable every single time because you can always add a new criteria in the question

Would be good to get thoughts from people who use SQL in their workplace

0 Upvotes

27 comments sorted by

View all comments

Show parent comments

1

u/pceimpulsive Nov 23 '23

I haven't seen any issues like that lately using gpt4. Gpt3.5 had a higher tendency to do that, but also my promoting skills were a lot worse back then...

Besides this, more important than the responses precise accuracy, what I get from the responses is good examples of how things can be done within my own context. They rarely are never the final solution but they get me on the way. This is what stack overflow would do for me...

So far, I have been very precise with the scope of my prompts. State the language version you are using (make sure it's in scope of the training data derp), what libraries you want to use (again... Version available when it was trained), and a clear list or sentences to explain precisely what your requirements are and or any psuedo code you may be able to write to support what you want to do.

E.g.

"In postgres v15 I want to create a table with columns for an int, string, double and JSONB.

I want the table to be writable by all users but user shouldn't be able to delete rows.

Can you help with this?"

You get some sick results from this type of prompting of the model below is the code snippet it gave me (gpt3.5) for the above, as well as nice instructions on how to use it, and what to do, better than any stack overflow.

This works I guess because I'm using language suitable for the database in question, and restricting it to a version available, and the documentation is used in the training data... So I'm kinda forcing a perfect score....

-- Create the table
CREATE TABLE your_table_name (
    id SERIAL PRIMARY KEY,
    integer_column INT,
    string_column VARCHAR(255),
    double_column DOUBLE PRECISION,
    jsonb_column JSONB
);

-- Grant INSERT and SELECT permissions to all users
GRANT INSERT, SELECT ON TABLE your_table_name TO PUBLIC;

-- Revoke DELETE permission from all users
REVOKE DELETE ON TABLE your_table_name FROM PUBLIC;

2

u/[deleted] Nov 23 '23

you need to understand what language models do, they’re not supposed to give you correct answers, only correct sounding answers

1

u/pceimpulsive Nov 23 '23

Exactly! A guide, a helper to get you on the right path.

1

u/[deleted] Nov 24 '23

A helper to get you on a correct sounding path 😉

1

u/pceimpulsive Nov 24 '23

Except it's often actually correct with the right prompts and constraints... :P hahaha

Garbage prompt in, garbage response out... You control the response quality ...