title: PostgreSQL. json_object_agg() returns text string instead of json object
body: <p>As it is written <a href="http://www.postgresql.org/docs/9.4/static/functions-aggregate.html" rel="nofollow">here</a>, <code>json_object_agg(name, value)</code> return type is <code>json</code>. Meanwhile, if I return the value returned by <code>json_object_agg()</code> from a stored procedure:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION _getlocales()
  
  RETURNS json AS
  $BODY$DECLARE
      var json;
  BEGIN
      select into var json_object_agg("key", "values") from table;
      RETURN var;
  END;$BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
  </code></pre>
  
  <p>And call it in another function:</p>
  
  <pre><code>variable    =   _getlocales();    
  RAISE NOTICE 'DATA TYPE %', pg_typeof(variable);
  SELECT variable-&gt;&gt;'property'
  </code></pre>
  
  <p>I can not get <code>JSON</code> object field. I run into:</p>
  
  <blockquote>
    <p>ERROR:  operator does not exist: text ->> unknown</p>
  </blockquote>
  
  <p>And raised notice shows that data type is <code>text</code>.</p>
  
  <blockquote>
    <p>NOTICE:  DATA TYPE text</p>
  </blockquote>
  
  <p>I've tried to change <code>_getlocales()</code> return type to <code>jsonb</code>, but nothing was changed:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION nav._getlocales()
  RETURNS jsonb AS
  $BODY$DECLARE
      _l18nJson   jsonb;
  ...
  </code></pre>
  
  <p>Why this happens?</p>