Re: Using row_to_json with %ROWTYPE ?

From: Tim Smith <randomdev4+postgres(at)gmail(dot)com>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: David Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using row_to_json with %ROWTYPE ?
Date: 2015-02-06 13:33:34
Message-ID: CA+HuS5GEPb1RA5tcFXZ3eMcOkN_-5MoROecVBSvFazGhanvo7A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nice work-around Marc. Thank you !

On 6 February 2015 at 13:01, Marc Mamin <M(dot)Mamin(at)intershop(dot)de> wrote:
>
>>Von: pgsql-general-owner(at)postgresql(dot)org
>> [pgsql-general-owner(at)postgresql(dot)org]" im Auftrag von "David Johnston
>> [david(dot)g(dot)johnston(at)gmail(dot)com]
>>Gesendet: Freitag, 6. Februar 2015 00:38
>>An: Tim Smith
>>Cc: Adrian Klaver; pgsql-general
>>Betreff: Re: [GENERAL] Using row_to_json with %ROWTYPE ?
>>On Thu, Feb 5, 2015 at 4:29 PM, Tim Smith <randomdev4+postgres(at)gmail(dot)com>
>> wrote:
>>
>> You're most welcome to look at my view definition view if you don't
>> believe me ....
>>
>> View definition:
>> SELECT a.session_id,
>> a.session_ip,
>> a.session_user_agent,
>> a.session_start,
>> a.session_lastactive,
>> b.user_id,
>> b.tenant_id,
>> b.reseller_id,
>> b.tenant_name,
>> b.user_fname,
>> b.user_lname,
>> b.user_email,
>> b.user_phone,
>> b.user_seed,
>> b.user_passwd,
>> b.user_lastupdate,
>> b.tenant_lastupdate
>> FROM app_sessions a,
>> app_users_vw b
>> WHERE a.user_id = b.user_id;
>>
>>?So that view and definition are correct.
>>So either PostgreSQL is seeing a different view (in a different schema) or
>> the function is confused in ways difficult to predict.
>>I guess it is possible that:
>>(SELECT v_?row FROM v_row) would give that message but I get a "relation
>> v_row does not exist" error when trying to replicate the scenario.
>>?It may even be a bug but since you have not provided a self-contained test
>> case, nor the version of PostgreSQL, the assumption is user error.?
>>David J.
>
> Hello,
> I don't know if there is some internal confusion when using the ROWTYPE
> (bug?)
> but if this helps, following function is equivalent and does the job:
>
> create or replace function doStuff() returns json as $$
>
> select row_to_json(app_val_session_vw) from app_val_session_vw WHERE ...;
>
> $$ LANGUAGE sql;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2015-02-06 14:09:06 Re: Partioning with overlapping and non overlapping constraints
Previous Message Guillaume Drolet 2015-02-06 13:03:30 Cluster seems broken after pg_basebackup