<div dir="ltr"><div>Or maybe, to be more flexible...</div><div><br></div><div>1. v.db.addtable doesn't create unique index</div><div>2. v.db.connect creates unique index "only if" there is no unique index</div><div><br></div><div>Just my 2 cents<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 26, 2019 at 8:50 AM Huidae Cho <<a href="mailto:grass4u@gmail.com">grass4u@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Markus,</div><div><br></div><div>If there is a linked table, v.db.addtable stops in line 106. If not, this script doesn't create a unique index and calls v.db.connect. v.db.connect adds a db link in line 317 and creates a unique index (db_create_index2) in line 334 if linking was successful. SQLite didn't complain when both modules created the same unique index, but PostgreSQL failed in v.db.connect (2nd time creating the same unique index). Not sure which code was added first/later. I think it's more of how we design both modules. v.db.connect will fail if we try to link a table with a unique index. Isn't v.db.connect supposed to "just" connect a table to a layer (without creating any database objects like index)? Which module should be responsible for creating unique indices?</div><div><br></div><div>Before this commit:</div><div>1. v.db.addtable creates unique index</div><div>2. v.db.connect tries to create unique index again ==> fatal error</div><div><br></div><div>After this commit:</div><div>1. v.db.addtable doesn't create unique index</div><div>2. v.db.connect creates unique index</div><div><br></div><div>Probably, it should be:</div><div>1. v.db.addtable should create unique index</div><div>2. v.db.connect shouldn't try to create unique index? Just "connect"...</div><div><br></div><div>Regards,</div><div>Huidae<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail-m_-3314287523125071821gmail_attr">On Sat, Jan 26, 2019 at 7:39 AM Markus Neteler <<a href="mailto:neteler@osgeo.org" target="_blank">neteler@osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Tue, Jan 22, 2019 at 3:51 AM <<a href="mailto:svn_grass@osgeo.org" target="_blank">svn_grass@osgeo.org</a>> wrote:<br>
><br>
> Author: hcho<br>
> Date: 2019-01-21 18:51:33 -0800 (Mon, 21 Jan 2019)<br>
> New Revision: 73995<br>
><br>
> Modified:<br>
>    grass/trunk/scripts/v.db.addtable/<a href="http://v.db.addtable.py" rel="noreferrer" target="_blank">v.db.addtable.py</a><br>
> Log:<br>
> v.db.addtable: Do not create unique index from this script; v.db.connect will try to create it again causing some drivers to fail (PostgreSQL)<br>
><br>
> Modified: grass/trunk/scripts/v.db.addtable/<a href="http://v.db.addtable.py" rel="noreferrer" target="_blank">v.db.addtable.py</a><br>
> ===================================================================<br>
> --- grass/trunk/scripts/v.db.addtable/<a href="http://v.db.addtable.py" rel="noreferrer" target="_blank">v.db.addtable.py</a>  2019-01-21 22:37:59 UTC (rev 73994)<br>
> +++ grass/trunk/scripts/v.db.addtable/<a href="http://v.db.addtable.py" rel="noreferrer" target="_blank">v.db.addtable.py</a>  2019-01-22 02:51:33 UTC (rev 73995)<br>
> @@ -139,16 +139,6 @@<br>
>          except CalledModuleError:<br>
>              grass.fatal(_("Unable to create table <%s>") % table)<br>
><br>
> -        # create index, see db/driver/*/index.c<br>
> -        if driver != "dbf":<br>
> -            sql = "CREATE UNIQUE INDEX %s_%s ON %s (%s)" % (table, key, table, key)<br>
> -            try:<br>
> -                grass.run_command('db.execute',<br>
> -                                  database=database, driver=driver, sql=sql)<br>
> -            except:<br>
> -                grass.warning(_("Unable to create index on table <%s>") % table)<br>
> -                pass<br>
> -<br>
>      # connect the map to the DB:<br>
>      if schema:<br>
>          table = '{schema}.{table}'.format(schema=schema, table=table)<br>
<br>
just a conceptual question:<br>
... are we sure that this index creation removal never leads to a<br>
table without index?<br>
<br>
Markus<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail-m_-3314287523125071821gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr">Huidae Cho, Ph.D., GISP, PE (MD), CFM, M.ASCE<br>Open Source GIS Developer, GRASS GIS Development Team</div></div></span></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr">Huidae Cho, Ph.D., GISP, PE (MD), CFM, M.ASCE<br>Open Source GIS Developer, GRASS GIS Development Team</div></div></span></div></div></div></div></div></div></div></div>