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

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: tsunghan hsieh <tsunghan(dot)hsieh(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to duplicate data for few times by SQL command in PG
Date: 2015-01-22 16:32:29
Message-ID: CA+6hpa=3GgQx+pcueLOHAoOGNSNs2_qmAyCRbRvMYLpSrxkk0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Han,

Here is an example:

create table foo (v integer);
insert into foo values (23), (45), (65), (22);
create table bar (v integer);
insert into bar select v from foo, generate_series(1,5);

But note that in any relational database there is no defined order for
the rows. A table is more like a set than a list. If you want order
you must specify it with an ORDER BY clause.

It sounds like you might want to read a SQL introduction to help you
get started.

Good luck!
Paul

On Thu, Jan 22, 2015 at 7:37 AM, tsunghan hsieh
<tsunghan(dot)hsieh(at)gmail(dot)com> 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
>
> Han
>
> Original Table
> 23
> 45
> 65
> 22
>
> New Table
> 23
> 23
> 23
> 45
> 45
> 45
> 65
> 65
> 65
> 65
> 22
> 22
> 22
> 22

--
_________________________________
Pulchritudo splendor veritatis.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Julie Reier 2015-01-22 16:35:02 Problem with unixODBC and PostgreSQL
Previous Message Rémi Cura 2015-01-22 16:28:30 Re: how to calculate standard deviation from a table