How do I use text script containing SQL?

Поиск
Список
Период
Сортировка
Искать

How do I use text script containing SQL?

От:
"Jeff S." <pgsqluser@yahoo.com>
Дата:
I want to build my tables by placing all the sql
statements in a file. What is the correct way to use
this file with psql?

Example: My text file has this in it:

CREATE TABLE table1 (  table1_id serial,  field1  char(5),  PRIMARY KEY (table1_id)
);

I want to be able to use the file to create my table.
I've tried psql -d databasename -e < filename.txt
but that doesn't work.

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Re: How do I use text script containing SQL?

От:
clayton cottingham <drfrog@smartt.com>
Дата:
"Jeff S." wrote:
> 
> I want to build my tables by placing all the sql
> statements in a file. What is the correct way to use
> this file with psql?
> 
> Example: My text file has this in it:
> 
> CREATE TABLE table1 (
>    table1_id serial,
>    field1  char(5),
>    PRIMARY KEY (table1_id)
> );
> 
> I want to be able to use the file to create my table.
> I've tried psql -d databasename -e < filename.txt
> but that doesn't work.
> 
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



the  syntax is 
psql database < file

Re: How do I use text script containing SQL?

От:
David Olbersen <dave@slickness.org>
Дата:
On Mon, 5 Mar 2001, Jeff S. wrote:

->I want to be able to use the file to create my table.
->I've tried psql -d databasename -e < filename.txt
->but that doesn't work.

You're making it too dificult :-)
'psql -d databasename < filename.txt' should work just fine

-- Dave


Re: How do I use text script containing SQL?

От:
Mathijs Brands <mathijs@ilse.nl>
Дата:
On Mon, Mar 05, 2001 at 11:08:40AM -0800, David Olbersen allegedly wrote:
> On Mon, 5 Mar 2001, Jeff S. wrote:
> 
> ->I want to be able to use the file to create my table.
> ->I've tried psql -d databasename -e < filename.txt
> ->but that doesn't work.
> 
> You're making it too dificult :-)
> 'psql -d databasename < filename.txt' should work just fine

Strange, the syntax you used (psql -d  -e) should work...

serv0:~$ echo '\d ntree' | psql -d iig -e        Table "ntree"Attribute |  Type   | Modifier
-----------+---------+----------pid       | integer |cid       | integer |
Indices: idx_ntree_cid,        idx_ntree_pid

I'm using psql 7.0.3 and I'm pretty sure it also works for 6.5.x.

Mathijs
-- 
It's not that perl programmers are idiots, it's that the language
rewards idiotic behavior in a way that no other language or tool has
ever done.                                                   Erik Naggum

Re: How do I use text script containing SQL?

От:
Jie Liang <jliang@ipinc.com>
Дата:

if you are a user with privalege can create table

psql -e dbname I want to build my tables by placing all the sql
> statements in a file. What is the correct way to use
> this file with psql?
> 
> Example: My text file has this in it:
> 
> CREATE TABLE table1 (
>    table1_id serial,
>    field1  char(5),
>    PRIMARY KEY (table1_id)
> );
> 
> I want to be able to use the file to create my table.
> I've tried psql -d databasename -e < filename.txt
> but that doesn't work.
> 
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail. 
> http://personal.mail.yahoo.com/
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 


Re: How do I use text script containing SQL?

От:
Andrew Perrin <andrew_perrin@unc.edu>
Дата:
psql 
\i filename.txt

-Andy Perrin

"Jeff S." wrote:
> 
> I want to build my tables by placing all the sql
> statements in a file. What is the correct way to use
> this file with psql?
> 
> Example: My text file has this in it:
> 
> CREATE TABLE table1 (
>    table1_id serial,
>    field1  char(5),
>    PRIMARY KEY (table1_id)
> );
> 
> I want to be able to use the file to create my table.
> I've tried psql -d databasename -e < filename.txt
> but that doesn't work.
> 
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

FAQ