2017-01-30 52 views
1

我想顯示任何表達式類型的名稱。 python中的'type'函數。如何顯示postgresql表達式類型?

要有點像工作這些:

select type(1); 
'int' 

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

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

有沒有這樣的PostgreSQL中什麼?

回答

5

這就是所謂的pg_typeof()雖然它不是你想

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

返回

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

但是,您不能使用pg_typeof(select * from t1),甚至不與limit 1因爲該功能需要一個表達什麼它的輸入,而不是多列。你可以做類似的事情:pg_typeof((select some_column from t1))