我正在使用以下查詢來發現(1)主鍵列和(2)列是否具有Postgresql 9.1中information_schema的缺省值。從information_schema查找Postgresql中的主鍵只有SELECT
SELECT kcu.column_name, (c.column_default is not null) AS has_default
FROM information_schema.key_column_usage kcu
JOIN information_schema.table_constraints tc ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.columns c on c.column_name = kcu.column_name and c.table_name = kcu.table_name
WHERE tc.constraint_type = 'PRIMARY KEY' AND kcu.table_name like :tablename
當數據庫所有者運行它工作正常,但是當我運行它的「只讀」的用戶(我需要在我的應用程序做的),它沒有返回數據。一些研究表明,問題在於information.table_constraints視圖;從文檔:
視圖table_constraints包含屬於當前用戶擁有或具有一些非SELECT權限的表的所有約束。
因此,爲了檢索table_constraints,我的登錄角色需要比表上的SELECT更多嗎?是否沒有辦法從information_schema獲取信息,而無需爲登錄角色提供寫入權限?