Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,38 @@
# Create an unnamed m*n array as a table with m rows, each row being a list
create or replace function matrix(m, n, init) as table (
with recursive row as (
select list_transform(range(0,n), x -> z) as row
from (select init as z)),
cte as (
select 1 as i, row from row
union all
select i+1, row
from cte
where i < m
)
from cte
);
# The backing table
create or replace table t_ (
i INTEGER NOT NULL check(i>0), check(i<= getenv('M')::INTEGER),
row DOUBLE[]
);
# The view
create or replace view t as from t_ order by i;
# Initialize the backing table
insert into t_ from matrix( getvariable('M')::INT, getvariable('N')::INT, 0.0);
prepare update_matrix as /* $1=i $2=j $3=value */
update t_
set row = row[1:$2-1] || [$3] || row[$2+1:]
where i = $1
;
create or replace function matrix_get(ii,jj) as (
select row[jj]
from t
where i = ii
);