PostgreSQL
Installation
../configure --enable-recode --enable-locale --prefix=/usr/local/postgresql
--enable-multibyte --with-odbc --enable-syslog --mandir=/usr/share/man --docdir=/usr/share/doc
Starting and stopping the deamon / server:
- login as postgres: su postgres / psw: er und 1ch
- STOP: pg_ctl stop -D /var/lib/pgsql/data
- cd /var/lib/pgsql/
- START: postmaster -i -D /var/lib/pgsql/data/ >logfile4>&1
&
(logfile4 is the logfile name)
- Confirmation:
[1] 15516
bash-2.05a$ DEBUG: database system was shut down at 2002-09-05
11:57:40 BST
DEBUG: checkpoint record is at 0/70435C
DEBUG: redo record is at 0/70435C; undo record is at 0/0; shutdown
TRUE
DEBUG: next transaction id: 17044; next oid: 28272
DEBUG: database system is ready
The Date issue:
Bruce Mojan FAQ:
"Check your locale configuration. POSTGRESQL uses the
locale setting of the user that ran the postmaster process. There
are postgres and psql SET commands to control the
date format. Set those accordingly for your operating environment. "
In order to use the european date style by default I made the follwing
changes:
- Added two lines to : /var/lib/pgsql/.bash_profile
PGDATESTYLE="POSTGRES,EUROPEAN"
export PGDATESTYLE
- Restart Postmaster to apply the changes
- check the changes:
- psql URGENT
- SHOW DATESTYLE;
If there is no .bash_profile for postgres:
Apply the above changes to /ect/profile, which works for all users on your
machine
Later in the datatables the date looks like:
- 24/12/2002 for Christmas
- or 31/12/2002 for New Years Eve
Importing a database:
Data Preparation
- Open the table in GNUMERIC; [MS EXCEL is less flexible if it
comes to saving text file data and chosse the delimiter]
- Copy / Paste all Values on one sheet (optional)
- Change all Datestyles in the Table to dd/mm/yyyy
- Make sure all NULL values [without an entry!] are representet
by the same special character (e.g. "-" )
- BACKUP FILE: Save the dataset into your archive for backup;
e.g. in it's native format ( .gnumeric or .xls );
- IMPORT FILE:
If it comes to copying the .csv file into a PostgreSQL table, PostgreSQL
complains about empty lines and column headings / descriptions (because
they often don't fit into the column datatype; e.g. the heading string
"time" won't fit into a datatype 'time' column).
In order to create the import file delete all emty rows and all descriptive
elements, that don't represent real data records.
Then save your prepared set:
- File -> Save As -> File Format: Text File Export (*.csv);
choose a filename (e.g. sediment_baseline.csv)
- Choose a sheet(s) to export via "add"
- Choose export formatting:
Line termination: UNIX (linefeed)
Separator: choose one, that's not in the data! (e.g. pipe |)
Quoting: NEVER
Data Import
- Open the database in PostgreSQL:
[userdirk@ggrain]# psql URGENT
- create a new table, that fits your data (the example uses
case sensitive indentifier, to enable names like pH or Cu):
URGENT=# create table sediment_baseline (date date, site_id text,
"Cd" numeric(10,3), "Cu" numeric(10,3), "Ni" numeric(10,3), "Pb"
numeric(10,3), "Zn" numeric(10,3));
URGENT=> create table photos (photo_id varchar(8), source_photofile
varchar(12), photo_time time, photo_date date, photo_description text, photo_filesize_small
integer, photo_filesize_average integer, photo_filesize_large integer);
- If you have 'superuserrights' you can go straight to point 6
if not:
quit as user:
URGENT=# \q
- Login into PostgreSQL as a superuser (e.g. postgres):
[userdirk@ggrain]# su postgres
- Open the database:
[postgres@ggrain]# psql URGENT
- Copy the .csv text file into your database:
URGENT=# copy sediment_baseline from '/home/userdirk/xlsdata/current/sediment_baseline.csv'
using delimiters '|' with null as '-';
If you receive error messages, rework and (re-)prepare your source
database in GNUMERIC
Q&A from the usenet
Case sensitive identifiers in PostgreSQL
Stefan Stern wrote:
Hi NG,
I'm using PostgreSQL and PHP together.
My datasets contain scientific information like the pH value of water.
I haven't found a way to store capital letters in PostgreSQL column
names.
Is it generally impossible?
Column names and table names are called "identifiers". In the ANSI
SQL standard, it is specified that all regular identifiers are case
*insensitive*, meaning that
PH, ph, and pH would all refer to the same column. However the standard
also supports delimited identifiers, usually indicated by putting quotes
around them. Delimited identifiers are case
* sensitive* so "PH", "ph",
and "pH" refer to three different columns.
In order to use delimited column names, you'd need to do that in the
original creation of the table like this:
CREATE TABLE foo (
id INTEGER,
"pH" INTEGER,
);
In that example id is a regular identifier and "pH" is a delimited identifier.
That means that id, iD, ID can all be used to refer to the first column
and id (in lower case) will always be returned by postgreSQL as the column
name. However, only "pH" can be used to refer to the second column
and it will always be returned as "pH" (in mixed case) by postgreSQL.
--
Jeff
Usefull Links and Resources:
There are two pretty good and complete books as online versions
at the web:
- PostgreSQL: Introduction and Concepts
(ISBN 0-201-70331-9) about open-source database
PostgreSQL. It was written by
Bruce Momjian and published by
Addison-Wesley. :
- Practical PostgreSQL , John Worsley
, Joshua Drake, published by
O'Reilly:
Links: