[GRASS-dev] Re: [GRASS-user] v.db.join script

Moritz Lennert mlennert at club.worldonline.be
Tue Oct 19 10:11:54 EDT 2010


On 19/10/10 15:23, Micha Silver wrote:
> Moritz Lennert wrote:
>
>> On 13/10/10 22:23, Micha Silver wrote:
>>> One line from the v.db.join script uses grep and cut to get the column
>>> names and the next line gets the column types like so:
>>>
>>> db.describe -c bike_rides2 | grep '^Column' | cut -d ':' -f 3
>>> INTEGER
>>> CHARACTER
>>> INTEGER
>>> CHARACTER
>>> CHARACTER
>>> CHARACTER
>>> CHARACTER
>>>
>>> So the column size is actually ignored.
>>>
>>> Next, in the script the above output is used by v.db.addcol to create
>>> the new columns in the joined vector. So all new character columns are
>>> created as a single char and the actual length is never used.
>>>
>>> Questions:
>>> Is the db.describe output the same for all db drivers?
>>> Any suggestions how to fix this as a script?
>>
>> Why not use an SQL join, i.e. something like the following ?
>>
>> 1) CREATE TABLE temp AS (SELECT * FROM $maptable JOIN $otable ON
>> $column=$ocolumn)
>>
>> 2) rename table $maptable to something else
>>
>> 3) rename table temp to $maptable
>>
>> 4) if this works, remove the original $maptable
>>
> Interesting. So your suggestion is to run the above sql commands thru
> db.execute to create a new attribute table for an existing vector?

Yes. You could put them all into a temporary text file then send this 
file as one transaction to db.execute.

Moritz


More information about the grass-dev mailing list