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

Re: Linux Format Gambas Easy Database Access!

From: Marcus Engene <mengpg(at)engene(dot)se>
To: john hedge <johnhedge(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Linux Format Gambas Easy Database Access!
Date: 2005-11-27 00:38:44
Message-ID: 43890014.40306@engene.se (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

In unix a process has stdin (normally keyboard), stdout (echo in a 
script etc) and stderr (error messages) by default. However, you can 
override this and the process won't know.

echo 'abcd' > test.txt

tells the shell to let the output of the program echo go to file 
test.txt instead of the screen (ie redirect of stdout). For stderr 
different shells have different syntax. The 2> thing has to do with 
this. In the example below you tell stderr to go where stdout goes 
(~/logfile).

If you do

psql database < data.sql

...the shell uses file data.sql as stdin instead of "the keyboard". That 
is, the content of data.sql is treated as if you would have been typing 
it by hand.
  cat data.sql | psql database
...would do the same thing as pipe connects stdout of the program to the 
left to stdin of the program to the right.

The error message indicates that there is no file data.sql in the 
current directory.

Hope this helps,
Marcus


john hedge wrote:
> Hi,
> 
> As you'll realise I'm new to all things Postgresql (& Gambas) and e-mail 
> lists.
> 
> I'm following Dr Bain's article in LXF71.
> 
> Everything has gone ok (now) up until the introduction of "< data.sql"
> as per below.
> 
> Can someone explain what we're trying to do here, and more importantly
> why it's not working and what I've done wrong, please?
> 
> TIA
> 
> John
> 
> postgres(at)zaphod2:~$ /usr/lib/postgresql/bin/initdb
> -D /usr/local/pgsql/data/
> The files belonging to this database system will be owned by user
> "postgres".
> This user must also own the server process.
> 
> The database cluster will be initialized with locale C.
> 
> initdb: directory "/usr/local/pgsql/data/" exists but is not empty
> If you want to create a new database system, either remove or empty
> the directory "/usr/local/pgsql/data/" or run initdb with an argument
> other than
> "/usr/local/pgsql/data/".
> postgres(at)zaphod2:~$ /usr/lib/postgresql/bin
> /postmaster
> -D /usr/local/pgsql/data/ >~/logfile 2>&1 &
> [1] 14081
> postgres(at)zaphod2:~$ /usr/lib/postgresql/bin/createdb customers CREATE
> DATABASE
> [1]+  Exit 1                  /usr/lib/postgresql/bin/postmaster
> -D /usr/local/pgsql/data/ >~/logfile 2>&1
> postgres(at)zaphod2:~$ /usr/lib/postgresql/bin/psql customers < data.sql
> bash: data.sql: No such file or directory


In response to

pgsql-novice by date

Next:From: operationsengineer1Date: 2005-11-27 03:07:00
Subject: Re: 8.0.2 Install Problems on Win XP
Previous:From: Jaime CasanovaDate: 2005-11-27 00:12:24
Subject: Re: How do I get an OID from a record in table?

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