Thread: Creating tables from files

Creating tables from files

From
Rich Shepard
Date:
  Rather embarrassing to have to ask this, but I forget how to do it and I
cannot find the directions in the available docs; I know it's there
somewhere but I'm just not seeing it.

  I have a series of 'create table' definitions in a text file. I want to
read this into postgres to create the tables, rather than re-keying them by
hand from within the program. INSERT works on rows and COPY works on values.
What I'm trying to do is create the entire database from a schema worked out
in a file.

  I would greatly appreciate a pointer to the proper command and the manual
in which I can read the syntax and, I hope, remember it for the next time.

Thanks,

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



Re: Creating tables from files

From
Jason Earl
Date:
I am not entirely sure what you want to do but I think that what you
are looking for is the -f flag to psql.

Let's say you had a file (create.sql) that had:

CREATE TABLE foo (
        bar     SERIAL PRIMARY KEY,
        baz     text
);

and you wanted to load this into the processdata database.  The
command would look like this:

psql processdata -f create.sql

See man psql for more information, and fire up psql and do /? and
check out the /i command it does the same thing.

I hope this is helpful,
Jason Earl

Rich Shepard <rshepard@appl-ecosys.com> writes:

>   Rather embarrassing to have to ask this, but I forget how to do it
> and I cannot find the directions in the available docs; I know it's
> there somewhere but I'm just not seeing it.
>
>   I have a series of 'create table' definitions in a text file. I
> want to read this into postgres to create the tables, rather than
> re-keying them by hand from within the program. INSERT works on rows
> and COPY works on values.  What I'm trying to do is create the
> entire database from a schema worked out in a file.
>
>   I would greatly appreciate a pointer to the proper command and the
> manual in which I can read the syntax and, I hope, remember it for
> the next time.
>
> Thanks,
>
> 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

Re: Creating tables from files

From
Rich Shepard
Date:
On 6 Nov 2001, Jason Earl wrote:

> Let's say you had a file (create.sql) that had:
>
> CREATE TABLE foo (
>         bar     SERIAL PRIMARY KEY,
>         baz     text
> );
>
> and you wanted to load this into the processdata database.  The
> command would look like this:
>
> psql processdata -f create.sql
>
> See man psql for more information, and fire up psql and do /? and
> check out the /i command it does the same thing.
>
> I hope this is helpful,

  Yup. Thank you very much, Jason.

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