[英]Teradata SQL : insert random data for testing into Table
I am trying to create random data and insert it into a table. 我正在尝试创建随机数据并将其插入表中。 Right now just thinking what'd be the efficient approaches to get this done. 现在只是想想完成这项工作的有效方法是什么。 eg 例如
Create volatile table mytb , no fallback, no journal
( C1 integer not null
C2 Varchar (50) Not null ,
C3 D1 Date Not null,
C4 D2 date not null
) with data primary index ( c1) on commit preserve rows;
What I want is to insert value randomly for X iterations for a specific List or range of each column value . 我想要的是为每个列值的特定List或范围的X迭代随机插入值。 eg C1 range is between 30 and 3000000 C2 is a list with ( 'approved','pending','unknown','disputed','wip','processed','pre-processed','denied' ) etc C3 is a date between 01-01-1999 to 12-31-2015 etc Then for say 1 million iterations I'd like to insert random values for these columns and CREATE a SKEW for certain values- that is there should be abundance of these values vs the rest. 例如C1范围在30到3000000之间C2是一个列表('已批准','待定','未知','有争议','wip','已处理','已预处理','已拒绝')等等C3是01-01-1999到2015年3月12日之间的日期等等。然后说100万次迭代我想为这些列插入随机值并为某些值创建一个SKEW-这些值应该是丰富的与其他人相比。 Has someone had a dig at this before . 有人曾经对此进行过挖掘。 What the best way to do it - recursive Q logic ? 最好的方法是什么 - 递归Q逻辑?
I use RANDOM
to produce test data: 我使用RANDOM
生成测试数据:
SELECT
RANDOM(30,3000000) AS c1,
CASE RANDOM(1,8)
WHEN 1 THEN 'approved'
WHEN 2 THEN 'pending'
WHEN 3 THEN 'unknown'
WHEN 4 THEN 'disputed'
WHEN 5 THEN 'wip'
WHEN 6 THEN 'processed'
WHEN 7 THEN 'pre-processed'
WHEN 8 THEN 'denied'
END,
DATE '1999-01-01' + RANDOM(0,6208) -- up to 2015-12-31
FROM sys_calendar.CALENDAR -- any table with a large number of rows
This results in evenly distributed data, if you want skew you can run different insert/selects or play around with multiple RANDOMs: 这会导致均匀分布的数据,如果您想要倾斜,您可以运行不同的插入/选择或使用多个RANDOM:
RANDOM(1,50) + RANDOM(0,50)
(RANDOM(1, 50) * RANDOM(1,200) + RANDOM(0,100)) / 100.00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.