Learn SQL with ChatGPT or when can ChatGPT really help

Post Reply
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

I tried the following in SQL

Code: Select all | Expand

SELECT * from vll_term WHERE WORT LIKE '%' + UNHEX('C39F') + '%'
The result is not as expected, maybe there is something wrong with the syntax?

The Google answer is:
Image

ChatGPT:
Image

The correct syntax is therefore:

Code: Select all | Expand

SELECT * FROM vll_term WHERE WORT LIKE CONCAT('%', UNHEX('C39F'), '%');
The answer was very helpful for me :D
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by Enrico Maria Giordano »

I can't believe that one would want to use such a totally non-standard SQL statement. What if you want to switch SQL engine in the future (most likely)? I recommend to ever use plain standard SQL.
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

Enrico,
THX for this helpful information, the rest I've done with ChatGPT :wink: :
Image

For users who are in an UTF8 environment it's simple:

Code: Select all | Expand

SELECT * FROM vll_term WHERE WORT LIKE '%ß%');
 
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

Enrico,

yes and

Code: Select all | Expand

SELECT * FROM vll_term WHERE WORT LIKE CONCAT('%', _utf8'\u00DF', '%');
doesn't work. ChatGPT has obviously made a mistake here.

But when I want to use hex codes for the search string, MariaDB has HEX() and UNHEX().
What is the equivalent in plain SQL?

ChatGPT says:
Certainly, if you're constrained to plain SQL without access to specific MariaDB functions like HEX() and UNHEX(), performing character matching using UTF-8 hexadecimal representations directly within a LIKE statement becomes challenging...

... Unfortunately, in plain SQL without access to database-specific functions, performing character matching using UTF-8 hexadecimal representations directly within LIKE might not be feasible.
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by Enrico Maria Giordano »

frose wrote:But when I want to use hex codes for the search string, MariaDB has HEX() and UNHEX().
What is the equivalent in plain SQL?
Why do you want to use hex codes for the search string? This is the first question you have to answer.
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

Enrico,

in German we have a saying: 'you are rowing back' 8)
So we can assume that there ist non corresponding construct in plain SQL! :(
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
Rick Lipkin
Posts: 2668
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by Rick Lipkin »

A little AI joke to make you laugh ...

"Open the Pod Bay Doors Hal" .. Sorry Dave, I can't do that"

Gota love it ... Rick
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

ChatGPT cannot (yet) do this, HAL could have done it back in 1968
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg
Contact:

Re: Learn SQL with ChatGPT or when can ChatGPT really help

Post by frose »

Ok, the movie takes place in 2001.

22 years later than Arthur C. Clarks predicted, it becomes reality for evveryone (HA user):
https://hackaday.com/2022/04/23/2022-sc ... -hal-9000/
https://www.home-assistant.io/integrati ... versation/

The I can say 'Ok Google (HAL), please unlock the front door' and Google (HAL) answers...
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
Post Reply