From: "Jerzy Bialas" <jbialas3(at)wp(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject:
Date: 2009-09-25 15:22:30
Message-ID: 4abce036419109.42346771@wp.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<div>Hi,</div>
<div>&nbsp;</div>
<div>&nbsp;I'm coming from Sybase ASE and Transact SQL.</div>
<div>Apart from long time desire to see true stored procedures in pl/pgsql,</div>
<div>with integer status and many arbitrary resultsets, I have one specific question:</div>
<div>is it possible to rename columns in rowset returned from function declared</div>
<div>as "returns table(...)" ?</div>
<div>&nbsp;</div>
<div>As far as I know, the column names are always the same as in table(...)</div>
<div>declaration, even if 'AS "name"' is used in internal query.</div>
<div>&nbsp;</div>
<div>I work with billing system in telecommunication company.</div>
<div>We have a system to publish business events about various changes to</div>
<div>MOM middleware (Websphere MQ).</div>
<div>There are triggers in various tables, and on changes, they insert records</div>
<div>into special table EVENTS:</div>
<div>&nbsp;</div>
<div>ID identity,</div>
<div>EVENT numeric(8,0),</div>
<div>STATUS char(1), -- R - new, S - sent</div>
<div>&lt;other parameters...&gt;</div>
<div>&nbsp;</div>
<div>There is a stored procedure, called periodically by external application,</div>
<div>which hits this table for STATUS=R (new) records, and, depending on EVENT field,</div>
<div>select varius data from EVENTS and other tables and returns rowset which</div>
<div>is transformed by application into XML message.</div>
<div>To make it simple, names and values of XML elements are encoded</div>
<div>as column names and column values, using "column name" = value,</div>
<div>which is Sybase equivalent of AS "column name".</div>
<div>&nbsp;</div>
<div>The whole logic is in this procedure and calling application is extremely</div>
<div>simple - it was basically unmodified (except minor bug fixing) by almost 10 years.</div>
<div>Of course, rowsets returned for different EVENT values are different - various</div>
<div>column numbers and value types, but this is perfectly OK in TSQL.</div>
<div>&nbsp;</div>
<div>I'd like to do the same in PostgreSQL, but:</div>
<div>- resulting rowset must be fixed and declared in 'returns table(...)' declaration.</div>
<div>&nbsp;I can declare all fileds "text" and convert them if needed. Ugly, butit&nbsp; should work.</div>
<div>- Number of columns in "table()" must be the highest needed and redundant columns</div>
<div>&nbsp;may be empty. Even more ugly, but it should work.</div>
<div>&nbsp;</div>
<div>Is it possible to rename columns in returned rowset ?</div>
<div>If not, perhaps I need to return 2 rowsets - the first one with</div>
<div>element names, and the 2nd one with values.</div>
<div>&nbsp;</div>
<div>Thanks in advance,</div>
<div>Jerzy</div><br /><br /><br />----------------------------------------------------<br />Rok szkolny 2009/2010.<br />Zobacz co cię czeka:<br /><A HREF="http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/rokszkolny09-10.html&sid=869" TARGET="_blank">http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/rokszkolny09-10.html&sid=869</A>

Attachment Content-Type Size
unknown_filename text/html 2.9 KB

Responses

  • Re: at 2009-09-25 16:52:09 from Pavel Stehule

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2009-09-25 15:22:57 Re: Delphi connection ?
Previous Message Mirko Pace 2009-09-25 15:05:13 UPDATE statement with syntax error doesn't raise a warning?