Re: Using row_to_json with %ROWTYPE ?

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Using row_to_json with %ROWTYPE ?
Date: 2015-02-05 21:59:21
Message-ID: 1423173561570-5836848.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tim Smith-2 wrote
> Hi,
>
> I have a function that broadly looks like this :
>
> create function doStuff() returns json as $$
> DECLARE
> v_row my_view%ROWTYPE;
> BEGIN
> select * into strict v_row from my_view where foo=bar;
> select row_to_json(v_row) from v_row;
> END;
> $$ LANGUAGE plpgsql;
>
> However this does not seem to work ? What am I doing wrong ?

I suspect that the main issue you are encountering is that "FROM v_row" is
complaining that v_row is not a known relation.

You really need to provide error messages or your observations in situations
like this. A blanket "does not seem to work" is not enough when asking
others to identify what you are doing wrong. A self-contained example is
even better.

If the above is true then this has nothing with row_to_json other than that
is the function you choose to try and use. A simple "SELECT * FROM v_row"
would get you the same error.

David J.

--
View this message in context: http://postgresql.nabble.com/Using-row-to-json-with-ROWTYPE-tp5836841p5836848.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Smith 2015-02-05 23:01:03 Re: Using row_to_json with %ROWTYPE ?
Previous Message Adrian Klaver 2015-02-05 21:57:29 Re: Using row_to_json with %ROWTYPE ?