1
테이블을 채우기 위해 임의의 값을 생성하고 싶습니다.테이블에서 임의 값 생성
CREATE TABLE t_city_ci (
ci_id SERIAL PRIMARY KEY,
ci_name VARCHAR(100) NOT NULL
);
그래서 나는이 같은 임의의 값을 삽입 :
첫째, 나는 city_table이
CREATE TABLE dw_core.t_temperatures_te (
te_id SERIAL PRIMARY KEY,
ci_id INTEGER,
te_temperature FLOAT NOT NULL,
te_date TIMESTAMP NOT NULL DEFAULT NOW()
);
: 이제
INSERT INTO t_city_ci ("ci_name")
SELECT DISTINCT(d.str)
FROM (
SELECT
(
SELECT string_agg(x, '') as str
FROM (
SELECT chr(ascii('A') + (random() * 25)::integer)
-- reference 'b' so it is correlated and re-evaluated
FROM generate_series(1, 10 + b * 0)
) AS y(x)
)
FROM generate_series(1,10000) as a(b)) as d;
를, I는 다음과 같습니다 온도 테이블이
어떻게 온도 표를 채울 수 있습니까 :
작년 (3210)- 임의의 날짜 -30 사이
- 임의의 온도와 t_city 테이블에서 50
- 임의의 값?
나는이 시도하지만 날짜는 결코 변하지 않는다 :
INSERT INTO dw_core.t_temperatures_te ("ci_id","te_temperature","te_date")
SELECT *
FROM (
SELECT (random() * (SELECT MAX(ci_id) FROM dw_core.t_city_ci) + 1)::integer
-- reference 'b' so it is correlated and re-evaluated
FROM generate_series(1, 100000)
) AS y
,(select random() * -60 + 45 FROM generate_series(1,1005)) d(f),
(select timestamp '2014-01-10 20:00:00' +
random() * (timestamp '2014-01-20 20:00:00' -
timestamp '2016-01-10 10:00:00')) dza(b)
LIMIT 1000000;
덕분에 많은