Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 5801616AF4E6 for ; Mon, 30 Jul 2012 17:22:46 -0300 (ADT) Received: from smtp102.prem.mail.ac4.yahoo.com ([76.13.13.41]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SvwUG-0004zL-UZ for pgsql-jdbc@postgresql.org; Mon, 30 Jul 2012 20:22:46 +0000 Received: (qmail 6289 invoked from network); 30 Jul 2012 20:22:31 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rv92m43D3Vsi0n7wjTusc8HCkOnQi8dZ7R5ZgbZrHjx2TOoPzE4uiqlT455abyj3r2FnsTMtE+7wIQ9NPQU0UmLow3pF02huqI6MVBqRTle31t7UB7D7c4t6y6RLQlHzscYzJdqECnG7VZMNF8Vx2p9Q0ITgkiKRVfzVGDMS4Ko= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1343679751; bh=DeWTfwhPq38FMyFXlGzXhxcJRf+PKH11TerwMkQEEeI=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=R+9cpfFBiDVUS8qcdGq7BGpQCDhxZY4aDlNzzbkM4ltpUM36t50xRDr0vZCTxyXLC+2pG0nNVrlB/ptdiatsq4mloAO6fgrjD5ahzhGCl4HjhxGdyAa1K1NyyOPfXfTZHgltomDzLFVmw9TuJDBuPRglkB5Xp57Hi6PmkeNNY0A= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: lZcnfE0VM1mhSevQAu3NwfXwRPU04SfHVQIb8zjzXTyoS3a ODsC8uyVhSdc.GvK7fxmi0.PRm4Y9i02p8jOVvHFh09hbZ5POTfiyV.zZm7u AV5kW4mQt8oeQz.unnkQqNuym8eqD25PfVhtrYkZj0IzDTtePmC_MtaV5rAV s5089.aOgocdgO5NQggwh7.m4bia1ZinRCu6bvp.r2T9GXZYy_i9C263MdcN iThUORA6CP8OqfL8hJuQeqjGA5p9nc1tNytTcH7kx7x3u8rn8HjtGxxADOpf vxHHpfCn4kzCB24lrtHEZQjh9Z8tqgh118vaYE3jc5rYHcCZIhBS8tjle1cr cUVAS19U6HLJvK9qT4iBnKsjwvIAa9uNoZZVYovSZmLXC8wSFizL5DA4QC10 p9mstHS2yBmgtOZA5DqmbW.JhfQ9aeLhNbCklkDCYXzbbhHB_XTDKCytJ_zj qLg7mwTh_w9gaPEE- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp102.prem.mail.ac4.yahoo.com with SMTP; 30 Jul 2012 20:22:31 +0000 UTC From: "David Johnston" To: "'Brady Mathis'" , References: <303846e6-18ea-47c7-ab9d-83ad583bbc8d@googlegroups.com> In-Reply-To: <303846e6-18ea-47c7-ab9d-83ad583bbc8d@googlegroups.com> Subject: Re: Opening view that uses a function - empty column Date: Mon, 30 Jul 2012 16:22:04 -0400 Message-ID: <021c01cd6e90$fc103900$f430ab00$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQH21I51eapvELw9ypuDn6sxpcPigAJ0+4poltvNenA= Content-Language: en-us X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/51 X-Sequence-Number: 23149 Couple of points - though they won't help the current question probably: >Brady's original ---------------my responses embedded > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > owner@postgresql.org] On Behalf Of Brady Mathis > Sent: Monday, July 30, 2012 1:38 PM > To: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] Opening view that uses a function - empty column > > Oh! And, I made another observation while cracking away at this: When I > connect to the DB using PGAdmin (1.14.3) from a remote workstation as > opposed to on the DB server itself, I see the same problem with the empty > external_id column when executing "select * from rhs.encounter;". ----------------Are you sure that when you connect to the server from "...the DB server itself" you are connecting to the same database as when you do so remotely? ----------------This really feels like an identity issue and not anything specifically related to the code you are showing us. That said...see below. > > Could this be a problem with how I have implemented my functions? There > are two functions calls actually used to fill the column - I included the > complete text of the functions below. > > get_valid_xml - ensures that content from pg_largeobject is valid xml > extract_from_extended - uses xmlparse and xpath to get one specific value > > Thanks...again! > > /* Function to validate xml for xpath use in SQL query */ CREATE OR REPLACE > FUNCTION rhs.get_valid_xml(x text) > RETURNS xml AS > $BODY$ > BEGIN > PERFORM XMLPARSE( DOCUMENT x ); > RETURN XMLPARSE( DOCUMENT x ); ------------It is unnecessary to call XMLPARSE twice, especially since you are doing so on the "no exception" code path. > EXCEPTION WHEN OTHERS THEN > RETURN XMLPARSE( DOCUMENT ' encoding="UTF-8"?>' ); END; $BODY$ ------------Whenever you are having difficulties you should avoid ignoring exceptions. At worse perform a RAISE NOTICE when one occurs it you still want to send back an empty document. However, raising the exception is also a valid and useful action. If you are debugging then raising an exception (and reviewing it) is even more worthwhile. > LANGUAGE plpgsql VOLATILE > COST 100; > ALTER FUNCTION rhs.get_valid_xml(text) OWNER TO postgres; > > > /* Function to allow extract of fields from _extended */ CREATE OR REPLACE > FUNCTION rhs.extract_from_extended(field_name text, menu_data_id > bigint) > RETURNS text AS > $BODY$ > select translate( xpath('//field[@name="'||$1||'" and > @type="String"]/text()', xmlparse(document ( rhs.get_valid_xml( > array_to_string( array(select lo.data from app.menu_data md, > pg_catalog.pg_largeobject lo where md.id = $2 and md.xml01 = lo.loid), '') ) > )))::text, '{}', ''); $BODY$ ------------Here you call XMLParse/Document on the result of "get_valid_xml(...)"; this seems redundant since "get_valid_xml(...)" already does this. > LANGUAGE sql VOLATILE > COST 100; > ALTER FUNCTION rhs.extract_from_extended(text, bigint) OWNER TO > postgres;