sql - Fetching records which have either of two values in an array column in postgres -


i have array_agg column in postgresql has values these:

"{metabolic/endocrinology}" "{cardiovascular}" "{oncology}" "{autoimmune/inflammation}" 

basically string variable being array_agg id.

now want fetch records table either of oncology or autoimmune/inflammation present.

i doing not sure why throwing error.

select * table id = any('{oncology,autoimmune/inflammation}') 

it throws following error.

error: operator not exist: text[] = text sql state: 42883 hint: no operator matches given name , argument type(s). may need add explicit type casts. character: 67 

please note have used ::text [] , still gives error.

you want use array-overlaps operator &&.

see array operators.

e.g.

select * (   values   (array['oncology','pediatrics']),   (array['autoimmune/inflammation','oncology']),   (array['autoimmune/inflammation']),   (array['pediatrics']),   (array[]::text[]) ) "table"(id) id && array['oncology','autoimmune/inflammation']; 

by way, suggest using sql-standard array[...] constructor possible.

also, it's terrible idea have id column (presumably primary key, if not, name confusing) defined array type.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -