0

I am trying to import a postgresql database through sql code. I am creating all the tables with their constraints but when reaching the following code:

COPY "Customers" (Id, "Name") FROM stdin;

psql throws an

ERROR: column "id" of relation "Customers" does not exist.

Here is my Customers table

CREATE TABLE "Customers" (
"Id" serial NOT NULL,
"Name" varchar(30) NOT NULL UNIQUE
);

ALTER TABLE "Customers" OWNER TO postgres;  

ALTER TABLE ONLY "Customers"
    ADD CONSTRAINT "Customers_pkey" PRIMARY KEY ("Id");

I've just started working with postgre and im totally lost, any help will be much appreciated.

4
  • You must double-quote Id column on COPY. Like this: COPY "Customers" ("Id", "Name") FROM stdin; Commented Jul 4, 2017 at 16:21
  • 1
    Possible duplicate of Are PostgreSQL column names case-sensitive? Commented Jul 4, 2017 at 16:24
  • michel.milezzy, thats exactly how i did it initially but i got the following ERROR: invalid input syntax for integer: "" CONTEXT: COPY Customers, line 1, column Id: "" so i removed the double quotes Commented Jul 4, 2017 at 16:33
  • @StoyanLupov This happens when a empty string is cast to a integer type. Since Id column is SERIAL (has auto-increment) you can ommit it from COPY. Commented Jul 4, 2017 at 18:21

1 Answer 1

2

As commented:

COPY "Customers" ("Id", "Name") FROM stdin;

Bad idea to create identifiers wrapped in double quotes. Only do it if they are otherwise illegal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.