dimanche 19 juillet 2015

Replacing white spaces in the fields of a SQLite database

I exported a spreadsheet from Excel to a database and it came with whites in some field's names. I did search for a solution before, but I couldn't find a workable method to strip whites from a column's name, only for the column itself. I'm using R to send queries to the server. This is what my fields look like:

[1] "DATA_GERACAO"             "HORA_GERACAO"            
 [3] "ANO_ELEICAO"              "NUM_TURNO"               
 [5] "DESCRICAO_ELEICAO"        "SIGLA_UF"                
 [7] "SIGLA_UE"                 "DESCRICAO_UE"            
 [9] "CODIGO_CARGO"             "NUMERO_CANDIDATO"        
[11] "SEQUENCIAL_CANDIDATO"     "NOME_CANDIDATO"          
[13] "NOME_URNA_CANDIDATO"      "DESCRICAO_CARGO"         
[15] "COD_SIT_CAND_SUPERIOR "   "DESC_SIT_CAND_SUPERIOR " 
[17] "COD_SITUACAO_CANDIDATURA" "DES_SITUACAO_CANDIDATURA"
[19] "COD_SIT_TOT_TURNO"        "DESC_SIT_TOT_TURNO"      
[21] "CODIGO_LEGENDA"           "SIGLA_PARTIDO"           
[23] "NOME_PARTIDO"             "SEQUENCIAL_LEGENDA "     
[25] "NOME_LEGENDA"             "COMPOSICAO_LEGENDA"      
[27] "TOTAL_VOTOS " 

I want to remove the whites, because it sucks when I need to call those fields. I've tried the following solution, and got the error message below. Any suggestion?

dbGetQuery(db, "UPDATE Table2 SET TOTAL_VOTOS = TRIM(Replace(Replace(Replace(TOTAL_VOTOS ,'\t',''),'\n',''),'\r',''))")

Error in sqliteSendQuery(con, statement, bind.data) : 
  error in statement: no such column: TOTAL_VOTOS

Aucun commentaire:

Enregistrer un commentaire