2014-09-24 39 views
-1

我想在postgresql特定的數據庫上執行postgresql等效的mysql select * from table。我能找到我需要的數據庫,當我做內表的名稱:postgresql當試圖從表中選擇所有的錯誤

SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'; 

但是當我嘗試全選在桌子上,我得到:

SELECT * from Sample; 
SELECT * from Sample; 
ERROR: relation "sample" does not exist 
LINE 1: SELECT * from Sample; 
        ^

任何想法?

+1

你有'sample'表? – zaratustra 2014-09-24 10:45:57

+4

嘗試'SELECT * from'Sample';' – wildplasser 2014-09-24 10:46:19

+1

http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS – 2014-09-24 10:46:36

回答

1

PostgreSQL是區分大小寫的。

我通常對字段,表和函數使用全部低字符。無論如何,你可以雙引號。

要充分回答你的問題,看看爲什麼和期運用報價時,我建議閱讀本特定部分:

http://www.postgresql.org/docs/current/interactive/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

+0

「* Postgresql區分大小寫*」 - 僅適用於帶引號的標識符。對於未加引號的標識符,它不是**區分大小寫(由SQL標準定義)'Foo','foo'和'FOO'全都引用同一個表,但是''Foo''和''FOO''做**不**參考同一張表。 – 2014-09-24 12:03:02

0

我試過單引號'Sample',它沒有工作。通過雙引號"Sample"修復。

+2

''Sample''是一個字符文字,而不是標識符。該手冊中記錄了以下內容:http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS和http://www.postgresql.org/docs/current /static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS – 2014-09-24 11:13:56

1

表中的鬃毛存儲在information_schema.tables中,因此您必須使用select * from information_schema.tables來查看錶格。如果你的table_schema是「公開」 嘗試一個表select select * from public.sample,是你table_schema一個不同的架構機會它是正確的。

這個鏈接將幫助您Psotgresql doc

相關問題