Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/sql/40-swh-func.sql
create or replace function hash_sha1(text) | create or replace function hash_sha1(text) | ||||
returns text | returns text | ||||
as $$ | as $$ | ||||
select encode(digest($1, 'sha1'), 'hex') | select encode(digest($1, 'sha1'), 'hex') | ||||
$$ language sql strict immutable; | $$ language sql strict immutable; | ||||
comment on function hash_sha1(text) is 'Compute SHA1 hash as text'; | comment on function hash_sha1(text) is 'Compute SHA1 hash as text'; | ||||
-- create a temporary table called tmp_TBLNAME, mimicking existing table | -- create a temporary table called tmp_TBLNAME, mimicking existing table | ||||
-- TBLNAME | -- TBLNAME | ||||
-- | -- | ||||
-- Args: | -- Args: | ||||
-- tblname: name of the table to mimick | -- tblname: name of the table to mimic | ||||
create or replace function swh_mktemp(tblname regclass) | create or replace function swh_mktemp(tblname regclass) | ||||
returns void | returns void | ||||
language plpgsql | language plpgsql | ||||
as $$ | as $$ | ||||
begin | begin | ||||
execute format(' | execute format(' | ||||
create temporary table tmp_%1$I | create temporary table tmp_%1$I | ||||
(like %1$I including defaults) | (like %1$I including defaults) | ||||
on commit drop; | on commit drop; | ||||
alter table tmp_%1$I drop column if exists object_id; | alter table tmp_%1$I drop column if exists object_id; | ||||
', tblname); | ', tblname); | ||||
return; | return; | ||||
end | end | ||||
$$; | $$; | ||||
-- create a temporary table for directory entries called tmp_TBLNAME, | -- create a temporary table for directory entries called tmp_TBLNAME, | ||||
-- mimicking existing table TBLNAME with an extra dir_id (sha1_git) | -- mimicking existing table TBLNAME with an extra dir_id (sha1_git) | ||||
-- column, and dropping the id column. | -- column, and dropping the id column. | ||||
-- | -- | ||||
-- This is used to create the tmp_directory_entry_<foo> tables. | -- This is used to create the tmp_directory_entry_<foo> tables. | ||||
-- | -- | ||||
-- Args: | -- Args: | ||||
-- tblname: name of the table to mimick | -- tblname: name of the table to mimic | ||||
create or replace function swh_mktemp_dir_entry(tblname regclass) | create or replace function swh_mktemp_dir_entry(tblname regclass) | ||||
returns void | returns void | ||||
language plpgsql | language plpgsql | ||||
as $$ | as $$ | ||||
begin | begin | ||||
execute format(' | execute format(' | ||||
create temporary table tmp_%1$I | create temporary table tmp_%1$I | ||||
(like %1$I including defaults, dir_id sha1_git) | (like %1$I including defaults, dir_id sha1_git) | ||||
▲ Show 20 Lines • Show All 1,077 Lines • Show Last 20 Lines |