0

非常感谢任何帮助 - 尝试将数据插入到我的数据库中的表中时遇到问题。

CREATE TABLE dwr2."DimCustomers"
(
"customer_id" smallint NOT NULL,
"company_name" VARCHAR (50) NOT NULL,
"contact_name" VARCHAR (50) NOT NULL,
"contact_title" VARCHAR (50) NOT NULL,
"address" VARCHAR (50) NOT NULL,
"city" VARCHAR (50) NOT NULL,
"region" VARCHAR (50) NOT NULL,
"postal_code" VARCHAR (50) NOT NULL,
"country" VARCHAR (50) NOT NULL,
"phone" VARCHAR (50) NOT NULL,
"fax" VARCHAR (50) NOT NULL,

PRIMARY KEY ("customer_id")
)

INSERT INTO dwr2."DimCustomers" (customer_id, company_name, contact_name,
contact_title, address, city, region, postal_code, country, phone, fax)
SELECT customer_id,company_name,contact_name,contact_title,
address,city,region,postal_code,country,phone,fax
FROM public.customers where customer_id!=0;

我收到以下错误:

ERROR:  operator does not exist: character <> integer
LINE 3: FROM public.customers where customer_id!=0;
                                           ^
HINT:  No operator matches the given name and argument types. You might need 
to add explicit type casts.
SQL state: 42883
Character: 295

在我遇到这个问题之前,所有其他表格插入都可以处理现在的问题......对程序不够熟悉以理解错误......我已经尝试了很多尝试和代码更改。任何帮助深表感谢。谢谢你。

4

1 回答 1

1

教授找到了答案……

CREATE TABLE dwr.DimCustomers
(
customer_id bpchar NOT NULL,
company_name character varying(40) NOT NULL,
contact_name character varying(30),
contact_title character varying(30),
address character varying(60),
city character varying(15),
region character varying(15),
postal_code character varying(10),
country character varying(15),
phone character varying(24),
fax character varying(24),
CONSTRAINT pk_customers PRIMARY KEY (customer_id)
)
drop table dwr.DimCustomers
INSERT INTO dwr.DimCustomers (customer_id, company_name, contact_name,
contact_title,address,city,region,postal_code,country,phone,fax)
SELECT customer_id, company_name, contact_name,
contact_title,address,city,region,postal_code,country,phone,fax
from public.customers where customer_id !='DRDAN';
于 2018-12-09T21:35:08.447 回答