Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show postgresql expression type?

Tags:

postgresql

I would like to show any expression type name. Something like 'type' function in python.

To work somewhat like these:

select type(1);
'int'

select type(ROW(1, 'abc'));
'row(int, text)'

select type(select * from t1);
'setof t1'

Is there anything like this in postgresql?

like image 958
Stepochkin Avatar asked Jan 30 '17 06:01

Stepochkin


1 Answers

It's called pg_typeof() although it's not exactly what you want

select pg_typeof(1), ROW(1, 'abc');

Returns

pg_typeof | row    
----------+--------
integer   | (1,abc)

You can't however use pg_typeof(select * from t1), not even with a limit 1 because the function requires a single expression as its input, not multiple columns. You could however do something like: pg_typeof((select some_column from t1))

like image 130
a_horse_with_no_name Avatar answered Nov 11 '22 13:11

a_horse_with_no_name