mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
45e2544584
composite type capability makes it possible to create a system view based on a table function in a way that is hopefully palatable to everyone. The attached patch takes advantage of this, moving show_all_settings() from contrib/tablefunc into the backend (renamed all_settings(). It is defined as a builtin returning type RECORD. During initdb a system view is created to expose the same information presently available through SHOW ALL. For example: test=# select * from pg_settings where name like '%debug%'; name | setting -----------------------+--------- debug_assertions | on debug_pretty_print | off debug_print_parse | off debug_print_plan | off debug_print_query | off debug_print_rewritten | off wal_debug | 0 (7 rows) Additionally during initdb two rules are created which make it possible to change settings by updating the system view -- a "virtual table" as Tom put it. Here's an example: Joe Conway
50 lines
3.6 KiB
SQL
50 lines
3.6 KiB
SQL
--
|
|
-- show_all_settings()
|
|
--
|
|
SELECT * FROM show_all_settings();
|
|
|
|
--
|
|
-- normal_rand()
|
|
--
|
|
SELECT * FROM normal_rand(100, 250, 5, EXTRACT(SECONDS FROM CURRENT_TIME(0))::int);
|
|
|
|
--
|
|
-- crosstab()
|
|
--
|
|
create table ct(id serial, rowclass text, rowid text, attribute text, value text);
|
|
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att1','val1');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att2','val2');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att3','val3');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test1','att4','val4');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att1','val5');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att2','val6');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att3','val7');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group1','test2','att4','val8');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att1','val1');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att2','val2');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test3','att3','val3');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att1','val4');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att2','val5');
|
|
insert into ct(rowclass, rowid, attribute, value) values('group2','test4','att3','val6');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') order by 1,2;');
|
|
|
|
select * from crosstab2('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
select * from crosstab3('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
select * from crosstab4('select rowid, attribute, value from ct where rowclass = ''group2'' order by 1,2;');
|
|
|
|
select * from crosstab('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;', 2) as c(rowid text, att1 text, att2 text);
|
|
select * from crosstab('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;', 3) as c(rowid text, att1 text, att2 text, att3 text);
|
|
select * from crosstab('select rowid, attribute, value from ct where rowclass = ''group1'' order by 1,2;', 4) as c(rowid text, att1 text, att2 text, att3 text, att4 text);
|