pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedinsert into help
5+ messages / 5 participants
[nested] [flat]
* insert into help
@ 1999-01-21 12:46 Walt Bigelow <walt@stimpy.com>
0 siblings, 0 replies; 5+ messages in thread
From: Walt Bigelow @ 1999-01-21 12:46 UTC (permalink / raw)
To: pgsql-sql
I have to impliment a loging facility (a table) into my database system.
As it is now, I do a 3 stage operation within access to get this done.
select the current disposition and location from our medialibrary,
update the table,
insert into the log table olddispo, oldlocal, newdispo, newlocal, etc
My question is this:
I'd like to remove one step (selecting the current info) and do the log
first:
something like
INSERT INTO tblmediastatuschangelog (librarynumber, olddispo, oldlocal,
newdispo, newlocal, date) VALUES ('1123',...
that is where I get stuck. I used INSERT INTO before like:
INSERT INTO tbladdressnew SELECT * from tbladdressold;
How might I be able to compound the insert into statment so that I can
provide values and also have it obtain olddispo, and oldlocal from the
media table?
Can this be done with SQL?
Thanks for any help!!!!
Walt
walt@stimpy.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* insert into help
@ 2010-09-22 07:32 Nicholas I <nicholas.domnic.i@gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Nicholas I @ 2010-09-22 07:32 UTC (permalink / raw)
To: pgsql-sql
Hi,
i have two tables,
---------------------------------------------------------------
*table1
id type serial, name varchar;*
*--------------------------------------------------------------
table 2
name varchar;*
---------------------------------------------------------------
i want to insert the values of table 2 into table 1, with automatic id's.
insert into table1(select * from table2);
is not working, how can i append the data to table 1 with auto incremented
or nextval.
-Nicholas I
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert into help
@ 2010-09-22 07:35 Guillaume Lelarge <guillaume@lelarge.info>
parent: Nicholas I <nicholas.domnic.i@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Guillaume Lelarge @ 2010-09-22 07:35 UTC (permalink / raw)
To: Nicholas I <nicholas.domnic.i@gmail.com>; +Cc: pgsql-sql
Le 22/09/2010 09:32, Nicholas I a écrit :
> Hi,
>
> i have two tables,
> ---------------------------------------------------------------
> *table1
>
> id type serial, name varchar;*
> *--------------------------------------------------------------
> table 2
>
> name varchar;*
> ---------------------------------------------------------------
>
> i want to insert the values of table 2 into table 1, with automatic id's.
>
> insert into table1(select * from table2);
>
> is not working, how can i append the data to table 1 with auto incremented
> or nextval.
>
INSERT INTO table1 (name) SELECT name FROM table2;
--
Guillaume
http://www.postgresql.fr
http://dalibo.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert into help
@ 2010-09-22 07:35 venkat <ven.tammineni@gmail.com>
parent: Nicholas I <nicholas.domnic.i@gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: venkat @ 2010-09-22 07:35 UTC (permalink / raw)
To: Nicholas I <nicholas.domnic.i@gmail.com>; +Cc: pgsql-sql
HI,
Please go through
http://www.java2s.com/Tutorial/Oracle/0080__Insert-Update-Delete/CopyingRowsfromOneTabletoAnotherINS...
<http://www.java2s.com/Tutorial/Oracle/0080__Insert-Update-Delete/CopyingRowsfromOneTabletoAnotherINS...
and Regards,
Venkat
On Wed, Sep 22, 2010 at 1:02 PM, Nicholas I <nicholas.domnic.i@gmail.com>wrote:
> Hi,
>
> i have two tables,
> ---------------------------------------------------------------
> *table1
>
> id type serial, name varchar;*
> *--------------------------------------------------------------
> table 2
>
> name varchar;*
> ---------------------------------------------------------------
>
> i want to insert the values of table 2 into table 1, with automatic id's.
>
> insert into table1(select * from table2);
>
> is not working, how can i append the data to table 1 with auto incremented
> or nextval.
>
> -Nicholas I
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: insert into help
@ 2010-09-24 09:37 James Kitambara <jameskitambara@yahoo.co.uk>
parent: Guillaume Lelarge <guillaume@lelarge.info>
0 siblings, 0 replies; 5+ messages in thread
From: James Kitambara @ 2010-09-24 09:37 UTC (permalink / raw)
To: Guillaume Lelarge <guillaume@lelarge.info>; +Cc: pgsql-sql
Hello Guillaume Lelarge !
I suggest you try the following question:
RE-CREATE YOUR TABLES AS FOLLOW:
CREATE SEQUENCE table1_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 10000000
START 1
CACHE 1;
CREATE TABLE TABLE1 (
ID INTEGER NOT NULL DEFAULT nextval('table1_id_seq'::regclass)
, NAME VARCHAR(200) NOT NULL
);
CREATE TABLE TABLE2 (
NAME VARCHAR(200) NOT NULL
);
------------------------INSERTING THE DATA------------------------------
INSERT INTO TABLE1 (NAME) SELECT NAME FROM TABLE2;
Note: The ID in Table1 will be generated automaticale because of
DEFAULT nextval('table1_id_seq'::regclass)
James Kitambara Computer System Analyst and Programmer
Bank of Tanzania,
P.O. Box 2939, Mobile : +255 71 3307632, Dar es Salaam, Tanzania.
--- On Wed, 22/9/10, Guillaume Lelarge <guillaume@lelarge.info> wrote:
From: Guillaume Lelarge <guillaume@lelarge.info>
Subject: Re: [SQL] insert into help
To: "Nicholas I" <nicholas.domnic.i@gmail.com>
Cc: pgsql-sql@postgresql.org
Date: Wednesday, 22 September, 2010, 8:35
Le 22/09/2010 09:32, Nicholas I a écrit :
> Hi,
>
> i have two tables,
> ---------------------------------------------------------------
> *table1
>
> id type serial, name varchar;*
> *--------------------------------------------------------------
> table 2
>
> name varchar;*
> ---------------------------------------------------------------
>
> i want to insert the values of table 2 into table 1, with automatic id's.
>
> insert into table1(select * from table2);
>
> is not working, how can i append the data to table 1 with auto incremented
> or nextval.
>
INSERT INTO table1 (name) SELECT name FROM table2;
--
Guillaume
http://www.postgresql.fr
http://dalibo.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2010-09-24 09:37 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-01-21 12:46 insert into help Walt Bigelow <walt@stimpy.com>
2010-09-22 07:32 insert into help Nicholas I <nicholas.domnic.i@gmail.com>
2010-09-22 07:35 ` Guillaume Lelarge <guillaume@lelarge.info>
2010-09-24 09:37 ` James Kitambara <jameskitambara@yahoo.co.uk>
2010-09-22 07:35 ` venkat <ven.tammineni@gmail.com>
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