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 90B5BD1C47A for ; Tue, 12 Aug 2003 23:06:47 +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 27736-07 for ; Tue, 12 Aug 2003 20:05:16 -0300 (ADT) Received: from lycos.com (www5.mail.lycos.com [209.202.220.85]) by svr1.postgresql.org (Postfix) with SMTP id 437C6D1B539 for ; Tue, 12 Aug 2003 20:06:36 -0300 (ADT) Received: from Unknown/Local ([?.?.?.?]) by mailcity.com; Tue, 12 Aug 2003 23:06:33 -0000 To: pgsql-sql@postgresql.org, "Christopher Browne" Date: Tue, 12 Aug 2003 19:06:33 -0400 From: "Vernon Smith" Message-ID: Mime-Version: 1.0 X-Sent-Mail: off Reply-To: vwu98034@lycos.com X-Mailer: MailCity Service X-Priority: 3 Subject: Re: INSERT INTO ... SELECT X-Sender-Ip: 24.87.63.31 Organization: Lycos Mail (http://www.mail.lycos.com:80) Content-Type: text/plain; charset=us-ascii Content-Language: en Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=BAYES_20, FROM_ENDS_IN_NUMS, QUOTED_EMAIL_TEXT, RCVD_FAKE_HELO_DOTCOM X-Spam-Level: * X-Archive-Number: 200308/119 X-Sequence-Number: 14735 Coincidentally, I have a very similar case using some twists. The table I want to insert data is something like table A ( user01 int, user02 int, ... primary key (user01, user02), CHECK ( user01 < user02 ) ); And the user table is: tabe user_table ( user int constraint pk_user primary key UNIQUE, --PK ..., email varchar(25) not null, ... }; In the insertion statement, the user02 is obtained by a subselect statement: "select user from user where email=?". There may not exist the email in the user table. And if yes, the check condition may not be met. If the condition is not met, the two user IDs need to be switched. How the query shall be construted? Thanks for any suggestions. v. -- --------- Original Message --------- DATE: Mon, 11 Aug 2003 21:57:05 From: Christopher Browne To: pgsql-sql@postgresql.org Cc: >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 > >---------------------------(end of broadcast)--------------------------- >TIP 4: Don't 'kill -9' the postmaster > ____________________________________________________________ Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail! http://login.mail.lycos.com/r/referral?aid=27005