Re: postgresql how to duplicate rows in result.

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Alessandro Baggi <alessandro(dot)baggi(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: postgresql how to duplicate rows in result.
Date: 2017-02-14 18:34:11
Message-ID: CANu8Fiz=svs1PwSSqgHyCXMXpWW1uzUM2FHFNE-VEDDaj0GgXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Feb 14, 2017 at 1:04 PM, Alessandro Baggi <
alessandro(dot)baggi(at)gmail(dot)com> wrote:

> Hi list,
> sorry for my english, I will try to example as well. I've a query that
> joins multiple tables and return a result like:
>
>
> id,customers,phone,code,number
> 1 , aaaaaaaa,33333,123 , 2
> 2 , aassdsds,33322,211 , 1
> 3 , oooooooo,21221,221 , 1
>
>
> I need, where "number" field is > 1, to duplicate the row * N(number field
> value) with a result like this:
>
> id,customers,phone,code,number
> 1 , aaaaaaaa,33333,123 , 2
> 1 , aaaaaaaa,33333,123 , 2
> 2 , aassdsds,33322,211 , 1
> 3 , oooooooo,21221,221 , 1
>
> How I can accomplish to this problem?
>
> I'm using postgresql 9.3.15.
>
> thanks in advance.
>
> Alessandro.
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

It would be immensely helpful if you provided the schema of tables involved
with original query.
In the meantime, I suggest you look into the use of UNION.

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2017-02-14 18:36:40 Re: postgresql how to duplicate rows in result.
Previous Message Lynn Dobbs 2017-02-14 18:12:07 Re: xmlelement AND timestamps.