2

there were a lot of related questions to this topic, but none of the ones I found could solve my issue.

I'm just trying to run a file to create a table in my database "test_scheduler". The table is created just fine; however, when I run the file to seed the table with boolean values... nothing happens and I receive an

ERROR:  INSERT has more target columns than expressions

Here is the file that creates the table:

DROP TABLE IF EXISTS operation;


CREATE TABLE operation (
  id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
  monday INTEGER NOT NULL DEFAULT FALSE,
  tuesday BOOLEAN NOT NULL DEFAULT FALSE,
  wednesday BOOLEAN NOT NULL DEFAULT FALSE,
  thursday BOOLEAN NOT NULL DEFAULT FALSE,
  friday BOOLEAN NOT NULL DEFAULT FALSE,
  saturday BOOLEAN NOT NULL DEFAULT FALSE,
  sunday BOOLEAN NOT NULL DEFAULT FALSE
);

Here is the Seed File:

TRUNCATE operation;

INSERT INTO operation
  (monday, tuesday, wednesday, thursday, friday, saturday, sunday)
  VALUES
    (FALSE),
    (FALSE),
    (TRUE),
    (FALSE),
    (FALSE),
    (FALSE),
    (FALSE);

I previously added created and seeded two tables in this same database as well. I've poured over this seed file and I just am not sure what to do.

Here is the full statement and error:

psql:C:/Users/Eli/Desktop/SQL/seed.operation-hours.sql:11: ERROR:  INSERT has more target columns than expressions
LINE 2:   (monday, tuesday, wednesday, thursday, friday, saturday, s...

I've tried different variations of the create and seed files, for instance, I've forgone "NOT NULL", "DEFAULT", I've set the default values to "false", false, '0',etc. Nothing I do in the files makes a difference. I appreciate any and all help!

ezg
  • 715
  • 2
  • 7
  • 20

1 Answers1

2

Your code is inserting seven rows with one value each rather than seven columns into one row. The syntax you want is:

INSERT INTO operation (monday, tuesday, wednesday, thursday, friday, saturday, sunday)
  VALUES (FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786