Database Reference
In-Depth Information
{"id":2,"data":0.1574,"tstampt":"2012-04-05
13:21:05.201"}
These functions are very useful as they enable us to write functions returning data
much more complex than would be possible using the standard RETURNS TABLE
syntax, but the real power of these functions comes from being able to convert arbit-
rarily complex rows.
Let's first create a simple table with some data:
create table test(
id serial primary key,
data text,
tstamp timestamp default current_timestamp
);
insert into test(data) values(random()),
(random());
Now, let's create another table, which has one column with the data type of the pre-
vious table, and insert rows from that table in the new table:
hannu=# create table test2(
hannu(# id serial primary key,
hannu(# data2 test,
hannu(# tstamp timestamp default
current_timestamp
hannu(# );
hannu=# insert into test2(data2) select test
from test;
INSERT 0 2
hannu=# select * from test2;
-[ RECORD 1
]------------------------------------
id | 5
data2 | (1,0.26281,"2012-04-05
Search WWH ::




Custom Search