pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedOk, what am I doing wrong here?
5+ messages / 4 participants
[nested] [flat]
* Ok, what am I doing wrong here?
@ 2004-02-17 16:02 Karl Denninger <karl@denninger.net>
0 siblings, 3 replies; 5+ messages in thread
From: Karl Denninger @ 2004-02-17 16:02 UTC (permalink / raw)
To: pgsql-sql
I want to insert values from one table into another, and add some "default"
values (that are not defaults on the table different reasons - that is, this
is maintenance function and in normal operation there would be "real" values
there - and null is valid)
So, I want to do, for example, the following:
insert into table (id, time, type) values (select id, now(), '1' from secondtable);
Postgres's command line pukes on this, complaining that "select" is invalid
inside the values part of the definition.
SQL's language specification says otherwise, as does "\h insert" from the
command line.
The query stand-alone returns a table with values that are valid for the
table I wish to insert into.
Where's my brain-fade on this?
--
--
Karl Denninger (karl@denninger.net) Internet Consultant & Kids Rights Activist
http://www.denninger.net Tired of spam at your company? LOOK HERE!
http://childrens-justice.org Working for family and children's rights
http://diversunion.org LOG IN AND GET YOUR TANK STICKERS TODAY!
http://scubaforum.org Come talk about DIVING!
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Ok, what am I doing wrong here?
@ 2004-02-17 16:20 Marc G. Fournier <scrappy@postgresql.org>
parent: Karl Denninger <karl@denninger.net>
2 siblings, 0 replies; 5+ messages in thread
From: Marc G. Fournier @ 2004-02-17 16:20 UTC (permalink / raw)
To: Karl Denninger <karl@denninger.net>; +Cc: pgsql-sql
On Tue, 17 Feb 2004, Karl Denninger wrote:
> I want to insert values from one table into another, and add some "default"
> values (that are not defaults on the table different reasons - that is, this
> is maintenance function and in normal operation there would be "real" values
> there - and null is valid)
>
> So, I want to do, for example, the following:
>
> insert into table (id, time, type) values (select id, now(), '1' from secondtable);
>
> Postgres's command line pukes on this, complaining that "select" is invalid
> inside the values part of the definition.
>
> SQL's language specification says otherwise, as does "\h insert" from the
> command line.
>
> The query stand-alone returns a table with values that are valid for the
> table I wish to insert into.
>
> Where's my brain-fade on this?
INSERT INTO table (id, time, type) SELECT id, now(), '1' FROM secondtable;
----
Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Ok, what am I doing wrong here?
@ 2004-02-17 16:29 Stephan Szabo <sszabo@megazone.bigpanda.com>
parent: Karl Denninger <karl@denninger.net>
2 siblings, 1 reply; 5+ messages in thread
From: Stephan Szabo @ 2004-02-17 16:29 UTC (permalink / raw)
To: Karl Denninger <karl@denninger.net>; +Cc: pgsql-sql
sszabo@bigpanda.com
On Tue, 17 Feb 2004, Karl Denninger wrote:
> I want to insert values from one table into another, and add some "default"
> values (that are not defaults on the table different reasons - that is, this
> is maintenance function and in normal operation there would be "real" values
> there - and null is valid)
>
> So, I want to do, for example, the following:
>
> insert into table (id, time, type) values (select id, now(), '1' from secondtable);
>
> Postgres's command line pukes on this, complaining that "select" is invalid
> inside the values part of the definition.
>
> SQL's language specification says otherwise, as does "\h insert" from the
> command line.
I think what you want is
insert into table (id, time, type) select id, now(), '1' from secondtable;
The choices allowed right now are default values, something that is
basically a row constructor with values [*] or a query.
[*] - The full spec allows a list of row constructors but we don't
currently.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Ok, what am I doing wrong here?
@ 2004-02-17 16:34 Tomasz Myrta <jasiek@klaster.net>
parent: Karl Denninger <karl@denninger.net>
2 siblings, 0 replies; 5+ messages in thread
From: Tomasz Myrta @ 2004-02-17 16:34 UTC (permalink / raw)
To: Karl Denninger <karl@denninger.net>; +Cc: pgsql-sql
Dnia 2004-02-17 17:02, Użytkownik Karl Denninger napisał:
> I want to insert values from one table into another, and add some "default"
> values (that are not defaults on the table different reasons - that is, this
> is maintenance function and in normal operation there would be "real" values
> there - and null is valid)
>
> So, I want to do, for example, the following:
>
> insert into table (id, time, type) values (select id, now(), '1' from secondtable);
Documentation says:
INSERT INTO table [ ( column [, ...] ) ]
{ DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) |
SELECT query }
insert into table (id, time, type)
select id, now(), '1' from secondtable;
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Ok, what am I doing wrong here?
@ 2004-02-17 16:58 Karl Denninger <karl@denninger.net>
parent: Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 0 replies; 5+ messages in thread
From: Karl Denninger @ 2004-02-17 16:58 UTC (permalink / raw)
To: Stephan Szabo <sszabo@megazone.bigpanda.com>; +Cc: pgsql-sql
Thanks...
--
--
Karl Denninger (karl@denninger.net) Internet Consultant & Kids Rights Activist
http://www.denninger.net Tired of spam at your company? LOOK HERE!
http://childrens-justice.org Working for family and children's rights
http://diversunion.org LOG IN AND GET YOUR TANK STICKERS TODAY!
http://scubaforum.org Come talk about DIVING!
On Tue, Feb 17, 2004 at 08:29:06AM -0800, Stephan Szabo wrote:
> sszabo@bigpanda.com
>
> On Tue, 17 Feb 2004, Karl Denninger wrote:
>
> > I want to insert values from one table into another, and add some "default"
> > values (that are not defaults on the table different reasons - that is, this
> > is maintenance function and in normal operation there would be "real" values
> > there - and null is valid)
> >
> > So, I want to do, for example, the following:
> >
> > insert into table (id, time, type) values (select id, now(), '1' from secondtable);
> >
> > Postgres's command line pukes on this, complaining that "select" is invalid
> > inside the values part of the definition.
> >
> > SQL's language specification says otherwise, as does "\h insert" from the
> > command line.
>
> I think what you want is
> insert into table (id, time, type) select id, now(), '1' from secondtable;
>
> The choices allowed right now are default values, something that is
> basically a row constructor with values [*] or a query.
>
> [*] - The full spec allows a list of row constructors but we don't
> currently.
>
>
>
> %SPAMBLOCK-SYS: Matched [@postgresql.org], message ok
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2004-02-17 16:58 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-17 16:02 Ok, what am I doing wrong here? Karl Denninger <karl@denninger.net>
2004-02-17 16:20 ` Marc G. Fournier <scrappy@postgresql.org>
2004-02-17 16:29 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-02-17 16:58 ` Karl Denninger <karl@denninger.net>
2004-02-17 16:34 ` Tomasz Myrta <jasiek@klaster.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox