How to change URL of PWA in Magento 2.3?

The result of pg_typeof() is an oid, if you want to compare that with a string value, you need to cast it, e.g. if pg_typeof($1)::text = 'jsonb' then...

But once you checked if the input is a JSON you also need to verify if it's a JSON array, because {"foo": "bar"} will also be reported as json(b).

The way you iterate over the array is also quite inefficient as you are running the same select statement over and over again. You can check this with a single statement.

There is no ELIF in PL/pgSQL. As documented in the manual it needs to be ELSIF

So the function would look something like this:

CREATE OR REPLACE FUNCTION check_is_animal(anyelement) 
  RETURNS boolean 
AS $$
DECLARE
   arr text[];
   l_result boolean;
BEGIN
  -- check if the argument is a text array
  -- this could be expanded to check for character varying[] as well
  IF pg_typeof($1)::text = 'text[]' THEN
    arr := $1;
  ELSEIF pg_typeof($1)::text = 'jsonb' THEN
    IF jsonb_typeof($1) = 'array' THEN
      -- check if the array contains strings or objects:
      IF jsonb_typeof($1 -> 0) = 'object' THEN
        -- assuming the key is always name:
        arr := array(select jsonb_array_elements($1) ->> 'name');
      ELSE 
        arr := array(select jsonb_array_elements_text($1::jsonb));
      END IF;
    ELSE 
      return false;
    END IF;
  ELSEIF pg_typeof($1)::text = 'json' THEN
    IF json_typeof($1) = 'array' THEN
      arr := array(select jsonb_array_elements_text($1::jsonb));
    ELSE 
      return false;
    END IF;
  ELSE 
    -- no array whatsoever 
    return false;
  END IF;

  select count(*) = 0
    into l_result
  from unnest(arr) as x(name)
  where not exists (select *
                    from animals a
                    where x.name = a.animal);

  return l_result;
END;
$$ LANGUAGE plpgsql;

If the JSON array contains unknown key names and you can't use the hardcoded name, you can use this instead:

    arr := array(select x.v
                 from jsonb_array_elements($1) as t(e) 
                 cross join jsonb_each_Text(t.e) as x(k,v));

The final select statement checks if all elements in the array exist in the table. By using a NOT EXISTS condition, the statement can stop as soon as one non-existing animal is found.

Online example


Look at an example or two. Suppose, for instance, that you double $B$ and triple $C$, in that order, starting with a value $a$ for $A$. Doubling $B$ while holding $C$ fixed causes $A$ to double to $2a$, and then tripling $C$ while holding $B$ fixed causes $A$ to triple to $3\cdot2a=6a$; the net effect is to multiply $A$ by $2\cdot 3=6$. Making the changes in the opposite order first triples $A$, to $3a$, and then doubles the result, so that again you end up with $A=6a$. If $b$ and $c$ are the original values of $B$ and $C$, respectively, the new values are $2b$ and $3c$, so $BC$ has also increased by a factor of $2\cdot3=6$.

Clearly you can substitute any multipliers for $2$ and $3$ and see the same behavior.

The only point that may still not be intuitively obvious is that the outcome remains the same even when $B$ and $C$ are changed simultaneously. This is actually a consequence of the (possibly unstated) assumption that changes in $B$ and $C$ act independently on $A$.


First, have a repeating command block set to Always Active testing for a minecraft:portal block(the purple part of the nether portal):

/execute @p ~ ~ ~ testforblock ~ ~ ~ minecraft:portal

It will point into another repeating command block, also Always Active, and it will also be set to Conditional, using /spreadplayers to teleport them 2-4 blocks out of the portal.

/execute @p ~ ~ ~ spreadplayers ~ ~ 2 4 true @p

The reason /execute is used is to teleport them within a 2-4 block range of where they are currently.