Skip site navigation (1) Skip section navigation (2)

Re: sql files in psql ?

From: Joe Brenner <doom(at)kzsu(dot)stanford(dot)edu>
To: Mariateresa L <mariateresa(dot)ll(at)bresciaonline(dot)it>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: sql files in psql ?
Date: 2010-05-31 21:37:55
Message-ID: 201005312138.o4VLbtjT031486@kzsu.stanford.edu (view raw or flat)
Thread:
Lists: pgsql-novice
Mariateresa L <mariateresa(dot)ll(at)bresciaonline(dot)it> wrote:

> [...] I cannot
> convince psql that the SQL commands (select, insert or
> copy...) it has to handle come from a file.
> I can submit  ("\i filename" or "psql --file filename")
> files that contains commands, eg starting with "\" but
> psql does not understand the same sintax if tne file
> contains a simple "SELECT * FROM tablex".

If I understand what you're saying, I can't reproduce the problem.

With a "tmp.sql" containing:

  create table nameo (nameo text);
  insert into nameo (nameo) VALUES ('bingo'), ('bonzo'), ('bang');
  select * from nameo;

I see this behavior:

psql --file tmp.sql
CREATE TABLE
INSERT 0 3

-------
(3 rows)
 bang
 bingo
 bonzo
 nameo


I'm on ununtu jaunty, using bash and PostgreSQL 8.3.7.

> P.S. Initially I discarded the use of procedural
> languages (C or ...) for a quick and simpler solution !

Myself, I wouldn't try to put together a db-backed app without
a glue language (e.g. perl).

In response to

Responses

pgsql-novice by date

Next:From: Mladen GogalaDate: 2010-05-31 21:51:28
Subject: Re: sql files in psql ?
Previous:From: Lonni J FriedmanDate: 2010-05-31 21:25:26
Subject: Re: psql in bash scrpts, is possible ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group