0

I want to update the sqlite table, the following is the example for updating one row:

update tpecroad set tnode = (SELECT  b.nodeid FROM "TPECRoad" as a
join tpecnode as b 
where pointn(a.geometry,numpoints(a.geometry)) = b.geometry and a.pk =1)
where pk=1

but there are 168432 rows to be updated, is there any faster way to update the large amount of the data?

It's like changed a.pk=1~168432 and pk=1~168432

Thanks a lots!!

3 Answers3

0
update tpecroad as c
set tnode = ( SELECT  b.nodeid 
              FROM "TPECRoad" as a join tpecnode as b 
              where pointn(a.geometry,numpoints(a.geometry)) = b.geometry and a.pk = c.pk);
tonirush
  • 430
  • 1
  • 6
  • 14
0

Try this:

Update tpecroad a
set tnode = (SELECT b.nodeid 
FROM tpecnode as b 
where pointn(tpecroad.geometry,numpoints(tpecroad.geometry)) = b.geometry)
Christian Barron
  • 2,695
  • 1
  • 14
  • 22
0

If I understand the question right, this query may help:

update tpecroad a set tnode = (
    select b.nodeid from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
)
where exists (
    select 1 from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
);

Edit: If a.pk = b.pk must verify to perform the update, the query will look as follows:

update tpecroad a set tnode = (
    select b.nodeid from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
        and a.pk = b.pk
)
where exists (
    select 1 from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
        and a.pk = b.pk
);
antonio
  • 18,044
  • 4
  • 45
  • 61