pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Anto Aravinth <anto.aravinth.cse@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Using COPY to import large xml file
Date: Sun, 24 Jun 2018 09:57:58 -0700
Message-ID: <3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com> (raw)
In-Reply-To: <CANtp6R+Xu_LmGEA9-5OvX=h+7UqEppJfTgB8P9EcbkLOOO0Xtw@mail.gmail.com>
References: <CANtp6R+Xu_LmGEA9-5OvX=h+7UqEppJfTgB8P9EcbkLOOO0Xtw@mail.gmail.com>

On 06/24/2018 08:25 AM, Anto Aravinth wrote:
> Hello Everyone,
> 
> I have downloaded the Stackoverflow posts xml (contains all SO questions 
> till date).. the file is around 70GB.. I wanna import the data in those 
> xml to my table.. is there a way to do so in postgres?

It is going to require some work. You will need to deal with:

1) The row schema inside the XML is here:

https://ia800107.us.archive.org/27/items/stackexchange/readme.txt

- **posts**.xml

2) The rows are inside a <posts> tag.

Seems to me you have two options:

1) Drop each row into a single XML field and deal with extracting the 
row components in the database.

2) Break down the row into column components before entering them into 
the database.

Adrien has pointed you at a Python program that covers the above:

https://github.com/Networks-Learning/stackexchange-dump-to-postgres

If you are comfortable in Python you can take a look at:

https://github.com/Networks-Learning/stackexchange-dump-to-postgres/blob/master/row_processor.py

to see how the rows are broken down into elements.

I would try this out first on one of the smaller datasets found here:

https://archive.org/details/stackexchange

I personally took a look at:

https://archive.org/download/stackexchange/beer.stackexchange.com.7z

because why not?

> 
> 
> Thanks,
> Anto.


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (18+ messages)  latest in thread

Message-ID: <3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com>
Permalink:  ../3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com/
Also on:    postgresql.org/message-id/3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, anto.aravinth.cse@gmail.com
  Subject: Re: Using COPY to import large xml file
  In-Reply-To: <3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com>
  References: <CANtp6R+Xu_LmGEA9-5OvX=h+7UqEppJfTgB8P9EcbkLOOO0Xtw@mail.gmail.com> <3b83c126-c9f6-0d1e-fecc-13fc0c8e59ec@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox