Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/sql/40-swh-func.sql
Show First 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | from tmp_content_fossology_license tcl | ||||
on conflict(id, license_id, indexer_configuration_id) | on conflict(id, license_id, indexer_configuration_id) | ||||
do nothing; | do nothing; | ||||
return; | return; | ||||
end | end | ||||
$$; | $$; | ||||
comment on function swh_content_fossology_license_add(boolean) IS 'Add new content licenses'; | comment on function swh_content_fossology_license_add(boolean) IS 'Add new content licenses'; | ||||
-- content_metadata functions | |||||
-- add tmp_content_metadata entries to content_metadata, overwriting | |||||
-- duplicates if conflict_update is true, skipping duplicates otherwise. | |||||
-- | |||||
-- If filtering duplicates is in order, the call to | |||||
-- swh_content_metadata_missing must take place before calling this | |||||
-- function. | |||||
-- | |||||
-- operates in bulk: 0. swh_mktemp(content_language), 1. COPY to | |||||
-- tmp_content_metadata, 2. call this function | |||||
create or replace function swh_content_metadata_add(conflict_update boolean) | |||||
returns void | |||||
language plpgsql | |||||
as $$ | |||||
begin | |||||
if conflict_update then | |||||
insert into content_metadata (id, metadata, indexer_configuration_id) | |||||
select id, metadata, indexer_configuration_id | |||||
from tmp_content_metadata tcm | |||||
on conflict(id, indexer_configuration_id) | |||||
do update set metadata = excluded.metadata; | |||||
else | |||||
insert into content_metadata (id, metadata, indexer_configuration_id) | |||||
select id, metadata, indexer_configuration_id | |||||
from tmp_content_metadata tcm | |||||
on conflict(id, indexer_configuration_id) | |||||
do nothing; | |||||
end if; | |||||
return; | |||||
end | |||||
$$; | |||||
comment on function swh_content_metadata_add(boolean) IS 'Add new content metadata'; | |||||
-- create a temporary table for retrieving content_metadata | |||||
create or replace function swh_mktemp_content_metadata() | |||||
returns void | |||||
language sql | |||||
as $$ | |||||
create temporary table tmp_content_metadata ( | |||||
like content_metadata including defaults | |||||
) on commit drop; | |||||
$$; | |||||
comment on function swh_mktemp_content_metadata() is 'Helper table to add content metadata'; | |||||
-- end content_metadata functions | |||||
-- add tmp_revision_intrinsic_metadata entries to revision_intrinsic_metadata, | -- add tmp_revision_intrinsic_metadata entries to revision_intrinsic_metadata, | ||||
-- overwriting duplicates if conflict_update is true, skipping duplicates | -- overwriting duplicates if conflict_update is true, skipping duplicates | ||||
-- otherwise. | -- otherwise. | ||||
-- | -- | ||||
-- If filtering duplicates is in order, the call to | -- If filtering duplicates is in order, the call to | ||||
-- swh_revision_intrinsic_metadata_missing must take place before calling this | -- swh_revision_intrinsic_metadata_missing must take place before calling this | ||||
-- function. | -- function. | ||||
-- | -- | ||||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |