Informazioni su CSV

Lo Storage Engine può leggere e scrivere nei file registrati nel formato CSV (comma-separated-values).

Lo Storage Engine CSV e il logging sulle tabelle

Lo Storage Engine CSV è quello utilizzato per default per il logging delle query SQL nelle tabelle.

mysqld --log-output=table

Lo Storage Engine CSV e NOT NULL

Lo Storage Engine CSV non supporta le colonne con valori NULL e se si cerca di creare una tabella CSV con tali colonne si ottiene un errore:

MariaDB [test]> CREATE TABLE csv_test (x INT, y DATE, z CHAR(10)) ENGINE=CSV;
ERROR 1178 (42000): The storage engine for the table doesn't support nullable columns

Si può invece aggiungere NOT NULL alle definizioni di ogni colonna.

I file dello Storage Engine CSV

Quando si crea una tabella usando lo Storage Engine CSV, vengono creati tre file:

  • <nome_tabella>.frm
  • <nome_tabella>.CSV
  • <nome_tabella>.CSM

Il file .frm contiene il formato della tabella.

Il file .CSV è di puro testo. Contiene i dati inseriti nella tabella, registrati come testo semplice, con i vari valori separati da virgole.

Il file .CSM contiene i metadati sulla tabella, come lo stato e il numero delle righe.

Esempi

MariaDB [test]> CREATE TABLE csv_test (
    -> x INT NOT NULL, y DATE NOT NULL, z CHAR(10) NOT NULL
    -> ) ENGINE=CSV;
Query OK, 0 rows affected (0.11 sec)
MariaDB [test]> INSERT INTO csv_test VALUES
    -> (1,CURDATE(),'one'),
    -> (2,CURDATE(),'two'),
    -> (3,CURDATE(),'three');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
MariaDB [test]> SELECT * FROM csv_test;
+---+------------+-------+
| x | y          | z     |
+---+------------+-------+
| 1 | 2011-11-16 | one   |
| 2 | 2011-11-16 | two   |
| 3 | 2011-11-16 | three |
+---+------------+-------+
3 rows in set (0.00 sec)
$ cat csv_test.CSV
1,"2011-11-16","one"
2,"2011-11-16","two"
3,"2011-11-16","three"

Vedi anche

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.