Posted to tcl by schelte at Wed May 08 15:19:51 GMT 2024view raw
- # I have a table with a sequence of name changes.
- # I want to translate from any past name to the current name.
- sqlite3 db ""
- db eval {
- create table rename (old text primary key, new text unique);
- insert into rename values \
- ('orig', 'name1'), \
- ('name1', 'name2'), \
- ('name2', 'name3'), \
- ('name3', 'final');
- }
- set name orig
- db eval {
- with recursive temp(name)
- as (values($name) union
- select new from rename, temp
- where temp.name = rename.old)
- select name from temp
- } {
- puts $name
- }
- # This prints:
- # orig
- # name1
- # name2
- # name3
- # final
- #
- # How to adjust the query to only get the final result?