Re: how to duplicate data for few times by SQL command in PG

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: tsunghan hsieh <tsunghan(dot)hsieh(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to duplicate data for few times by SQL command in PG
Date: 2015-01-23 11:25:41
Message-ID: 54C22FB5.9070202@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2015-01-23 12:18:14 Re: Retrieving the role in a logical replication plugin
Previous Message Craig Ringer 2015-01-23 09:33:57 Re: BDR Error restarted