How do I import table information?
How do I import table information?
От:
Jeff 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
Re: How do I import table information?
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Jeff Self 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
Re: How do I import table information?
От:
Patrick Welche <prlw1@newn.cam.ac.uk>
Дата:
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
Re: How do I import table information?
От:
Pete Forman <pete.forman@westerngeco.com>
Дата:
Tom Lane writes:
> Jeff Self 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.