3.尽量选择区分度高的列作为索引,区分度的公式是count(distinct col)/count(*),表示字段不重复的比例,比例越大我们扫描的记录数越少,唯一键的区分度是1,而一些状态、性别字段可能在大数据面前区分度就是0,那可能有人会问,这个比例有什么经验值吗?使用场景不同,这个值也很难确定,一般需要join的字段我们都要求是...
模式匹配:使用REGEXP操作符进行正则表达式匹配。 SELECT * FROM table_name WHERE column_name REGEXP 'pattern'; 复制代码使用聚合函数: 统计信息:使用聚合函数如COUNT()、SUM()、AVG()等来统计数据。 SELECT COUNT(*), SUM(column_name), AVG(column_name) FROM table_name; 复制代码分区表: 数据分区:通过...
COUNT():计数 条件函数:CASE:条件语句,类似于SQL的CASE语句。其他常用函数:COALESCE():返回第一个非NULL值。NULLIF():如果两个值相等,则返回NULL,否则返回第一个值。类型转换函数:CAST():类型转换。例如, CAST(column_name AS new_type)。其他常用函数:GREATEST() and LEAST():返回一组值中的最大值和最...
每个部门的员工个数 # count(): 括号中可以填任意非空值 select post, count(salary) from emp group by post; select post, count(post_comment) from emp group by post; 聚合函数,必须跟在group by 后面(执行顺序); 练习题: 1. 查询 "岗位名" 以及 岗位包含的所有员工名字 一行展示 # group_concat(...
函数:regexp_split_to_array(string text, pattern text [, flags text ]) 说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成数组 例子:regexp_split_to_array('hello world', E'\\s+') = {hello,world} ...
postgresql 查找PL/PGSQL函数以返回N列如果不在某个地方对列列表进行硬编码(无论是在调用函数时还是在...
create or replace function PRIMARY_KEY_MANY(t character varying, columnnames character varying, types character varying) RETURNS void AS $BODY$ DECLARE count int4 :=0; --判断是否需要添加主键 num int4 := 0; rec_column varchar; cur_column CURSOR(columnNames varchar) FOR SELECT regexp_split_...
proname => 'regexp_count', prorettype => 'int4', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_count_no_start' }, { oid => '6255', descr => 'count regexp matches', proname => 'regexp_count', prorettype => 'int4', ...
# (change requires restart) #memqcache_oiddir = '/var/log/pgpool/oiddir' # Temporary work directory to record table oids # (change requires restart) #cache_safe_memqcache_table_list = '' # Comma separated list of table names to memcache # that don't write to database # Regexp are ...
函数:regexp_split_to_array(string text, pattern text [, flags text ]) 说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成数组 例子:regexp_split_to_array('hello world', E'\\s+') = {hello,world} ...