Thread: creating tables from a disk file
I have created the database schema as a text file. It contains all the CREATE TABLE comands with the fields and their constraints. But, I cannot find a command that will have postgres accept this file and create the tables for me. The COPY (\copy) commands are only for data and so is INSERT. CREATE TABLE does not appear to have an option by which a disk file can be specified. Is there a way of having the postmaster read the specifications and create the tables, or do I re-enter them all from within psql? TIA, Rich Dr. Richard B. Shepard, President Applied Ecosystem Services, Inc. (TM) 2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A. + 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard@appl-ecosys.com http://www.appl-ecosys.com
Simply use psql and redirection... createdb database psql database < create-tables.sql Just ensuring your statements are ';' terminated or '\g' terminated, but not both! Regards, Lee Kindness. Rich Shepard writes: > I have created the database schema as a text file. It contains all the > CREATE TABLE comands with the fields and their constraints. But, I cannot > find a command that will have postgres accept this file and create the > tables for me. > > The COPY (\copy) commands are only for data and so is INSERT. CREATE TABLE > does not appear to have an option by which a disk file can be specified. > > Is there a way of having the postmaster read the specifications and create > the tables, or do I re-enter them all from within psql?
Rich Shepard <rshepard@appl-ecosys.com> writes: > I have created the database schema as a text file. It contains all the > CREATE TABLE comands with the fields and their constraints. But, I cannot > find a command that will have postgres accept this file and create the > tables for me. > > The COPY (\copy) commands are only for data and so is INSERT. CREATE TABLE > does not appear to have an option by which a disk file can be specified. > > Is there a way of having the postmaster read the specifications and create > the tables, or do I re-enter them all from within psql? A little reading of the docs would have solved your problem. ;) $ psql -f <file> or $ psql > \i <file> Is this not what you are looking for? -Doug -- Let us cross over the river, and rest under the shade of the trees. --T. J. Jackson, 1863
psql -f myschema.sql mydb ----- Original Message ----- From: "Rich Shepard" <rshepard@appl-ecosys.com> To: <pgsql-general@postgresql.org> Sent: Tuesday, February 19, 2002 10:54 AM Subject: [GENERAL] creating tables from a disk file > I have created the database schema as a text file. It contains all the > CREATE TABLE comands with the fields and their constraints. But, I cannot > find a command that will have postgres accept this file and create the > tables for me. > > The COPY (\copy) commands are only for data and so is INSERT. CREATE TABLE > does not appear to have an option by which a disk file can be specified. > > Is there a way of having the postmaster read the specifications and create > the tables, or do I re-enter them all from within psql? > > TIA, > > Rich > > Dr. Richard B. Shepard, President > > Applied Ecosystem Services, Inc. (TM) > 2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A. > + 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard@appl-ecosys.com > http://www.appl-ecosys.com > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >
On Tue, 19 Feb 2002, Gregory Wood wrote: > psql -f myschema.sql mydb Thanks everyone! The meaning of the '-f' switch escaped me last evening. I am a morning person so I should put off serious work at night. Rich Dr. Richard B. Shepard, President Applied Ecosystem Services, Inc. (TM) 2404 SW 22nd Street | Troutdale, OR 97060-1247 | U.S.A. + 1 503-667-4517 (voice) | + 1 503-667-8863 (fax) | rshepard@appl-ecosys.com http://www.appl-ecosys.com