#!/usr/bin/env bash
set -euo pipefail
IMAGE="docker.io/library/postgres@sha256:c7526c0f6c3f30260a563d7bcf8ad778effac59a44f8ffa86678c35418338609"
SQL="CREATE TEMP TABLE tasks(title text); INSERT INTO tasks VALUES ('percent 100%'),('under_a'),('bang!mark'),('mixed 50%_! done'),('plain'); PREPARE find_literal(text) AS SELECT title FROM tasks WHERE title ILIKE \\\$1 ESCAPE '!' ORDER BY title; EXECUTE find_literal('%100!%%'); EXECUTE find_literal('%under!_%'); EXECUTE find_literal('%bang!!mark%'); EXECUTE find_literal('%50!%!_!! done%');"
output="$(deck-podman run --rm --user postgres --env LANG=C --env LC_ALL=C "$IMAGE" sh -lc "initdb --no-locale --auth=trust -D /tmp/db >/dev/null && pg_ctl -D /tmp/db -o '-k /tmp' -w start >/dev/null && psql -h /tmp -d postgres -Atqc \"$SQL\"")"
expected=$'percent 100%\nunder_a\nbang!mark\nmixed 50%_! done'
[[ "$output" == "$expected" ]] || { printf 'literal ILIKE integration mismatch\nexpected:\n%s\nactual:\n%s\n' "$expected" "$output" >&2; exit 1; }
printf 'pinned PostgreSQL literal ILIKE tests passed\n'
