Last active
December 12, 2022 22:52
-
-
Save saerdnaer/a38f57bf50861f69676a81d181ec0f3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE INDEX "items_alternate_ids_idx" ON "items" USING GIN ("alternate_ids"); | |
CREATE OR REPLACE FUNCTION items_by_ids(ids text[], is_published boolean DEFAULT NULL) | |
RETURNS SETOF items | |
AS $$ | |
SELECT items.* | |
FROM unnest($1) WITH ORDINALITY t(value, ord), items | |
WHERE ( | |
items.core_id = t.value | |
OR items.id = CASE WHEN isnumeric(t.value) THEN t.value::integer ELSE null END | |
OR items.alternate_ids @> ARRAY[t.value] | |
) | |
AND ($2 IS NULL OR items.is_published = $2) | |
LIMIT 500 | |
$$ | |
LANGUAGE sql | |
STABLE; | |
COMMENT ON FUNCTION items_by_ids(text[], boolean) IS E'@simpleCollections both'; |
Author
saerdnaer
commented
Dec 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment