What's the maximum length for a value stored in a field in Anki?

I’m currently generating cards programmatically and I’m using Javascript to display the fields programmatically in templates. I just had a new idea which I consider useful for my use cases: Instead of creating an Anki field for storing every piece of data, I would provide all the data as a single field which will contain a JSON object. However, before proceeding with this idea, I would like to know if there’s a maximum length for the value of an Anki field.

Please, if you are going to recommend me how I should structure my cards, I kindly ask you to also answer the main question of this thread.

I decided to take a look at the database schema and found that the SQL table that stores all notes is called notes and the attribute that store the fields is flds which has type text.

So the question here is: What’s the maximum length for a column text in a SQLite database? The official documentation states the following

The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand million or 1,000,000,000).

So, you should be fine with storing 10000 characters in a field (unless I’m omitting some Anki schema-related limitations which I’m not aware of).

Relevant information about Anki schema

I also learned that all fields are stored in flds and the values are separated with a newline. The following are the commands that I used to learn about this.

sqlite> select * from notes;
id             guid        mid            mod         usn  tags  flds                                                          sfld                                                          csum        flags  data
-------------  ----------  -------------  ----------  ---  ----  ------------------------------------------------------------  ------------------------------------------------------------  ----------  -----  ----
1692845220324  IJ)PhSPWfD  1692845214067  1692845344  -1         this is the front field of my first note                      this is the front field of my first note                      130059640   0          
                                                                 this is the back field of my first note                                                                                                            

1692845221664  EGY`zsg;yZ  1692845214067  1692845351  -1         this is the front field of my second note                     this is the front field of my second note                     2674002115  0          
                                                                 this is the back field of my second note                                                                                                           

1692845471000  cOFV35s;Ak  1692845214067  1692845486  -1         this is line no. 1 in the front field of my third note<br>th  this is line no. 1 in the front field of my third notethis i  1113587933  0          
                                                                 is is line no. 2 in the front field of my third note<br>this  s line no. 2 in the front field of my third notethis is line                         
                                                                  is line no. 3 in the front field of my third note             no. 3 in the front field of my third note                                           
                                                                 this is line no. 1 in the back field of my third note<br>thi                                                                                       
                                                                 s is line no. 2 in the back field of my third note<br>this i                                                                                       
                                                                 s line no. 3 in the back field of my third note                                                                                                    
sqlite> select LENGTH(flds) from notes where id = '1692845220324';
LENGTH(flds)
------------
80          
sqlite> select LENGTH('this is the front field of my first note');
LENGTH('this is the front field of my first note')
--------------------------------------------------
40                                                

10k should be fine. If it grows into megabytes, it will stop working on AnkiWeb, and the editor performance will tank.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.