Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

400
Vistas
how do to_date function in postgresql works?
select to_date('20170202','YYYYMMDD');

returns:

2017-02-02

but when i do:

select to_date('20172202','YYYYMMDD');

the output is :

2018-10-04

when the Month is wrong why don't it returns an error as in Oracle?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I think here is a reason why this not causing an error:

to_timestamp and to_date exist to handle input formats that cannot be converted by simple casting. These functions interpret input liberally, with minimal error checking. While they produce valid output, the conversion can yield unexpected results. For example, input to these functions is not restricted by normal ranges, thus to_date('20096040','YYYYMMDD') returns 2014-01-17 rather than causing an error. Casting does not have this behavior.

https://www.postgresql.org/docs/9.6/static/functions-formatting.html

over 4 years ago · Santiago Trujillo Denunciar

0

Now this command raise error (this issue was fixed in PostgreSQL 10):

postgres=# select to_date('20172202','YYYYMMDD');
ERROR:  date/time field value out of range: "20172202"
over 4 years ago · Santiago Trujillo Denunciar

0

i have an answer of what i wanted/ i used the to_char instead of to_date an i cast the fisrt parameter into date..

select to_char(DATE '20162202,'YYYYMMDD') into datResult ;

so i can now have an error..

thanks for your help you all

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda