I wish to compare two arrays in a Postgres query, returning true when the first array is embedded within the second array. The smaller array can occur at any point within the larger one. It's probably best shown with an example. For the following, *cmp* is the magical operator that I'm hoping to find.
{b,c} *cmp* {a,b,b,c,d} -- true
{b,d} *cmp* {a,b,b,c,d} -- false
{a,b,b} *cmp* {a,b,b,c,d} -- true
{a,b} *cmp* {a,b,b,c,d} -- true
{a,b,c} *cmp* {a,b,b,c,d} -- false
I know of the <@ operator, which is a good start, but does not take into account the order of elements.
{b,d} <@ {a,b,b,c,d} -- true, but I want false
I have in my code a workaround which is quite ugly (perl's DBD::Pg uses '?' as a placeholder)
array_values::text similar to '%({|,)' || ? || '(,|})%'
Seems to work, but I'd love to be able to use an index here. It will also fall over whenever quotes are used in the text representation, but fortunately that won't happen for my use case. Am I missing a trick?
EDIT
I probably should have made better examples. Here are some more
{bb,c} *cmp* {a,b,bb,c,d} -- true
{b,c} *cmp* {a,b,bb,c,d} -- false
{a,b,bb} *cmp* {a,b,bb,c,d} -- true
{a,b,b} *cmp* {a,b,bb,c,d} -- false
{c,d} *cmp* {a,b,bb,c,d} -- true