1

If you query tables from dbc.columns, you will get full metadata for every column, especially data type, length, nullable/non-nullable, etc. When querying views, you only get the database, table, and column names. All the other fields are null.

If I have a view that's doing nothing but select * from table, it seems that the underlying table's metadata would propagate to the view when it's compiled to database objects. This makes sense even for calculated columns since my experiments have shown that Teradata analyzes all possible logic paths to determine a calculated column's type. Here's an example:

replace view mydb.testview as
select case when 1 = 1 then 'a' else 'aaaa' end a;

create table mydb.testviewtotable as (select * from mydb.testview) with data;

show table mydb.testviewtotable;

In that case statement, only the first condition will ever return true, so the result will always be 'a'. However, when you look at the table DDL, you can see that it calculates the column as VARCHAR(4) which proves that it analyzes all cases:

a VARCHAR(4) CHARACTER SET UNICODE NOT CASESPECIFIC

Therefore, it seems reasonable to assume that this view metadata exists somewhere even though querying that view through DBC results in nulls for all but the aforementioned columns.

oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
  • 2
    There's no dbc table where the view's metadata is stored, when you Select from it the parser will resolve it's source code down to the base tables. For a single view the best way to get all metadata is `HELP COLUMN viewname.*;` – dnoeth Jul 08 '16 at 12:49
  • @dnoeth This is awesome. Is there such a thing for tables and indexes? If so, I could use those instead of querying the DBC views. Edit: I take back the last part. The `help` command only returns the column name, not the table and database. Still, having a help for tables amd indexes would be nice – oscilatingcretin Jul 08 '16 at 13:04
  • Yep, `HELP COLUMN` is only metadata on column level. It's probably not possible to return table name, there might be calculated columns based on multiple columns. The best you can get is the *source code* of all objects using `SHOW SELECT ...` (if it doesn't work you got bad luck because your DBA restricted it) – dnoeth Jul 08 '16 at 14:43
  • @dnoeth You may as well go ahead and compile all your comments into an answer so I can mark it. – oscilatingcretin Jul 09 '16 at 21:08

0 Answers0