Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

column "birthdate" is of type timestamp without time zone but expression is of type text

This query throws an error: column "birthdate" is of type timestamp without time zone but expression is of type text

INSERT INTO profile.profile(name,gender,birthDate,userId)
      SELECT 
          userId,
          substr(md5(random()::text), 0, 5) AS name,
          substr(md5(random()::text), 0, 2) AS gender,
          to_timestamp('2021-08-09 13:57:40', 'YYYY-MM-DD hh24:mi:ss') AS birthDate
      FROM 
          generate_series(1,10) AS y(userId)

My table:

      CREATE TABLE profile.profile 
        (
          id SERIAL NOT NULL, 
          name character varying NOT NULL, 
          gender character varying NOT NULL, 
          birthDate TIMESTAMP NOT NULL, 
          image character varying NOT NULL DEFAULT 
            'https://e7.pngegg.com/pngimages/274/947/png-clipart-computer-icons-user-business-believer-business-service-people.png',
          userId integer NOT NULL, 
          CONSTRAINT UQ_profile_user UNIQUE (userId), 
          CONSTRAINT PK_profile PRIMARY KEY (id)
        )

What am I doing wrong? Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

just change the order of the columns in the INSERT so that it corresponds to the order of the values to be inserted :

INSERT INTO profile.profile(userId,name,gender,birthDate)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading