Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

390
Visualizações
column "expired_date" is of type date but expression is of type text

I want update multiple row with multiple condition.

Here is my select query to test result.

select name, register_date, expired_date, to_char(register_date + interval '1 year' - interval '1 day', 'YYYY-MM-DD') from tb_agent where agent_id = agent_id and agent_id in (46,47,62)

It can show result like I expected,

But when I craft to multiple update with this code

update tb_agent set expired_date = (select to_char(register_date + interval '1 year' - interval '1 day', 'YYYY-MM-DD') from tb_agent where agent_id = agent_id) where agent_id in (46,47,62)

I got this

column "expired_date" is of type date but expression is of type text

register_date is date time column and expired_date is varchar

Is something wrong with my code?

Thanks, in advance.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

to_char converts the date to a formatted string. you can cast it instead as a date.

but the update statement could be simplified to the following as well:

update tb_agent 
set expired_date = (register_date + interval '1 year' - interval '1 day')::date
where agent_id in (46,47,62)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda