Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4183C16AF4E6 for ; Mon, 30 Jul 2012 14:45:10 -0300 (ADT) Received: from news.hub.org ([200.46.204.72]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Svu1k-0002bo-4w for pgsql-jdbc@postgresql.org; Mon, 30 Jul 2012 17:45:09 +0000 Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.5/8.14.5) with ESMTP id q6UHisgq097712 for ; Mon, 30 Jul 2012 14:44:54 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.5/8.14.5/Submit) id q6UHc3CZ091927 for pgsql-jdbc@postgresql.org; Mon, 30 Jul 2012 14:38:03 -0300 (ADT) (envelope-from news) From: Brady Mathis X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: Opening view that uses a function - empty column Date: Mon, 30 Jul 2012 10:38:02 -0700 (PDT) Organization: http://groups.google.com Lines: 108 Message-ID: <303846e6-18ea-47c7-ab9d-83ad583bbc8d@googlegroups.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Complaints-To: groups-abuse@google.com In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=205.168.223.3; posting-account=0Pn6hwoAAAAFMfiMGGYB3MQVLeGq7kK1 User-Agent: G2/1.0 X-Received-Bytes: 3886 To: pgsql-jdbc@postgresql.org X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/49 X-Sequence-Number: 23147 Oh! And, I made another observation while cracking away at this: When I c= onnect to the DB using PGAdmin (1.14.3) from a remote workstation as oppose= d to on the DB server itself, I see the same problem with the empty externa= l_id column when executing "select * from rhs.encounter;". Could this be a problem with how I have implemented my functions? There ar= e two functions calls actually used to fill the column - I included the co= mplete 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 ); EXCEPTION WHEN OTHERS THEN RETURN XMLPARSE( DOCUMENT '' ); END; $BODY$ 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=3D"'||$1||'" and @type=3D"String"]/= text()', xmlparse(document ( rhs.get_valid_xml( array_to_string( array(sele= ct lo.data from app.menu_data md, pg_catalog.pg_largeobject lo where md.id = =3D $2 and md.xml01 =3D lo.loid), '') ) )))::text, '{}', ''); $BODY$ LANGUAGE sql VOLATILE COST 100; ALTER FUNCTION rhs.extract_from_extended(text, bigint) OWNER TO postgres; On Friday, July 27, 2012 1:46:20 PM UTC-6, Brady Mathis wrote: > Two step inquiry: >=20 >=20 >=20 >=20 >=20 > 1) I have created a function that will parse a value out of XML stored i= n the pg_largeobject table using xpath, like so: >=20 >=20 >=20 >=20 >=20 > CREATE OR REPLACE FUNCTION extract_from_extended(text, bigint) >=20 > RETURNS text AS >=20 > $BODY$ >=20 > select translate( xpath(...) ); >=20 > $BODY$ >=20 > LANGUAGE sql VOLATILE >=20 > COST 100; >=20 >=20 >=20 >=20 >=20 > 2) I then created a view that calls this function as part of the query, = like so: >=20 >=20 >=20 >=20 >=20 > CREATE OR REPLACE VIEW encounter AS=20 >=20 > SELECT md.account_id, extract_from_extended('externalEncounterID'::text, = md.id) AS external_id... >=20 > FROM app.menu_data md, app.menu_structure ms >=20 > WHERE...; >=20 >=20 >=20 > When I open this view via JDBC, there is no data in the column that is fi= lled by the function call. >=20 >=20 >=20 > Any thoughts? >=20 > TIA,=20 >=20 > BRady