Search code examples
sqlsqlitedatatablesyntaxappend

sqlite append column to existing table


I have a table(MyTable) with 3 columns named as "A","B",and "C". Now, I use SELECT and LENGTH function like SELECT LENGTH("A") FROM MyTable. So, I just got another column with rows of characters length from each row of column A. However, I have no clue to append this to MyTable.

In other words, if my question is rephrased, I wonder how to make another column with characters length of a certain column.

I tried to make new table with the column made from SELECT LENGTH("A") FROM, and CREATE new table AS SELECT LENGTH("A") FROM. But, it shows syntax error.


Solution

  • I guess the error you are getting is because you are not specifying name for the new column. Can you try this:

    CREATE TABLE NewTable AS SELECT A, B, C, LENGTH(A) AS A_length FROM MyTable;
    

    As @forpas said, your syntax error was caused by a typo - using LENTH instead of LENGTH.