Importing SQLite database - Mailing list pgsql-general

From Igor Korot
Subject Importing SQLite database
Date
Msg-id CA+FnnTzb8DcxXSsQhGgAtM41XPd3Ypyh90wjg6naxTg9VeTshQ@mail.gmail.com
Whole thread Raw
Responses Re: Importing SQLite database
Re: Importing SQLite database
List pgsql-general
Hi, ALL,
I have a text file which I got from exporting the SQLite database.

The file contains an SQL statement which will generate the database.

Excerpt from this file:

[code]
CREATE TABLE leagues( id INTEGER AUTOINCREMENT PRIMARY KEY, name
VARCHAR(100),balance DOUBLE(10,2));
CREATE TABLE players(playerid INTEGER AUTOINCREMENT PRIMARY KEY,
player_name VARCHAR(60), player_position CHAR(1));
CREATE TABLE player_draft(id INTEGER, playerid INTEGER,
drafted_position CHAR(1), FOREIGN KEY id REFERENCE leagues(id),
FOREIGN KEY playerid REFERENCE players(playerid));
INSERT INTO leagues VALUES(1, 'Test1', 260.00);
INSERT INTO leagues VALUES(2, 'Test2', 260.00);
INSERT INTO players VALUES(1, 'Player1', 'D');
INSERT INTO players VALUES(2, ''Player2', 'F');
[/code]

My question would be:
Is there a command in Postgres which will open this file and execute all those
commands one-by-one in a transaction?
Or I will have to do a manual table creation, then split this file and
use "LOAD..."
command to load the data into the tables?

Hopefully I made myself clear.
Let me know if not and I will try to clarify further.

Thank you.


pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: pgbasebackup necessary for master slave change?
Next
From: Tim Clarke
Date:
Subject: Re: FreeBSD 10 => 11: Dump and reload your PostgreSQL database unless you like it broken