如图表中,在content字段中会有一个或多个6位数的数字,例如“每日穿搭打卡87 优衣库UNIQLO新品货号:123456, 货号:112233“这样一行,该怎么把“123456”和“112233”这两组数字都提取出来,像87这样非6位的不用提取。本人小白,刚开始学习postgresql,在网上找了好久都没有找到能用的方法,求教各位大佬,帮忙写个查询语句
如果提取的字符串格式基本是“新品货号:123456, 货号:112233”的话,可以用截取字符串的形式,获取“货号:”后的的内容
获取表名及注释:
select relname as tabname,cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c
where relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname
过滤掉分表:
加条件 and relchecks=0 即可
获取字段名、类型、注释、是否为空:
SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull
FROM pg_class as c,pg_attribute as a where c.relname = '表名' and a.attrelid = c.oid and a.attnum>0