postgresqlinsertcryptographypsqlpgcrypto

Why my psql (postgreSQL) not inserting the email and password


I've created a table using the following code and I'm encrypting the password using bf.

CREATE EXTENSION pgcrypto;
CREATE TABLE auth (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  dob DATE NOT NULL,
  email TEXT NOT NULL UNIQUE,
  password TEXT NOT NULL
);

After this If i try to INSERT the data using the following -:

INSERT INTO auth (name, dob, email, password) VALUES (
  'Divyansh'
  '1995-09-21'
  'divyanshkumar@gmail.com',
  crypt('password', gen_salt('bf'))
);

I got error "INSERT has more target columns than expressions"

enter image description here


Solution

  • It seems to me you are missing commas after each value:

    INSERT INTO auth (name, dob, email, password) VALUES (
    'Divyansh', # <--- comma here
    '1995-09-21', # <--- comma here
    'divyanshkumar@gmail.com',
    crypt('password', gen_salt('bf'))
    );
    

    It does point that there's more targets than expression, it effectively sees 2 values without commas.

    See if that works.