From: | "Joel Burton" <joel(at)joelburton(dot)com> |
---|---|
To: | <gss+pg(at)cs(dot)brown(dot)edu>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: immediate set values |
Date: | 2002-05-19 21:23:10 |
Message-ID: | JGEPJNMCKODMDHGOBKDNGEMCCOAA.joel@joelburton.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Something like:
INSERT INTO mytable SELECT 1, * FROM (select 1
union all
select 2
union all
select 3
union all
select 4)
will work, but will run slowly, assuming you'll be inserting more than 4
rows at a time.
You could make a helper table that just contains integers <= n, if n is the
max number of rows you want to insert.
Then
INSERT INTO mytable SELECT 1, i FROM ints WHERE i < 100;
- J.
Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant
> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Gregory Seidman
> Sent: Sunday, May 19, 2002 5:15 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] immediate set values
>
>
> I'd like to insert into a table several pairs of values where the first
> value does not change. Rather than numerous INSERT statements, I think
> there should be a way to insert from a select with immediate values, but I
> just can't figure it out. What I'd like:
>
> INSERT INTO mytable
> SELECT 1, *
> FROM (1,2,3,4)
>
> ...which would result in inserting the pairs
>
> 1,1
> 1,2
> 1,3
> 1,4
>
> Is there some clean way of doing this, or do I really need multiple
> INSERTs?
>
> --Greg
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
From | Date | Subject | |
---|---|---|---|
Next Message | Gregory Seidman | 2002-05-19 21:34:13 | Re: immediate set values |
Previous Message | Gregory Seidman | 2002-05-19 21:15:05 | immediate set values |