Export data from a table to a JSON file in MariaDB

MariaDb

It is possible starting from MariaDB version 1.5 to export a table into a javascript array by using the following syntax


	SELECT 
	
		IFNULL(JSON_ARRAYAGG(
	
			JSON_OBJECT(
			    'Property1', c.Property1,
			    'Proeprty2', c.Property2,
			    ...
			    'PropertyN', c.PropertyN
			)
		), '[]')
	
	INTO OUTFILE 'c:/path/to/output.json'
	
	FROM MyTable c
	WHERE sc.SomeTime >= now() - INTERVAL 1 DAY

Make sure to save the file with a diffrent name each time or create a file with a timetsamp in its name, this method does not allow you to override existing files for some reason.

Post a Comment

Previous Post Next Post