1
我剛剛開始使用postgreSQL(我有MSSQL和MySQL的歷史),並且有關於別名的問題。如果我在一個函數聲明的SQL語句:來自PostgreSQL函數的列別名
RETURN QUERY SELECT "Table"."col1" AS "Column 1",
"Table"."col2" AS "Column 2"
FROM "Table";
突出這一點,並單獨運行它給了我什麼,我會想到:
Column 1 | Column 2
------------------------
Contents | Contents
of | of
col1 | col2
但是調用外部此功能似乎忽視了別名設定:
SELECT * FROM "f_Function"();
獲取:
col1 | col2
------------------------
Contents | Contents
of | of
col2 | col2
我試圖改變的情況下,該函數返回類型定義他們是一個更高的優先級命名的父進程:
... RETURNS TABLE (col1 integer AS "Column 1", col2 integer AS "Column 2") ...
但是,這是錯誤的語法。
正如我所說,我剛開始使用postgreSQL,所以可能會丟失明顯的東西,但我似乎無法找到任何幫助這種特定的情況。
要清楚,我希望能夠調用該函數並使列別名出現在返回的表中。
任何想法?
編輯:解決方案從尤里Levinsky
... RETURNS TABLE ("Column 1" integer, "Column 2" integer) ...
隨着
RETURN QUERY SELECT "Table"."col1",
"Table"."col2"
FROM "Table";
返回表:
Column 1 | Column 2
------------------------
Contents | Contents
of | of
col1 | col2
完美,這正是我一直在尋找的!謝謝! –