MySQL LOAD DATA Trick

I leaned a new trick today with LOAD DATA INFILE . I’m migrating some data from an external source, and the Date Format is not the MySQL required YYYY-MM-DD, it was DD-MMM-YY. So how do you load this into a Date Field.

`
$ echo “02-FEB-07” > /tmp/t1.psv
$ mysql -umysql
USE test;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(d1 DATE);

echo “02-FEB-07” > /tmp/t1.psv

LOAD DATA LOCAL INFILE ‘/tmp/t1.psv’
INTO TABLE t1 (@var1)
SET d1=STR_TO_DATE(@var1,’%d-%M-%y’);
SELECT * FROM t1;
EXIT
`

The trick is to bind the appropriate column within the file being loaded to a variable, @var1 in my example and use the SET syntax to perform a function on the variable. Rather cool.

A good tip to know.

Tagged with: Databases MySQL

Using GenAI directly in the database. A practical example using MySQL 8.0

If you have a typical MySQL production setup using MySQL 8.0 (EOL) with replication, you can take advantage of VillageSQL extensions to generate AI responses directly with your source data with no impact on your production setup or existing application software.

Producing Skewness statistics with SQL

Skewness measures the asymmetry of a distribution. A perfectly symmetric distribution has a skewness of zero. A positive skew (right-skewed) means the tail extends to the right — a small number of high values pull the mean above the median.

Exploring the vsql-ai extension

The vsql-ai extension adds AI prompt capabilities and text embeddings directly in SQL queries, with support for Anthropic Claude , Google Gemini , OpenAI ChatGPT , or a local LLM such as Ollama .