Home > Back-end >  Why does this happen when I insert a date value into a table? ERROR: value too long for type charact
Why does this happen when I insert a date value into a table? ERROR: value too long for type charact

Time:04-23

I am trying to insert a DATE type value into a table. For that to happen, I used this line of code:

insert into funcionario (primeiro_nome, nome_meio, ultimo_nome, cpf, data_nascimento, endereco, sexo, salario, numero_departamento)
values ('João', 'B', 'Silva', 12345678966, '19650109', 'R. das Flores, 751, São Paulo, SP', 'M', 30000, 5);

But when I run the script I get this message:

ERROR:  value too long for type character varying(30)

The data type is set to DATE and I've also tried rewriting it in all sorts of ways, such as '1965-09-01', '1965/09/01', '1965.09.01', and so on. I have even tried to use to_date()

What should I do to revert this situation?

CodePudding user response:

it seems that your 'endereco' is most probably limited to 30 characters and you are trying to insert 33 characters in that column.

You can try shortening that text and see if this works. If yes, then you should maybe rethink the max size of that column in the table.

  • Related