About EasyMorph Tutorials & Examples Web-help

Excel export to PostgreSQL with Primary key

Do you have a quick example of specifying on export to PostgreSQL a primary key?

Can you please elaborate on what you want to achieve?

I have a excel table that has a column that has a unique identifier. I need to insert this table into a pgSQL database, and make sure that column has the constraint Primary key.

Why? I want users to be able to use the CDATA excel plugin to be able to read/update/insert and delete rows from via that CDATA ODBC connector. see: https://www.cdata.com/excel/

That connector cannot update a row, unless the table has a primary key.

Example of the table definition that works: (I did this by hand with pgadmin, after Easymorph created the table).

CREATE TABLE se3d."CellTestElectorlyte"
(
    "SAMPLE_ID" character varying(255) COLLATE pg_catalog."default" NOT NULL,
    "Date" date,
    "Creator" character varying(255) COLLATE pg_catalog."default",
    "Description" character varying(255) COLLATE pg_catalog."default",
    "Materials Include" character varying(255) COLLATE pg_catalog."default",
    "Wet Mass" character varying(255) COLLATE pg_catalog."default",
    "Mass Used (g)" character varying(255) COLLATE pg_catalog."default",
    "Processing" character varying(255) COLLATE pg_catalog."default",
    "Dry Mass produced (g)" double precision,
    "Location" character varying(255) COLLATE pg_catalog."default",
    "Comments" character varying(255) COLLATE pg_catalog."default",
    "FS5 Link to details" character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT "SAMPLE_ID" PRIMARY KEY ("SAMPLE_ID")
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE se3d."CellTestElectorlyte"
    OWNER to postgres

You can try to use the “Advanced mode” of the “Create table” command and specify PRIMARY KEY constraint for your primary key column with the “Custom definition” option:

Excellent. I was about to go to custom DB commands.

And what about creating an index on a column (just simple integer values?)

It seems that PostgreSQL doesn’t support indexes declaration in the CREATE TABLE statement. Indexes should be added with an additional custom DB column action.

To learn more about EasyMorph visit easymorph.com.