Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
la columna "expired_date" es de tipo fecha pero la expresión es de tipo texto

Quiero actualizar varias filas con varias condiciones.

Aquí está mi consulta de selección para probar el resultado.

 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)

Puede mostrar el resultado como esperaba,

Pero cuando elaboro múltiples actualizaciones con este código

 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)

tengo esto

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

register_date es la columna de fecha y hora y expired_date es varchar

¿Algo está mal con mi código?

Gracias por adelantado.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

to_char convierte la fecha en una cadena formateada. en su lugar, puede lanzarlo como una fecha.

pero la declaración de actualización también podría simplificarse a lo siguiente:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!