How do I import table information?

Started by Jeff Selfabout 25 years ago4 messagesgeneral
Jump to latest
#1Jeff Self
jself@greatbridge.com

I'm trying to convert a package that uses MySQL as the database. When
installing the package, you have to create the database and then run the
following command: mysql database < database.sql. The database.sql
contains the sql statements for building tables. I'm trying to use this
file to build tables under PostgreSQL. But I'm getting an error because
there are comments in the file. If I remove the comments, the file works.
I am using the command: psql -e database < /home/dir/database.sql

An example of the database.sql is this:

# Table structure for table 'adminblock'
#

CREATE TABLE adminblock (
title character varying(60),
content text
);

# Dumping data for table 'adminblock'
#

INSERT INTO adminblock VALUES ('Administration','blah,blah,blah');

Is there a way to run this script without removing the comments?

Thanks.

--
Jeff Self
Information Specialist
Great Bridge, LLC
www.greatbridge.com | www.greatbridge.org
Norfolk, VA
(757)233-5570
jself@greatbridge.com

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jeff Self (#1)
Re: How do I import table information?

Jeff Self <jself@greatbridge.com> writes:

Is there a way to run this script without removing the comments?

You'll have to change the comments to one of the SQL-standard
conventions:

-- this is a one-line comment

/* this is a comment block.
It can span as many lines as you want.
*/

I do not know whether MySQL is spec-compliant enough to accept these
same kinds of comments...

regards, tom lane

#3Patrick Welche
prlw1@newn.cam.ac.uk
In reply to: Jeff Self (#1)
Re: How do I import table information?

On Thu, Jan 18, 2001 at 12:57:47PM -0500, Jeff Self wrote:
..

But I'm getting an error because
there are comments in the file. If I remove the comments, the file works.
I am using the command: psql -e database < /home/dir/database.sql

An example of the database.sql is this:

# Table structure for table 'adminblock'
#

...

Is there a way to run this script without removing the comments?

How about

sed s/^#/--/

to get the standard SQL comment character(s)?

Cheers,

Patrick

#4Pete Forman
pete.forman@westerngeco.com
In reply to: Tom Lane (#2)
Re: How do I import table information?

Tom Lane writes:

Jeff Self <jself@greatbridge.com> writes:

Is there a way to run this script without removing the comments?

You'll have to change the comments to one of the SQL-standard
conventions:

At the risk of stating the obvious, you can keep the comments with

sed 's/^#/--/' /home/dir/database.sql | psql -e database

or ignore them with

grep -v '^#' /home/dir/database.sql | psql -e database

--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pete.forman@westerngeco.com -./\.- opinion of Schlumberger, Baker
http://www.crosswinds.net/~petef -./\.- Hughes or their divisions.