Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Mathias Wulff edited this pageJun 20, 2023 ·1 revision

KeywordCSV

AlaSQL can import from and export to CSV (comma-separated values) format.

Syntax:

SELECT column INTO CSV(filename,options)FROM tableid;SELECT columnFROM CSV(filename,options) ;

Please note that when interacting with files AlaSQLwill run async. We strongly recommend you touse the promise notation instead of the simple notation:alasql(sql, params, function(data) { console.log(data) })

Import CSV data

alasql.promise('SELECT * FROM CSV("my.csv", {headers:false})').then(function(data){console.log(data);}).catch(function(err){console.log('Error:',err);});

You can try this examplein jsFiddle

You can also give the full content of a CSV file as a string instead of the path.

You can specify delimiters and quote characters:

alasql.promise('SELECT * FROM CSV("my.csv", {headers:false, quote:"\'",separator:","})').then(function(data){console.log(data);}).catch(function(err){console.log('Error:',err);});

Example on how to change the seperator only

alasql.promise('SELECT * FROM CSV("a.csv",{separator:";"})').then(function(data){console.log(data);}).catch(function(err){console.log('Error:',err);});

Export to CSV data

alasql.promise('SELECT * INTO CSV("my.csv", {headers:false}) FROM ?',[data]).then(function(){console.log('Data saved');}).catch(function(err){console.log('Error:',err);});;

Options

For CSV you can set the following options

  • header is defaulttrue. If set tofalse the first row in the CSV file will contain data instead of the column names
  • utf8Bom default depends on header. If headers will be included it will be defaulttrue. If headers not included it will be defaultfalse. Iftrue BOM will be added to the CSV file (useful in some cases with excel)
  • separator is default; and can be set to any string used as a seperator
  • quote is default" and can be set to any string used to quote strings
  • raw is defaultfalse and can be set to true if you want all data returned as the raw string (so no conversion of numbers)

Please note that default seperator is; and not, as specified by theRFC. The reason is thatExcel cant always handle ','. As Excel usage is such a big use case for the library we rather bother people who can't handle the incorrect.csv file with adding the parameter {seperator:','} than getting questions from all the people who cant make the lib "work" with Excel.

See also:TAB,TSV,XLSX,JSON

© 2014-2026,Andrey Gershun &Mathias Rangel Wulff

Please help improve the documentation by opening a PR on thewiki repo

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp