Search code examples
sqlpostgresqlfull-text-searchsupabase

SQL : to_tsvector on a specific value of a jsonB colonne


I want to make a full search query on a spécific value of my jsonb like the format of the json is :

{
  "highlights": {
    "concise": null,
    "complete": null
  },
  "gist": {
    "concise": [
      {
        "text": "",
        "isHighlighted": false,
        "highlightID": ""
      }...
    ],
    "complete": null
  },
  "summary": {
  },
  "followup": {
  },
  "subjects": {
    ...
}

i want do my research on gist.concise

I have already tri like that but doesn't work :

SELECT
  audio.id
FROM
  audio
JOIN
  audio_json ON audio.id = audio_json.audio_id
WHERE
  to_tsvector(audio.name) @@ to_tsquery('ornithorinque')
  OR to_tsvector(audio.context::text) @@ to_tsquery('ornithorinque')
  OR to_tsvector(
    audio_json.analysis ->> 'gist' ->> 'concise'::text
  ) @@ to_tsquery('ornithorinque');


Solution

  • the answer is: to_tsvector((audio_json.analysis ->> 0)::jsonb ->> 'gist') @@ to_tsquery('ornithorinque')