[GRASS-user] Rename multiple sqlite columns at once
Moritz Lennert
mlennert at club.worldonline.be
Thu Nov 6 19:38:01 EST 2008
On 06/11/08 20:33, Nikos Alexandris wrote:
> On Thu, 2008-11-06 at 19:59 +0100, Moritz Lennert wrote:
>> [...]
>>
>>> # output
>>> block_id\_tmp
>> I think this is because of the quotes:
>>
>> tempcolumn="$tempcolumn""\_tmp"
>>
>> But actually, trying out your entire original script, I don't see
>> where
>> the problem is. The attached version seems to work perfectly for me
>> (just slightly simplified from your original version):
>>
>> What exactly did not work when you tried this ?
>>
>> Moritz
>
> Moritz,
> thank you for your time.
>
> 1. I *corrected* the double quotes and re-run the script. [Script +
> output attached]
You still use quotes:
tempcolumn="$tempcolumn\_tmp"
IIUC, the quotes will let the slash appear literally. So, just leave out
the quotes as follows:
tempcolumn=$tempcolumn\_tmp
However, as you say your original script (in my modified form) actually
worked, it just spit out a series of warnings. So it might be more
interesting to check upon these warnings. I only saw these with the
sqlite driver, not with dbf or postgresql, so we should try to find out
what happens with that driver.
Moritz
>
> 2. I tried your latest script (the one you attached in the previous
> message). It works but I still get those column-type-related WARNINGS.
> [Script + output attached]
>
> Kind Regards, Nikos
>
>
> ------------------------------------------------------------------------
>
> # I *corrected* the tempcolumn="$tempcolumn""\_tmp"
> ## Actually it didn't work in first place this is why I experimented a bit by adding the double quotes!
>
> cat caps_2_lower_moritzx.sh -n
>
> 1 #!/bin/sh -x
> 2
> 3 key_column="cat"
> 4 suffix="_tmp"
> 5 for column in `db.columns test`; do
> 6 if [ "$column" != "$key_column" ]; then
> 7 tempcolumn=`echo $column | awk '{print tolower($1)}'`
> 8 tempcolumn="$tempcolumn\_tmp"
> 9 echo $tempcolumn
> 10 v.db.renamecol map=befliegung_copy column=$column,$tempcolumn
> 11 lower_column=`echo $tempcolumn $suffix | awk '{print
> 12 substr($1,1,length($1)-length($2))}'`
> 13 v.db.renamecol map=test layer=1 column=$tempcolumn,$lower_column
> 14 fi
> 15 done
> 16
> 17 db.columns test
>
>
> # Output when running the above
> sh ./caps_2_lower_moritzx.sh > caps_2_lower_moritzx2
>
> ERROR: Column <block_id> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <AREA> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <PERIMETER> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <RAS2X2_> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <RAS2X2_ID> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <RAS2X2_NR> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <block> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <STAND> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <BEFL_DATUM> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <BEFL_JAHR> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> ERROR: Column <QUALITAET> not found in table
> Sorry <_tmp> is not a valid option
>
> Description:
> Renames a column in the attribute table connected to a given vector map.
>
> Keywords:
> vector, database, attribute table
>
> Usage:
> v.db.renamecol map=name [layer=value] column=string[,string,...]
> [--verbose] [--quiet]
>
> Flags:
> --v Verbose module output
> --q Quiet module output
>
> Parameters:
> map Vector map for which to rename attribute column
> layer Layer where to rename column
> default: 1
> column Old and new name of the column (old,new)
> [Raster MASK present]
>
>
> ------------------------------------------------------------------------
>
> # Moritz's script...
> cat change_case.sh -n
>
> 1 #!/bin/sh -x
> 2
> 3 key_column="cat"
> 4 suffix="_tmp"
> 5 map="test"
> 6 for column in `db.columns test`; do
> 7 if [ "$column" != "$key_column" ]; then
> 8 tempcolumn=$column$suffix
> 9 echo $tempcolumn
> 10 v.db.renamecol map=$map column=$column,$tempcolumn
> 11 lowercolumn=`echo $column | awk '{print tolower($1)}'`
> 12 v.db.renamecol map=$map layer=1 column=$tempcolumn,$lowercolumn
> 13 fi
> 14 done
> 15
> 16 db.columns test
>
> # running the above works but I still get some WARNINGS... ??
> sh ./change_case.sh
>
> block_id_tmp
> AREA_tmp
> PERIMETER_tmp
> RAS2X2__tmp
> RAS2X2_ID_tmp
> RAS2X2_NR_tmp
> block_tmp
> WARNING: SQLite driver: unable to parse decltype: CHARACTER INTEGER
> WARNING: SQLite driver: unable to parse decltype: CHARACTER INTEGER
> WARNING: SQLite driver: column 'block_tmp', SQLite type 1 is not supported
> WARNING: SQLite driver: unable to parse decltype: CHARACTER INTEGER
> WARNING: SQLite driver: unable to parse decltype: CHARACTER INTEGER
> WARNING: SQLite driver: column 'block_tmp', SQLite type 1 is not supported
> ERROR: Column <block_tmp> not found in table
> STAND_tmp
> BEFL_DATUM_tmp
> BEFL_JAHR_tmp
> QUALITAET_tmp
> cat
> block_id
> area
> perimeter
> ras2x2_
> ras2x2_id
> ras2x2_nr
> stand
> befl_datum
> befl_jahr
> qualitaet
More information about the grass-user
mailing list