SQL to retrieve datatype of a column

UDA
Enthusiast

SQL to retrieve datatype of a column

Hi,

I was trying to identify the datatype of a column using teradata SQL. While TYPE returns datatype of the column for all rows. So if it's 1000's of record in a column then using TYPE for that column would return 1000 times datatype of that column.

I am sure there are better way of doing this, pls let me know.

Thanks,
rlaskar
3 REPLIES
Teradata Employee

Re: SQL to retrieve datatype of a column

select type(my_foo_col) from foobar group by 1;

or

select distinct type(my_foo_col) from foobar;
Senior Apprentice

Re: SQL to retrieve datatype of a column

> select distinct type(my_foo_col) from foobar;

will be heavily skewed (all rows on a single AMP)

Better use:
select type(foobar.myfoocol);

Don't ask me why, but this is not accessing the table:

-> The row is sent directly back to the user as the result of
statement 1.

Or query the system tables:
select columntype
from dbc.columns
where databasename = 'foo' and tablename = 'foobar'
and columnname = 'myfoocol';

Dieter
Enthusiast

Re: SQL to retrieve datatype of a column

Thanks.