⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rowtypes.out

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 OUT
字号:
---- ROWTYPES---- Make both a standalone composite type and a table rowtypecreate type complex as (r float8, i float8);create temp table fullname (first text, last text);-- Nested compositecreate type quad as (c1 complex, c2 complex);-- Some simple tests of I/O conversions and row constructionselect (1.1,2.2)::complex, row((3.3,4.4),(5.5,null))::quad;    row    |          row           -----------+------------------------ (1.1,2.2) | ("(3.3,4.4)","(5.5,)")(1 row)select row('Joe', 'Blow')::fullname, '(Joe,Blow)'::fullname;    row     |  fullname  ------------+------------ (Joe,Blow) | (Joe,Blow)(1 row)select '(Joe,von Blow)'::fullname, '(Joe,d''Blow)'::fullname;     fullname     |   fullname   ------------------+-------------- (Joe,"von Blow") | (Joe,d'Blow)(1 row)select '(Joe,"von""Blow")'::fullname, E'(Joe,d\\\\Blow)'::fullname;     fullname      |    fullname     -------------------+----------------- (Joe,"von""Blow") | (Joe,"d\\Blow")(1 row)select '(Joe,"Blow,Jr")'::fullname;    fullname     ----------------- (Joe,"Blow,Jr")(1 row)select '(Joe,)'::fullname;	-- ok, null 2nd column fullname ---------- (Joe,)(1 row)select '(Joe)'::fullname;	-- badERROR:  malformed record literal: "(Joe)"DETAIL:  Too few columns.select '(Joe,,)'::fullname;	-- badERROR:  malformed record literal: "(Joe,,)"DETAIL:  Too many columns.create temp table quadtable(f1 int, q quad);insert into quadtable values (1, ((3.3,4.4),(5.5,6.6)));insert into quadtable values (2, ((null,4.4),(5.5,6.6)));select * from quadtable; f1 |             q             ----+---------------------------  1 | ("(3.3,4.4)","(5.5,6.6)")  2 | ("(,4.4)","(5.5,6.6)")(2 rows)select f1, q.c1 from quadtable;		-- fails, q is a table referenceERROR:  missing FROM-clause entry for table "q"select f1, (q).c1, (qq.q).c1.i from quadtable qq; f1 |    c1     |  i  ----+-----------+-----  1 | (3.3,4.4) | 4.4  2 | (,4.4)    | 4.4(2 rows)create temp table people (fn fullname, bd date);insert into people values ('(Joe,Blow)', '1984-01-10');select * from people;     fn     |     bd     ------------+------------ (Joe,Blow) | 01-10-1984(1 row)-- at the moment this will not work due to ALTER TABLE inadequacy:alter table fullname add column suffix text default '';ERROR:  cannot alter table "fullname" because column "people"."fn" uses its rowtype-- but this should work:alter table fullname add column suffix text default null;select * from people;     fn      |     bd     -------------+------------ (Joe,Blow,) | 01-10-1984(1 row)-- test insertion/updating of subfieldsupdate people set fn.suffix = 'Jr';select * from people;      fn       |     bd     ---------------+------------ (Joe,Blow,Jr) | 01-10-1984(1 row)insert into quadtable (f1, q.c1.r, q.c2.i) values(44,55,66);select * from quadtable; f1 |             q             ----+---------------------------  1 | ("(3.3,4.4)","(5.5,6.6)")  2 | ("(,4.4)","(5.5,6.6)") 44 | ("(55,)","(,66)")(3 rows)-- The object here is to ensure that toasted references inside-- composite values don't cause problems.  The large f1 value will-- be toasted inside pp, it must still work after being copied to people.create temp table pp (f1 text);insert into pp values (repeat('abcdefghijkl', 100000));insert into people select ('Jim', f1, null)::fullname, current_date from pp;select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people; first |        substr        | length  -------+----------------------+--------- Joe   | Blow                 |       4 Jim   | abcdefghijklabcdefgh | 1200000(2 rows)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -