Created
April 12, 2023 02:21
-
-
Save leongkui/f1abcdc4740ace927523469084ac0347 to your computer and use it in GitHub Desktop.
SQL to dump to CSV format with header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT GROUP_CONCAT(CONCAT("'", COLUMN_NAME, "'")) | |
FROM INFORMATION_SCHEMA.COLUMNS | |
WHERE TABLE_NAME = 'patient' | |
AND TABLE_SCHEMA = 'db2' | |
order BY ORDINAL_POSITION | |
INTO OUTFILE '/Users/leongkui/Downloads/db2-header.csv' | |
FIELDS TERMINATED BY ',' | |
OPTIONALLY ENCLOSED BY '"' | |
LINES TERMINATED BY '\n'; | |
SELECT * | |
FROM patient | |
INTO OUTFILE '/Users/leongkui/Downloads/db2.csv' | |
FIELDS TERMINATED BY ',' | |
OPTIONALLY ENCLOSED BY '"' | |
LINES TERMINATED BY '\n'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment