分类:PostGresql
2021
01-13
2021
01-13
2021
01-13
1、随机生成身份证新建一个函数,用来生成身份证号码,需要输入两个日期参数createorreplacefunctiongen_id(adate,bdate)returnstextas$$selectlpad((random()*99)::int::text,2,'0')||lpad((random()*99)::int::text,2,'0')||lpad((random()*99)::int::text,2,'0')||to_char(a+(random()*(b-a))::int,'yyyymmdd')||lpad((random()*99)::int::text,2,'0')||...
继续阅读 >
2021
01-13
创建表:CREATETABLEt_test(IDINTPRIMARYKEYNOTNULL,NAMETEXTNOTNULL,AGEINTNOTNULL,ADDRESSCHAR(50),SALARYREAL);模拟批量插入:insertintot_testSELECTgenerate_series(1,5000000)askey,repeat(chr(int4(random()*26)+65),4),(random()*(6^2))::integer,null,(random()*(10^4))::integer;解释:其中:1、generate_series(1,5000000),表示生成一个数值序列,从1到5000...
继续阅读 >
2021
01-13
我就废话不多说了,大家还是直接看实例吧~postgres=#createtablet1(aintprimarykey,btext,cdate);CREATETABLEpostgres=#createtablet2(aintprimarykey,bintreferencest1(a),ctext);CREATETABLEpostgres=#insertintot1(a,b,c)values(1,'aa',now());INSERT01postgres=#insertintot1(a,b,c)values(2,'bb',now());INSERT01postgres=#insertintot2(a,b,c)values(1,1,'aa');INSERT01postgres=...
继续阅读 >
2021
01-13
2021
01-13