2.2. Common Separated Value File

A CSV file is commonly thought of as a "Comma Separated Value" file, or "Common Separated Value" file[1].. The second description here is more accurarate since a CSV file can have it's values delimited by any character.

CSV files are text files which allow us to store textual information in an organised fashion. In a CSV file each row contains one record. Each record can contain multiple fields each separated by a common character.

2.2.1. CSV Specification

While there is no formal specification for CSV files RFC 4180 describes a common format with a MIME type of "text/csv"

The most common format of CSV files has each record on a separate line, delimited by a line break (CRLF). An initial record with column names is optional.

For Example:

Example 2-1. Sample CSV


	id,firstname,lastname,email CRLF
	12345,John,Smith,john.smith@example.com CRLF
	23456,Patrick,Murphy,patrick.murphy@example.com CRLF
	34567,Sarah,Jones,sarah.jones@example.com
					

The CRLF in the above example is a "Carriage Return Line Feed". It is not necessary for the last line, but must be at the end of each preceeding record. It might be good to note at this stage, that although Windows and Unix have different end of line characters. CsvSQL can recognise either.

2.2.2. What can CSV files be used for?

The short answer is most anything that requires the transfer of formatted data between two systems. The CSV file format is supported by almost all spreadsheet applications and database management systems. Most modern applications support importing or exporting data in CSV format including many every day applications such as the OpenOffice and Microsoft Office suites. Many programming languages also have CSV support for reading information from CSV files.

2.2.2.1. Real World Examples

Many real world examples exist, a few of which we will mention here. For Systems Administrators dealing with CSV files is usually a daily task. It can be quite tedious to trace errors should something go awry as often times these CSV files are very large, with it being commonplace to have files up to (and above) 1 million lines long.

A few examples of CSV's being used in real world applications

  • Google use CSV files for importing users into their Google Apps email system

  • Most Content Management Systems will take CSV imports of user data

  • MySQL[2], PostgreSQL[3], SQL Server and other database systems import CSV data

  • MS Active Directory can be populated with new users using CSV files

  • Most desktop applications that manipulate / store data can export and import CSV files