Re: [GENERAL] filter records by substring match of an postgresql array column - Mailing list pgsql-general

From Arup Rakshit
Subject Re: [GENERAL] filter records by substring match of an postgresql array column
Date
Msg-id 7F8673F7-CFF5-4C3E-B5ED-1C80BE505B5A@outlook.com
Whole thread Raw
In response to [GENERAL] filter records by substring match of an postgresql array column  (Arup Rakshit <aruprakshit1987@outlook.com>)
Responses Re: [GENERAL] filter records by substring match of an postgresqlarray column
List pgsql-general
I enabled the extension `pg_trgm`.

I thought to query like:

SELECT  "videos".*
FROM  "videos"
WHERE  (     array_to_string(tags, ', ') ilike '%web shorts%'  )  AND EXISTS  (     SELECT     FROM        unnest(tags)
ASu(val)      WHERE        u.val ILIKE '%web shorts%'  ) 
;

And to do I wanted to add an index like:

CREATE INDEX trgm_idx_video_tags ON videos USING gist ((array_to_string(tags, ', ')) gist_trgm_ops)

But on running this I get an error as:

ERROR:  functions in index expression must be marked IMMUTABLE

How can I fix this?



> On Nov 8, 2017, at 4:02 PM, Arup Rakshit <aruprakshit1987@outlook.com> wrote:
>
> Hi,
>
> I do have a videos table, and it has a column called `tags` of type array. I would like to select all videos where
anystring inside tag column matches a given substring. What method should I use? The *Contains `@>` operator* will do
fullstring comparisons as far as I understood. 



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Jeff Janes
Date:
Subject: Re: [GENERAL] filter records by substring match of an postgresqlarray column
Next
From: Jeff Janes
Date:
Subject: Re: [GENERAL] filter records by substring match of an postgresqlarray column