子查询返回的多行

时间:2015-05-22 08:31:17

标签: sql postgresql

您好我正在编写一个查询以在表中插入值。 它给了我一个错误。

我的Qyery

INSERT INTO res_partner(
                        name,
                        company_id,
                        create_date,
                        street,
                        city,
                        display_name,
                        zip,
                        supplier,
                        ref,
                        is_company,
                        customer,
                        street2,
                        employee,
                        write_date,
                        active,
                        write_uid,
                        lang,
                        create_uid,
                        notify_email) 
       VALUES(
              (SELECT shipping_address_name FROM temp_unicom),
              1,
              LOCALTIMESTAMP,
              (SELECT shipping_address_line_1 FROM temp_unicom;),
              (SELECT shipping_address_city FROM temp_unicom),
              (SELECT shipping_address_name FROM  temp_unicom),
              (SELECT shipping_address_pincode FROM temp_unicom),
              FALSE,
              (Select sale_order_item_code FROM temp_unicom),
              FALSE,
              TRUE,
              (SELECT shipping_address_line_2 FROM temp_unicom),
              FALSE,
              LOCALTIMESTAMP,
              TRUE,
              1,
              'en_US',
              1,
              'always');

错误:

  

错误:用作表达式

的子查询返回多行

**********错误**********

  

错误:用作表达式的子查询返回多行       SQL状态:21000

我知道每个select子查询返回多行,但我不知道如何纠正它。 我的temp_unicom表中有大约15000行,我正在尝试将数据从temp_unicom插入res_partner

1 个答案:

答案 0 :(得分:6)

您的代码不是insert ... select语句的正确语法。如果要从temp_unicom表中插入多行,则应重写查询,如下所示

Insert into res_partner
(name,company_id,create_date,street,city,display_name,zip,supplier,ref,is_company,customer,street2,employee,write_date,active,write_uid,lang,create_uid,notify_email) 
Select shipping_address_name,1, LOCALTIMESTAMP, shipping_address_name, 
shipping_address_line_1,shipping_address_city,
shipping_address_name,shipping_address_pincode,sale_order_item_code,FALSE,
shipping_address_line_2,FALSE, LOCALTIMESTAMP, TRUE,1,'en_US',1,'always'
from temp_unicom