X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8BEBBD1B539 for ; Tue, 12 Aug 2003 03:18:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 81451-07 for ; Tue, 12 Aug 2003 00:17:26 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id B9D6FD1B550 for ; Tue, 12 Aug 2003 00:18:48 -0300 (ADT) Received: from news.hub.org (news.hub.org [64.117.224.194]) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7C3Imek012877 for ; Tue, 12 Aug 2003 03:18:48 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7C2wZfP003088 for pgsql-sql@postgresql.org; Tue, 12 Aug 2003 02:58:35 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: INSERT INTO ... SELECT Date: Mon, 11 Aug 2003 21:57:05 -0400 Organization: cbbrowne Computing Inc Lines: 33 Message-ID: References: <3F376E13.7080907@informatik.hu-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne X-Emacs-Acronym: Ever Made A Control-key Setup? Microsoft: Where even the version numbers aren't Y2K-compliant X-Uboat-Death-Message: BOMBED BY SPACE-TIME VORTEX. DEPTH CHARGES. LEAVE BOAT. U-774. User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Rational FORTRAN, linux) Cancel-Lock: sha1:bR4elyprg4WxQgwr+CzqUWZ8IWI= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/115 X-Sequence-Number: 14731 Centuries ago, Nostradamus foresaw when trissl@informatik.hu-berlin.de (Silke Trissl) would write: > I would like to insert into a table values from a table and user > defined ones. Here is the example: > > I found this statement to insert values from another table: > > INSERT INTO test_table (cust_id, cust_name) SELECT id, name from CUSTOMER; > > But the test_table has another column, which should have the same > value for all the customers. > > Is there something like > > INSERT INTO test_table (int_id, cust_id, cust_name) '1', SELECT id, > name from CUSTOMER: > > and if so, what ist the correct statement? If not, what is an > alternative to insert a single row at a time? You're close. The constant term needs to be inside the SELECT. Try: insert into test_table (int_id, cust_id, cust_name) select '1', id, name from customer; -- select 'cbbrowne' || '@' || 'acm.org'; http://www.ntlug.org/~cbbrowne/sap.html (eq? 'truth 'beauty) ; to avoid unassigned-var error, since compiled code ; will pick up previous value to var set!-ed, ; the unassigned object. -- from BBN-CL's cl-parser.scm