Re: how to duplicate data for few times by SQL command in PG - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: how to duplicate data for few times by SQL command in PG
Date
Msg-id 54C22FB5.9070202@iol.ie
Whole thread Raw
In response to how to duplicate data for few times by SQL command in PG  (tsunghan hsieh <tsunghan.hsieh@gmail.com>)
List pgsql-general
On 22/01/2015 15:37, tsunghan hsieh wrote:
> Hi
>
> I have a table which just has one column as following in Original Table.
> I wanna duplicate all of data for few times and with same order as
> following in New Table. Is there anyone who can help me? Thanks

How about something like this? -

    insert into <new table>
    select <whatever> from <original table>
    cross join generate_series(1, 3)
    order by <whatever>

This assumes that you want each item duplicated the same number of times.

Hope this helps,

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie


pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: BDR Error restarted
Next
From: Michael Paquier
Date:
Subject: Re: Retrieving the role in a logical replication plugin