在文檔頁面 https://www.postgresql.org/docs/9.6/static/functions-comparisons.html什麼是PostgreSQL ANY/SOME語法?
ANY/SOME描述如下: expression operator ANY (array expression)
給出的表格:
create table ints1(
id int
);
create table arrays1(
ints int[]
);
和查詢:
select id from ints1 where id = any (array[1, 2]);
工作,如預期,因爲數組文字的語法是解釋性的這裏定義 https://www.postgresql.org/docs/9.6/static/arrays.html
select id from ints1 where id = any (select id from ints1 where id in (1, 2));
工作,但是爲什麼呢? 所以我想也許有1列的行智能型轉換設置爲數組類型,並試圖下面的查詢:
insert into arrays1 (ints) values (select id from ints1);
不工作 - 附近選擇
語法錯誤,然後嘗試這樣:
insert into arrays1 (ints) values (ARRAY(select id from ints1));
這工作,並插入正確的值到arrays
表中,但我沒有找到ARRAY(..)表達式應如何在文檔中工作。
我想,也許陣列(..)是某種類型轉換操作一遍,並試圖用::int[]
:
insert into arrays1 (ints) values ((select id from ints1)::int[]);
錯誤:無法投類型整數到整數[]
- 任何人都可以指向
array expression
定義的文檔 - 澄清爲什麼第二個查詢運行正常,第三個失敗
- 說明如何ARRAY(..)表達的作品,什麼是與類型轉換爲
int[]
[數組構造函數](https://www.postgresql.org/docs/current/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS)和[Array Inp ut和輸出語法](https://www.postgresql.org/docs/current/static/arrays.html#ARRAYSIO)在手冊 –
@a_horse_with_no_name中確實解釋了所有內容,但爲什麼第二個查詢可以工作 –