Re: Using row_to_json with %ROWTYPE ?

From: Tim Smith <randomdev4+postgres(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: David Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using row_to_json with %ROWTYPE ?
Date: 2015-02-06 12:19:39
Message-ID: CA+HuS5GZU50Loqcfr=x=XkE=tn9QjGV4_x7KnAS2aW3WbSq+Sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alright then, here you go ... Postgres 9.4

We start with a clean database :

json_return_debugdb=> \dn
List of schemas
Name | Owner
--------+----------
public | postgres
(1 row)

json_return_debugdb=> \dt
No relations found.
json_return_debugdb=> \dv
No relations found.

We replicate a basic version of app_val_session_vw:

create table app_sessions (session_id bigint primary key,user_id
bigint unique not null, session_ip inet);
create table app_users (user_id bigint primary key,user_name text,
user_active boolean not null);
create view app_users_vw as select * from app_users where user_active=true;
create view app_val_session_vw as select
a.session_id,a.session_ip,b.user_name,b.user_id from app_sessions a,
app_users b where a.user_id=b.user_id;

We insert data :
insert into app_users values(1,’Foobar',true);
insert into app_sessions(441122,1,’10.11.12.13’,);

json_return_debugdb=> select
validateSession('441122','10.11.12.13','abc',3600,3600);
ERROR: Failed to validate session for session 441122 (SQLSTATE: 42702
- SQLERRM: column reference "session_id" is ambiguous)
HINT: Database error occured (sval fail)

On 5 February 2015 at 23:58, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> wrote:
> On 02/05/2015 03:25 PM, Tim Smith wrote:
>>>
>>> PostgreSQL doesn't lie
>>
>>
>> Well if its not lying its one big stinking bug !
>
>
> In my experience Postgres does not randomly make up error messages.
> Somewhere it is seeing a duplicate column.
>
>>
>> How about you tell me where you see these duplicate columns in my view
>> that PostgreSQL is apparently not lying to me about ....
>>
>
> So then this is not the problem, which moves the troubleshooting to the
> function.
>
> Have you tried the previous suggestions on modifying the function?
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Smith 2015-02-06 12:22:08 Re: Using row_to_json with %ROWTYPE ?
Previous Message David G Johnston 2015-02-06 03:12:56 Re: Partioning with overlapping and non overlapping constraints