Skip to main content
Question

How to get ADONET VerticaTypes for table columns

  • Nov 26, 2021 3:47 PM UTC
  • 5 replies
  • 17 views

joergschaber
Forum|alt.badge.img+2

Hi,
is there an easy way to get table column VerticaType using the ADONET driver? Currently, I get the column types from a SELECT statement and convert those to ADONET VerticaTypes.
Naively I tried

VerticaType type= (VerticaType)Enum.Parse(typeof(VerticaType), typeName, true);

However, e.g., from v_catalog.columns or v_catalog.types I get "int" or "Integer", but VerticaType is BigInt and, therefore, the above does not work.

best, Jörg

5 replies

joergschaber
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Nov 29, 2021 11:32 AM UTC

Yes, that works!
However, when I speciy all 4 restrictions, I only get one row with meta-info for the specified column, such that

(VerticaType)Enum.Parse(typeof(VerticaType), Rows[0]["DATA_TYPE"].ToString()));

is sufficient.

When I wnat to get the meta-info for all columns of a table with one GetSchema-command, then

DataTable table = connection.GetSchema("Columns", new string[] { "<Database Name>", "<Schema Name>", "<Table Name>", null});
foreach (DataRow row in table.Rows)
{
        Console.WriteLine(row["COLUMN_NAME"] + " : " + (VerticaType)Enum.Parse(typeof(VerticaType), row["DATA_TYPE"].ToString()));
}

joergschaber
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Nov 30, 2021 7:56 AM UTC

Hi Hibiki,

yes, I noticed that the VARCHAR and LONG VARCHAR is not matched with VerticaType, however, for Insert and Update operations it still seems to work.


joergschaber
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Jun 10, 2022 2:50 PM UTC

Hi Hibiki,

I noticed a similar problem with TIMESTAMPTZ. When I have a table with a column as TIMESTAMPTZ and try to get the type using
(VerticaType)Enum.Parse(typeof(VerticaType), row["DATA_TYPE"].ToString())

the ADONET.Driver version 11.1 returns Timestamp, i.e. 93, even through row["TYPE_NAME"] == TimestampTz.
Thus, when I get the tyble and column info suing 'GetSchema'
the column TYPE_NAME = TimestampTz, but DATA_TYPE == 93. It should be 1093. Seems like another bug to me.


joergschaber
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Jun 10, 2022 3:17 PM UTC

By the way, indedd with driver version 11.1 the wrong VerticaType is returned for VARCHAR and LONG VARCHAR is fixed!
However, now there (still) is the issued with timestampTz returning the wrong Vertica type.


joergschaber
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • Jun 21, 2022 9:02 AM UTC

Well, there is a VerticaType.TimestampTz. It is just not recognized correctly, when I parse the row["DATA_TYPE"] that I get from the getSchema command. I have to handle it myself:

DataTable cols = _dbConnection.GetSchema(
                        "Columns",
                        new[] { "<DataBase>", schemaTable[0], schemaTable[1], null });
                    foreach (DataRow row in cols.Rows)
                    {
                        VerticaType dataType =
                            (VerticaType)Enum.Parse(typeof(VerticaType), row["DATA_TYPE"].ToString());
                        if (row["TYPE_NAME"].ToString() == "TimestampTz") // can be removed when bug is fixed.
                        {
                            dataType = VerticaType.TimestampTz;
                        }