平时用的比较多的SQL语句,有时候会忘掉一点点,在这里记录一下:
1.创建表的同时,插入数据:
create table test as select generate_series(1, 1000000) as id, cast(random() as text) as info , now() as crt_time;
mydb=# create table test as select generate_series(1, 1000000) as id, cast(random() as text) as info , now() as crt_time;
SELECT 1000000
mydb=# \d test
Table "public.test"
Column |
Type
| Modifiers
----------+--------------------------+-----------
id
| integer
|
info
| text
|
crt_time | timestamp with time zone |
mydb=> select pg_relation_filepath(\'test1\');
pg_relation_filepath
----------------------------------------------
pg_tblspc/16474/PG_9.5_201510051/16475/16477
(1 row)
mydb=> select pg_size_pretty(pg_relation_size(\'test1\'));
pg_size_pretty
----------------
5888 kB
(1 row)