user138084: I found this schema.
I wonder how organize the relationship with prev_block_id(prev_hash)?
I think it would be like a below schema.(Here  limited to id(hash))
CREATE TABLE block (
    id VARCHAR(8) PRIMARY KEY,
    prev_id VARCHAR(8) NOT NULL,
    FOREIGN KEY (prev_id) REFERENCES block (id),
);

However, this schema would not be able to be INSERT due to self-reference constraints.

user126793: Because you want to do this in PostgreSQL[which version?], this is what should be working for you:

Create the table.
Insert genesis as a self referencing block.
alter table block add constraint fk_prev_block_id foreign key (prev_block_id) references block(block_id)

Other engine vendors may require more simple or more complex code.

138084: <p>I found this <a href="https://github.com/blockchain-etl/bitcoin-etl#blocksjson" rel="nofollow noreferrer">schema</a>.
I wonder how organize the relationship with prev_block_id(prev_hash)?</p>
<p>I think it would be like a below schema.(Here  limited to id(hash))</p>
<pre><code>CREATE TABLE block (
    id VARCHAR(8) PRIMARY KEY,
    prev_id VARCHAR(8) NOT NULL,
    FOREIGN KEY (prev_id) REFERENCES block (id),
);
</code></pre>
<p>However, this schema would not be able to be INSERT due to self-reference constraints.</p>
 126793: <p>Because you want to do this in PostgreSQL<sup>[which version?]</sup>, this is what should be working for you:</p>
<ul>
<li>Create the table.</li>
<li>Insert genesis as a self referencing block.</li>
<li>alter table block add constraint fk_prev_block_id foreign key (prev_block_id) references block(block_id)</li>
</ul>
<p>Other engine vendors may require more simple or more complex code.</p>
