Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #600

Re: Returning a table in SQL

From Jasen Betts <jasen@xnet.co.nz>
Newsgroups comp.databases.postgresql
Subject Re: Returning a table in SQL
Date 2014-08-30 05:45 +0000
Organization JJ's own news server
Message-ID <ltroel$ek1$1@gonzo.reversiblemaps.ath.cx> (permalink)
References <ltignr$1hgl$1@adenine.netfront.net> <c644cpF2g32U1@mid.individual.net> <ltlfj0$1702$1@adenine.netfront.net> <c691fnFahj8U1@mid.individual.net>

Show all headers | View raw


On 2014-08-28, Harry Tuttle <SOZRBLNTLEEE@spammotel.com> wrote:
> AP wrote on 27.08.2014 22:37:
>> Actually, I figured it out :
>>
>> with report as (select some_report('Customer','2014-08-01','2014-08-08') cr)
>>   select
>>     (cr).field1,
>>     (cr).field2,
>>     (cr).field3
>>   from report;
>>
>> gives three separated columns.
>>
>> WITH clause is for clarity solely
>>
>
> It's still "wrong".
>
> You should really put the function into the from clause.
>
> select *
> from some_report('Customer','2014-08-01','2014-08-08')

both produce the same result.


never do this:

  select (some_report('Customer','2014-08-01','2014-08-08')).* ;

eg: try it with this create_report. 

create or replace function some_report(text,text,text) 
returns table ( field1 int, field2 int, field3 int )
language SQL as $$
 with a as ( select generate_series (1,4) as r order by random())
 select a.r,a.r,a.r from a $$;



-- 
umop apisdn


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Returning a table in SQL "AP" <unixpro-nospam@verizon.spam.net> - 2014-08-26 13:39 -0400
  Re: Returning a table in SQL Harry Tuttle <SOZRBLNTLEEE@spammotel.com> - 2014-08-26 21:10 +0200
    Re: Returning a table in SQL Robert Klemme <shortcutter@googlemail.com> - 2014-08-26 22:28 +0200
      Re: Returning a table in SQL Harry Tuttle <SOZRBLNTLEEE@spammotel.com> - 2014-08-26 23:34 +0200
        Re: Returning a table in SQL Robert Klemme <shortcutter@googlemail.com> - 2014-08-27 08:36 +0200
    Re: Returning a table in SQL "AP" <unixpronospam@verizon.net> - 2014-08-27 16:37 -0400
      Re: Returning a table in SQL Harry Tuttle <SOZRBLNTLEEE@spammotel.com> - 2014-08-28 17:51 +0200
        Re: Returning a table in SQL Robert Klemme <shortcutter@googlemail.com> - 2014-08-28 21:45 +0200
        Re: Returning a table in SQL Jasen Betts <jasen@xnet.co.nz> - 2014-08-30 05:45 +0000
        Re: Returning a table in SQL "AP" <unixpronospam@verizon.net> - 2014-09-01 03:02 -0400
          Re: Returning a table in SQL Jasen Betts <jasen@xnet.co.nz> - 2014-09-01 10:56 +0000
            Re: Returning a table in SQL "AP" <unixpronospam@verizon.net> - 2014-09-04 02:57 -0400
              Re: Returning a table in SQL Jasen Betts <jasen@xnet.co.nz> - 2014-09-04 11:21 +0000
  Re: Returning a table in SQL Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2014-08-27 19:33 +0200

csiph-web