Re: insert question..

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Williams, Travis L, NPONS" <tlw(at)att(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: insert question..
Date: 2003-06-11 14:57:23
Message-ID: 20030611145723.GA10356@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 11, 2003 at 10:45:05 -0400,
"Williams, Travis L, NPONS" <tlw(at)att(dot)com> wrote:
> I'm looking for an example on how to insert static data and information from a select at the same time..
>
> currently I'm doing:
>
> insert into performance (start,finish) select min(poll_time),max(poll_time) from poll
>
> I need to add a 3rd field that is static so I would have something like this
>
>
> insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

If travis is really a constant then you could do:
insert into performance (name,start,finish)
select 'travis', min(poll_time), max(poll_time) from poll;

Another option that might be faster (if there is an index on poll_time)
because you are using max and min is:
insert into performance (name,start,finish)
values ('travis',
(select poll_time from poll order by poll_time limit 1),
(select poll_time from poll order by poll_time desc limit 1))

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rory Campbell-Lange 2003-06-11 15:09:59 Re: Options for select from function returning record?
Previous Message Tom Lane 2003-06-11 14:54:44 Re: How to find the definition of a sequence ?