Creating index using dynamic SQL I have following code for creating gist index

CREATE INDEX web_stats_project_107_properties_crosspromo_gist_idx 
    ON web_stats_project_107 USING gist (properties) 
    WHERE properties @&gt; '"block_level_0"=&gt;"cerber-head"'::hstore  
        AND properties @&gt; '"block_level_1"=&gt;"head"'::hstore 
        AND properties @&gt; '"block_level_2"=&gt;"cross-news"'::hstore
        AND properties ? 'block_level_5'::text
        AND (NOT (properties ? 'block_level_6'::text));


It works smoothly when I use it directly.

But I need to use it inside the trigger with some variables. And here the problem comes.

I tried two variants of code:

createIndex := 'CREATE INDEX idx_'||Fulltable_name||'_properties_crosspromo_gist 
ON public.'||Fulltable_name||' USING gist (properties) 
WHERE properties @&gt; '"block_level_0"=&gt;"cerber-head"'::hstore 
AND ...;


and

createIndex := 'CREATE INDEX idx_'||Fulltable_name||'_properties_crosspromo_gist 
ON public.'||Fulltable_name||' USING gist (properties) 
WHERE (((((properties @&gt; '"block_level_0"=&gt;"cerber-head"'::hstore) 
AND ...;


And I even can't apply it for DB because of syntax error


  ERROR:  syntax error at or near "=>" LINE 32: ...perties) WHERE
  (((((properties @> '"block_level_0"=>"cerber-...


or


  ERROR:  syntax error at or near "CREATE" LINE 32:
  createIndex := 'createIndex := 'CREATE INDEX idx...


Seems I have to escape some symbols with some characters.

Any ideas how to do that?
createIndex := 'CREATE INDEX idx_'
    || Fulltable_name
    || '_properties_crosspr_gist ON public.'
    || Fulltable_name
    || ' 
    USING gist (properties) 
    WHERE properties @&gt; $$"block_level_0"=&gt;"cerber-head"$$::hstore 
      AND properties @&gt; $$"block_level_1"=&gt;"head"$$::hstore 
      AND properties @&gt; $$"block_level_2"=&gt;"cross-news"$$::hstore 
      AND properties ? $$block_level_5$$::text 
      AND NOT properties ? $$block_level_6$$::text';