INSERT has more target columns than expressions

PostgreSQL INSERT has more target columns than expressions

INSERT has more target columns than expressions in PL/pgSQL

INSERT has more target columns

The cause of error: INSERT has more target columns than expressions in PL/pgSQL.
The solution is to check the number of columns from the insert row.

Create Students table

CREATE TABLE test.students
(
    id numeric NOT NULL,
    first_name character varying(50) NOT NULL,
    last_name character varying(50) NOT NULL,
    entry_date timestamp without time zone DEFAULT now(),
    address_id numeric,
    CONSTRAINT studentss_pkey PRIMARY KEY (id)
);

CREATE TABLE
Query returned successfully in 506 msec.

Wrong insert

INSERT INTO test.students (id, first_name, last_name) 
VALUES (4, 'Sandra');

ERROR: INSERT has more target columns than expressions
LINE 1: INSERT INTO test.students (id, first_name, last_name) VALUES...
                                                   ^
Query returned successfully in 430 msec.

Correct insert

INSERT INTO test.students (id, first_name, last_name) 
VALUES (4, 'Sandra', 'Green');

INSERT 0 1

Query returned successfully in 393 msec.