You can write an update request for records where bookCode is null. To write this query, you must use the same logic that you use before inserting records. I don't know your table structure. If your book codes stores in same table, you can update these using join to the same table. If not, then join to another table. I wrote some sample queries for updating.
Sample 1. (Update book codes from same table):
CREATE TABLE books (
id int4 NOT NULL DEFAULT nextval('newtable_id_seq'::regclass),
bookcode int4 NULL,
bookname varchar NULL,
CONSTRAINT newtable_pk PRIMARY KEY (id)
);
INSERT INTO books (id, bookcode, bookname) VALUES(1, NULL, 'Book1');
INSERT INTO books (id, bookcode, bookname) VALUES(2, NULL, 'Book2');
INSERT INTO books (id, bookcode, bookname) VALUES(3, 1245, 'Book1');
INSERT INTO books (id, bookcode, bookname) VALUES(4, 1655, 'Book5');
INSERT INTO books (id, bookcode, bookname) VALUES(5, 2211, 'Book4');
INSERT INTO books (id, bookcode, bookname) VALUES(6, 1219, 'Book8');
INSERT INTO books (id, bookcode, bookname) VALUES(7, 9955, 'Book2');
INSERT INTO books (id, bookcode, bookname) VALUES(8, NULL, 'Book10');
INSERT INTO books (id, bookcode, bookname) VALUES(9, 3357, 'Book10');
update books b1
set
bookcode = b2.bookcode
from books b2
where
b1.bookcode is null
and b1.bookname = b2.bookname
and b2.bookcode is not null
Sample 2. Update book codes from another table
update books b1
set
bookcode = b2.bookcode
from book_code_table b2
where
b1.bookcode is null
and b1.bookname = b2.bookname