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.

  • You must double-quote Id column on `COPY`. Like this: `COPY "Customers" ("Id", "Name") FROM stdin;` – Michel Milezzi Jul 04 '17 at 16:21
  • 1
    Possible duplicate of [Are PostgreSQL column names case-sensitive?](https://stackoverflow.com/questions/20878932/are-postgresql-column-names-case-sensitive) – Laurenz Albe Jul 04 '17 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 –  Jul 04 '17 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`. – Michel Milezzi Jul 04 '17 at 18:21

1 Answers1

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.

Clodoaldo Neto
  • 118,695
  • 26
  • 233
  • 260