Home > database >  Postgres reports coltype -7 (BIT) but qualified-name bool
Postgres reports coltype -7 (BIT) but qualified-name bool

Time:04-13

I read the type of a column using the jdbc metadata.

Using this java-code

columns = metadata.getColumns(catalogName, schema.getName(), table.getName(), "%");
while (columns.next()) {
  final String fqtn = columns.getString(6);
  int type = columns.getInt(5);
  LOG.fine("Column '"   table.getName()   "."   columnName   "' is type: "   type   " and of fqtn:"   fqtn   "!");
}

I log this output:

Column 'BUILD_RESULT.finished' is type: -7 and of fqtn:bool!

I look into java.sql.Types and looking for -7 and found BIT

enter image description here

So type -7 is BIT but name is reported bool.

There is a difference between BIT and BOOL:

  • BIT can be 0 or 1
  • BOOL can be true or false.

Why is bit (-7) reported when there is a better matching type 16 (BOOLEAN) in java.sql.Types?

I installed a sql-manager and inspect the field BUILD_RESULT.finished like this:

enter image description here

It is boolean, not bit. Why is postgres jdbc telling me it is a BIT?

EDIT: Add version of jdbc-jar

I do not have the jar-name but I have the Manifest's info:

Manifest-Version: 1.0
Bnd-LastModified: 1455914805118
Build-Jdk: 1.8.0_66
Built-By: vladimirsitnikov
Bundle-Activator: org.postgresql.osgi.PGBundleActivator
Bundle-Copyright: Copyright (c) 2003-2015, PostgreSQL Global Development
  Group
Bundle-Description: Java JDBC 4.1 (JRE 7 ) driver for PostgreSQL databas
 e
Bundle-DocURL: http://jdbc.postgresql.org/
Bundle-License: http://www.postgresql.org/about/licence/
Bundle-ManifestVersion: 2
Bundle-Name: PostgreSQL JDBC Driver JDBC41
Bundle-SymbolicName: org.postgresql.jdbc41
Bundle-Vendor: PostgreSQL Global Development Group
Bundle-Version: 9.4.1208.jre7

And select version() said: PostgreSQL 9.4.25 on x86_64-pc-linux-gnu (Ubuntu 9.4.25-1.pgdg18.04 1), compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit

CodePudding user response:

The bug is unsolved since 7 years: https://github.com/pgjdbc/pgjdbc/issues/367

Credits to a @a_horse_with_no_name

  • Related