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

396
Visualizações
PostgreSQL returns java.sql.Types.OTHER when i select a constant with AS keyword

When run the select on Postgres over java

SELECT '' AS COL1, 0 AS COL2 FROM MYTABLE 1=2;

Column type is Types.OTHER both for COL1 and COL2. As it is obvious resultset has not any row.

But if I have rows in result set using the query below:

SELECT '' AS COL1, 0 AS COL2 FROM MYTABLE;

Type of COL1 is still Types.OTHER but COL2 type is Types.INTEGER. In my case I need Types.VARCHAR and Types.INTEGER even result is empty or not.

Are there any configurations on db layer or jdbc url to get Types.VARCHAR and Types.INTEGER both for two queries.

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

0

try explicit cast:

SELECT ''::VARCHAR  AS COL1, 0::INTEGER AS COL2 FROM MYTABLE;
over 4 years ago · Santiago Trujillo Relatório

0

The Postgres JDBC driver 9.4.1212 reports the type of constant 0 as Types.INTEGER = 4, regardless if there is a result or not (this may also depend on the Server version - I tested with a 9.4 server).

The string constant is still reported as Types.OTHER. For such columns ResultSetMetaData.getColumnClassName(i) returns java.lang.String, so if you encounter a Types.OTHER you can use this information to recognize the column as a character column.

If you want the ResultSetMetaData to return the wanted type, grab the sources from Github and patch the ResultSetMetaData to do this translation.

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