Re: Using row_to_json with %ROWTYPE ? - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Using row_to_json with %ROWTYPE ?
Date
Msg-id 54D4E7CA.9080407@aklaver.com
Whole thread Raw
In response to Re: Using row_to_json with %ROWTYPE ?  (Tim Smith <randomdev4+postgres@gmail.com>)
List pgsql-general
On 02/06/2015 05:33 AM, Tim Smith wrote:
> Nice work-around Marc.  Thank you !
>

Nice that it works, but in the end it proves that the issue is not with
row_to_json and a row type, but with how %ROW_TYPE is being used in a
specific function. To prove it, using your earlier function modified for
your latest test case:

CREATE OR REPLACE FUNCTION public.dostuff()
  RETURNS json
  LANGUAGE plpgsql
AS $function$
DECLARE
v_row app_val_session_vw %ROWTYPE;
j_return json;
BEGIN
select * into strict v_row from app_val_session_vw where user_id=1;
select into j_return row_to_json(v_row);
RETURN j_return;
END;
$function$


test=# select dostuff();
                                       dostuff

-----------------------------------------------------------------------------------

{"session_id":441122,"session_ip":"10.11.12.13","user_name":"Foobar","user_id":1}
(1 row)



--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Using row_to_json with %ROWTYPE ?
Next
From: Adrian Klaver
Date:
Subject: Re: Cluster seems broken after pg_basebackup