--
-- PostgreSQL database dump
--

-- Dumped from database version 12.0 (Debian 12.0-1+b1)
-- Dumped by pg_dump version 12.0 (Debian 12.0-1+b1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: swh_content_find(public.sha1, public.sha1_git, public.sha256, public.blake2s256); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.swh_content_find(sha1 public.sha1 DEFAULT NULL::bytea, sha1_git public.sha1_git DEFAULT NULL::bytea, sha256 public.sha256 DEFAULT NULL::bytea, blake2s256 public.blake2s256 DEFAULT NULL::bytea) RETURNS public.content
    LANGUAGE plpgsql
    AS $$
declare
    con content;
    filters text[] := array[] :: text[];  -- AND-clauses used to filter content
    q text;
begin
    if sha1 is not null then
        filters := filters || format('sha1 = %L', sha1);
    end if;
    if sha1_git is not null then
        filters := filters || format('sha1_git = %L', sha1_git);
    end if;
    if sha256 is not null then
        filters := filters || format('sha256 = %L', sha256);
    end if;
    if blake2s256 is not null then
        filters := filters || format('blake2s256 = %L', blake2s256);
    end if;

    if cardinality(filters) = 0 then
        return null;
    else
        q = format('select * from content where %s',
                   array_to_string(filters, ' and '));
        execute q into con;
	return con;
    end if;
end
$$;


--
-- PostgreSQL database dump complete
--

