Как отобразить результат множественного выбора в PgAdmin III?

2987
D T
select 1 as a,4 as b, 5 as c; select 1 as a,3 as b; 

Результат отображает только `выберите 1 как a, 3 как b;

Как отобразить результат множественного выбора в PgAdmin III? `

1
pgAdmin может отображать только последний результат - кстати, PostgreSQL не поддерживает множественные наборы записей - он поддерживает множественный выбор, но результат - только последний результат 10 лет назад 1

1 ответ на вопрос

2
Erwin Brandstetter

One way around this limitation would be UNION ALL.

However, the row type of all SELECTs has has to match. So I added NULL for the missing column c in the second query. Could be any value that fits the data type:

SELECT 1 AS a, 4 AS b, 5 AS c FROM tbl_a UNION ALL SELECT 1, 3, NULL FROM tbl_b; -- aliases only needed in 1st SELECT 

Returns a single result set.

To indicate the source of each row you could add a column or slide in a row between individual SELECTs. Demonstrating both at once with VALUES expressions:

SELECT * FROM ( VALUES (1, 1, 14, 15) ,(1, 2, 17, 11) ) AS t(query, a, b, c) UNION ALL VALUES (NULL::int, NULL::int, NULL::int, NULL::int) -- delimiter UNION ALL ( VALUES (2, 3, 24, NULL::int) ,(2, 4, 27, NULL::int) ); 

Explicit type casts may be necessary. I only added what's absolutely necessary here. ->SQLfiddle demo.

Похожие вопросы