select 8 % 3;
select mod(8, 3);
select round(10.2);
select ceil(10.2);
select floor(10.2);
select * from test1;
select octet_length(col1), char_length(col1), octet_length(col2), char_length(col2) from test1;
insert into test1 (col3) values ('aaaaaaaaaaaaaa')
select char_length(col3) from test1;
select position('a' in 'abcd');
select substring('abcdefg' from 3 for 4 );
select split_part('abc@def@ghij', '@', 2);
select now();
select now()::timestamp with time zone;
select now()::timestamp without time zone;
select now()::date;
select now()::time without time zone;
select now()::time with time zone;
select now(), now() + interval '1 day';
select now(), now() + interval '1D';
-- 时间精度默认为6
select now(), now()::timestamp(1);
-- 时间/日期类型操作符
select date '2017-07-29' + interval '1 days';
select date '2017-07-29' - interval '1 hour';
select 100 * interval '1 second';
select interval '1 hour' / double precision '3';
-- 时间日期常用函数
select current_date, current_time, current_timestamp;
select extract(year from now());
select extract(month from now()), extract(day from now());
select extract(hour from now()), extract(minute from now()), extract(second from now());
select extract(week from now());
select extract(doy from now());
-- 布尔值 boolean
-- TRUE、t、true、y、yes、on、1
-- FALSE、f、false、n、no、off、0
-- 网络地址类型
select '192.168.1.100'::cidr;
select '192.168.1.100'::inet;
select '192.168.1.100/16'::inet;
-- cidr类型对IP地址和子网掩码合法性进行检查,而inet不会
-- macaddr、macaddr8存储MAC地址
select host(cidr '192.168.1.0/24');
select host(cidr '192.168.1.0/24');
select netmask(cidr '192.168.1.0/24');
-- 数组类型
create table array_test(
id serial,
array_i integer[],
array_t text[]
);
insert into array_test(array_i, array_t)
values (
'{1,2,3}',
'{a,b,c}'
);
select * from array_test;
insert into array_test(array_i, array_t)
values (
array[4,5,6],
array['d','e','f']
);
select array_i, array_i[1] from array_test;
select array_append(array[1,2,3], 4);
select array[1,2,3] || 4;
select array_remove(array[1,2,2,4], 2);
update array_test set array_i[1] = 9;
select * from array_test;
select array_ndims(array[[1,2,3],[4,5,6]]);
select array_length(array[1,2,3],1);
select array_position(array[1,2,3,4], 3);
select array_replace(array[1,2,5,9], 5, 10);
select array_to_string(array[1,2,null,3], ',', '10');