1

As per another question, sql: update a column if another column poses a conflict in namespace, we know that the following could be used to ensure that a set of 10000 unique package names and 100 categories, having 15000 unique combinations (thus table entries in table categories), could be updated to ensure that the two namespaces don't collide with one another (affecting about 10 entries in total):

UPDATE categories
SET fullpkgpath = fullpkgpath || ',pkg'
WHERE fullpkgpath IN (SELECT value
                      FROM categories)

However, the fullpkgpath field also repeats in other tables within my sqlite3 database, as per the schema.

  • Is there a way to have the above UPDATE statement applied to all other tables within a given sqlite3 database with the same fullpkgpath field, without having to manually specify any such extra tables?

    • If the answer to be above is, "no", then how would I manually specify which other tables I want the statement applied to? Consider that only the categories table has the categories that could be directly compared with names of packages (to be fair, the ports table also has a categories field, but it has all the categories of a given port jammed into one field (space separated), as opposed to separate table entries as is the case in the categories table).
Community
  • 1
  • 1
cnst
  • 25,870
  • 6
  • 90
  • 122
  • 1
    The outer query and the subquery are independent. – CL. Jan 17 '14 at 20:20
  • @CL., oh, so, I'd have a separate `update` entry, mentioning every table? OK, that makes sense, now that you mention it; but it'd still be interesting if there's a shortcut for this. – cnst Jan 17 '14 at 20:23
  • Normalize your schema? – ThisSuitIsBlackNot Jan 17 '14 at 20:33
  • @ThisSuitIsBlackNot, please elaborate. – cnst Jan 17 '14 at 20:43
  • 3
    You have `fullpkgpath` in 18 different tables. To change a single path, you have to make 18 updates. Instead, you could add a [surrogate key](http://en.wikipedia.org/wiki/Surrogate_key) `path_id` to your `paths` table. `path_id` is just a number generated by the database engine that has nothing to do with your application data. Instead of referencing `fullpkgpath` in your other tables, you reference `path_id`. To change a single `fullpkgpath`, you now only have to make one update. – ThisSuitIsBlackNot Jan 17 '14 at 20:53
  • @ThisSuitIsBlackNot, I think that would make it more complex -- you'd then need to keep mapping and remapping the keys all the time. – cnst Jan 17 '14 at 21:01
  • I don't know what you mean by mapping keys. It is more complex, but you don't have to worry about updating redundant data in all of your tables. – ThisSuitIsBlackNot Jan 17 '14 at 21:15

0 Answers0