Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 269
bahtiyartan Avatar asked Apr 26 '17 09:04

bahtiyartan


1 Answers

try explicit cast:

SELECT ''::VARCHAR  AS COL1, 0::INTEGER AS COL2 FROM MYTABLE;
like image 71
Vao Tsun Avatar answered Oct 21 '22 09:10

Vao Tsun