squirrel-sql-client / squirrel-sql-code

Share of the SQuirreL SQL source code originating from SourceForge, see https://squirrelsql.org
GNU Lesser General Public License v2.1
65 stars 12 forks source link

Please add PostgreSQL enum support #26

Open wangyuehong opened 11 months ago

wangyuehong commented 11 months ago

sql to create enum in pg database.

CREATE TYPE aenum AS ENUM ('a', 'b', 'c');

aenum should be shown in object tree under TYPE.

gerdwagner commented 10 months ago

This is a problem of the JDBC driver: Though Connection.getMetaData().getTableTypes() returns the table type "TYPE" it doesn't return enums from Connection.getMetaData().getTables(...). The test program below illustrates the problem. Please consult your JDBC driver or database vendor about the issue.

public class PgTypeTest
{
   public static void main(String[] args) throws ClassNotFoundException, SQLException
   {
      Class.forName("org.postgresql.Driver");

      Connection con = DriverManager.getConnection("<yourDbUrl>", "yourUser", "yourPassword");

      ResultSet tableTypes = con.getMetaData().getTableTypes();

      System.out.println("Available table types:");
      while (tableTypes.next())
      {
         System.out.println(tableTypes.getString("TABLE_TYPE"));
      }

      //ResultSet types = con.getMetaData().getTables(null, null, null, null);
      ResultSet types = con.getMetaData().getTables(null, null, null, new String[]{"TYPE"});

      System.out.println("Available types:");
      while (types.next())
      {
         // Will not get here because types is empty
         System.out.println(types.getString("TABLE_NAME"));
      }
   }
}