-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path01_extraction_tables.sql
64 lines (59 loc) · 2.13 KB
/
01_extraction_tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* SQL statements to create transactions and blocks tables if they don't already exist.
These Tables are needed for Ethereum ETL to work correctly. They are the extraction location
where all transaction and block data goes into right after having been exported.
The Tables are then truncated before each new extraction.
*/
CREATE TABLE IF NOT EXISTS transactions (
hash TEXT PRIMARY KEY,
nonce BIGINT,
transaction_index BIGINT,
from_address TEXT,
to_address TEXT,
value NUMERIC(38),
gas BIGINT,
gas_price BIGINT,
input TEXT,
receipt_cumulative_gas_used BIGINT,
receipt_gas_used BIGINT,
receipt_contract_address TEXT,
receipt_root TEXT,
receipt_status BIGINT,
block_timestamp TIMESTAMP,
block_number BIGINT,
block_hash TEXT
);
TRUNCATE TABLE transactions;
CREATE TABLE IF NOT EXISTS blocks (
number BIGINT,
hash TEXT PRIMARY KEY,
parent_hash TEXT,
nonce TEXT,
sha3_uncles TEXT,
logs_bloom TEXT,
transactions_root TEXT,
state_root TEXT,
receipts_root TEXT,
miner TEXT,
difficulty NUMERIC(38),
total_difficulty NUMERIC(38),
size BIGINT,
extra_data TEXT,
gas_limit BIGINT,
gas_used BIGINT,
timestamp TIMESTAMP,
transaction_count BIGINT
);
TRUNCATE TABLE blocks;
CREATE TABLE IF NOT EXISTS token_transfers (
token_address TEXT,
from_address TEXT,
to_address TEXT,
value NUMERIC(88),
transaction_hash TEXT,
log_index BIGINT,
block_timestamp TIMESTAMP,
block_number BIGINT,
block_hash TEXT,
PRIMARY KEY (transaction_hash, log_index)
);
TRUNCATE TABLE token_transfers;