Skip to main content
Question

How to get ADONET VerticaTypes for table columns

  • November 26, 2021
  • 5 replies
  • 10 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
  • November 29, 2021

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
  • November 30, 2021

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
  • June 10, 2022

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
  • June 10, 2022

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
  • June 21, 2022

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;
                        }