summaryrefslogtreecommitdiff
path: root/install/5.005/DBD-Pg-1.22-fixvercmp/dbd-pg.pod
blob: cb37d70b69e9bb6b4dffbc0b83c389cc353fb967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

# $Id: dbd-pg.pod,v 1.1.2.1 2004-04-29 09:40:07 ivan Exp $

=head1 NAME

DBD::Pg - PostgreSQL database driver for the DBI module

=head1 DESCRIPTION

DBD::Pg is a Perl module which works with the DBI module to provide
access to PostgreSQL databases.

=head1 DBD::Pg

=begin docbook
<!-- The following blank =head1 is to allow us to use purely =head2 headings -->
<!-- This keeps the POD fairly simple with regards to Pod::DocBook -->

=end docbook

=head1

=head2 Version

Version 0.91.

=head2 Author and Contact Details

The driver author is Edmund Mergl.  He can be contacted via the
I<dbi-users> mailing list.


=head2 Supported Database Versions and Options

The DBD-Pg-0.92 module supports Postgresql 6.5.


=head2 Connect Syntax

The C<DBI-E<gt>connect()> Data Source Name, or I<DSN>, can be one of the
following:

  dbi:Pg:dbname=$dbname
  dbi:Pg:dbname=$dbname;host=$host;port=$port;options=$options;tty=$tty

All parameters, including the userid and password parameter of the 
connect command, have a hard-coded default which can be overridden 
by setting appropriate environment variables:

  Parameter  Environment Variable  Default
  ---------  --------------------  --------------
  dbname     PGDATABASE            current userid
  host       PGHOST                localhost
  port       PGPORT                5432
  options    PGOPTIONS             ""
  tty        PGTTY                 ""
  username   PGUSER                current userid
  password   PGPASSWORD            ""

There are no driver specific attributes for the C<DBI->connect()> method.


=head2 Numeric Data Handling

Postgresql supports the following numeric types:

  Postgresql     Range
  ----------     --------------------------
  int2           -32768 to +32767
  int4           -2147483648 to +2147483647
  float4         6 decimal places
  float8         15 decimal places

Some platforms also support the int8 type.
C<DBD::Pg> always returns all numbers as strings.


=head2 String Data Handling

Postgresql supports the following string data types:

  CHAR            single character
  CHAR(size)      fixed length blank-padded
  VARCHAR(size)   variable length with limit
  TEXT            variable length

All string data types have a limit of 4096 bytes. 
The CHAR type is fixed length and blank padded.

There is no special handling for data with the 8th bit set. They
are stored unchanged in the database. 
None of the character types can store embedded nulls and Unicode is
not formally supported.

Strings can be concatenated using the C<||> operator.


=head2 Date Data Handling

Postgresql supports the following date time data types:

  Type       Storage   Recommendation              Description
  ---------  --------  --------------------------  ----------------------------
  abstime     4 bytes  original date and time      limited range
  date        4 bytes  SQL92 type                  wide range
  datetime    8 bytes  best general date and time  wide range, high precision
  interval   12 bytes  SQL92 type                  equivalent to timespan
  reltime     4 bytes  original time interval      limited range, low precision
  time        4 bytes  SQL92 type                  wide range
  timespan   12 bytes  best general time interval  wide range, high precision
  timestamp   4 bytes  SQL92 type                  limited range

  Data Type    Range                               Resolution
  ----------   ----------------------------------  -----------
  abstime      1901-12-14        2038-01-19        1 sec
  timestamp    1901-12-14        2038-01-19        1 sec
  reltime      -68 years         +68 years         1 sec
  tinterval    -178000000 years  +178000000 years  1 microsec
  timespan     -178000000 years  178000000 years   1 microsec
  date         4713 BC             32767 AD        1 day
  datetime     4713 BC           1465001 AD        1 microsec
  time         00:00:00:00       23:59:59:99       1 microsec

Postgresql supports a range of date formats:

  Name           Example
  -----------    ----------------------
  ISO            1997-12-17 0:37:16-08
  SQL            12/17/1997 07:37:16.00 PST
  Postgres       Wed Dec 17 07:37:16 1997 PST
  European       17/12/1997 15:37:16.00 MET
  NonEuropean    12/17/1997 15:37:16.00 MET
  US             12/17/1997 07:37:16.00 MET

The default output format does not depend on the client/server locale.
It depends on, in increasing priority: the PGDATESTYLE environment
variable at the server, the PGDATESTYLE environment variable at the client, and
the C<SET DATESTYLE> SQL command.

All of the formats described above can be used for input. A great many
others can also be used. There is no specific default input format.
If the format of a date input is ambiguous then the current DATESTYLE
is used to help disambiguate.

If you specify a date/time value without a time component, the default 
time is 00:00:00 (midnight). To specify a date/time value without a date 
is not allowed. 
If a date with a two digit year is input then if the year was less than
70, add 2000; otherwise, add 1900.

The currect date/time is returned by the keyword C<'now'> or C<'current'>,
which has to be casted to a valid data type. For example:

  SELECT 'now'::datetime

Postgresql supports a range of date time functions for converting
between types, extracting parts of a date time value, truncating to a
given unit, etc. The usual arithmetic can be performed on date and
interval values, e.g., date-date=interval, etc.

The following SQL expression can be used to convert an integer "seconds
since 1-jan-1970 GMT" value to the corresponding database date time:

  DATETIME(unixtime_field)

and to do the reverse:

  DATE_PART('epoch', datetime_field)

The server stores all dates internally in GMT.  Times are converted to
local time on the database server before being sent to the client
frontend, hence by default are in the server time zone.

The TZ environment variable is used by the server as default time
zone.  The PGTZ environment variable on the client side is used to send
the time zone information to the backend upon connection. The SQL C<SET
TIME ZONE> command can set the time zone for the current session.


=head2 LONG/BLOB Data Handling

Postgresql handles BLOBS using a so called "large objects" type. The
handling of this type differs from all other data types. The data are
broken into chunks, which are stored in tuples in the database. Access
to large objects is given by an interface which is modelled closely
after the UNIX file system. The maximum size is limited by the file
size of the operating system.


If you just select the field, you get a "large object identifier" and
not the data itself. The I<LongReadLen> and I<LongTruncOk> attributes are
not implemented because they don't make sense in this case. The only
method implemented by the driver is the undocumented DBI method
C<blob_read()>.


=head2 Other Data Handling issues

The C<DBD::Pg> driver supports the C<type_info()> method.

Postgresql supports automatic conversions between data types wherever
it's reasonable.

=head2 Transactions, Isolation and Locking

Postgresql supports transactions.
The current default isolation transaction level is "Serializable" and
is currently implemented using table level locks. Both may change.
No other isolation levels for transactions are supported.

With AutoCommit on, a query never places a lock on a table. Readers
never block writers and writers never block readers. This behavior
changes whenever a transaction is started (AutoCommit off). Then a
query induces a shared lock on a table and blocks anyone else
until the transaction has been finished.

The C<LOCK TABLE table_name> statement can be used to apply an explicit
lock on a table. This only works inside a transaction (AutoCommit off).

To ensure that a table being selected does not change before you make
an update later in the transaction, you must explicitly lock it with a
C<LOCK TABLE> statement before executing the select.


=head2 No-Table Expression Select Syntax

To select a constant expression, that is, an expression that doesn't involve
data from a database table or view, just omit the "from" clause.
Here's an example that selects the current time as a datetime:

  SELECT 'now'::datetime;

=head2 Table Join Syntax

Outer joins are not supported. Inner joins use the traditional syntax.

=head2 Table and Column Names

The max size of table and column names cannot exceed 31 charaters in
length.
Only alphanumeric characters can be used; the first character must
be a letter.

If an identifier is enclosed by double quotation marks (C<">), it can
contain any combination of characters except double quotation marks.

Postgresql converts all identifiers to lower-case unless enclosed in
double quotation marks.
National character set characters can be used, if enclosed in quotation
marks.


=head2 Case Sensitivity of LIKE Operator

Postgresql has the following string matching operators:

 Glyph Description                                Example
 ----- ----------------------------------------   -----------------------------
 ~~    Same as SQL "LIKE" operator                'scrappy,marc' ~~ '%scrappy%'
 !~~   Same as SQL "NOT LIKE" operator            'bruce' !~~ '%al%'
 ~     Match (regex), case sensitive              'thomas' ~ '.*thomas.*'
 ~*    Match (regex), case insensitive            'thomas' ~* '.*Thomas.*'
 !~    Does not match (regex), case sensitive     'thomas' !~ '.*Thomas.*'
 !~*   Does not match (regex), case insensitive   'thomas' !~ '.*vadim.*'


=head2 Row ID

The Postgresql "row id" pseudocolumn is called I<oid>, object identifier.
It can be treated as a string and used to rapidly (re)select rows.


=head2 Automatic Key or Sequence Generation

Postgresql does not support automatic key generation such as "auto
increment" or "system generated" keys.

However, Postgresql does support "sequence generators". Any number of
named sequence generators can be created in a database. Sequences 
are used via functions called C<NEXTVAL> and C<CURRVAL>. Typical usage:

  INSERT INTO table (k, v) VALUES (nextval('seq_name'), ?);

To get the value just inserted, you can use the corresponding C<currval()>
SQL function in the same session, or

  SELECT last_value FROM seq_name


=head2 Automatic Row Numbering and Row Count Limiting

Postgresql does not support any way of automatically numbering returned rows.


=head2 Parameter Binding

Parameter binding is emulated by the driver.
Both the C<?> and C<:1> style of placeholders are supported.

The TYPE attribute of the C<bind_param()> method may be used to
influence how parameters are treated. These SQL types are bound as
VARCHAR: SQL_NUMERIC, SQL_DECIMAL, SQL_INTEGER, SQL_SMALLINT,
SQL_FLOAT, SQL_REAL, SQL_DOUBLE, SQL_VARCHAR.

The SQL_CHAR type is bound as a CHAR thus enabling fixed-width blank
padded comparison semantics.

Unsupported values of the TYPE attribute generate a warning.


=head2 Stored Procedures

C<DBD::Pg> does not support stored procedures.


=head2 Table Metadata

C<DBD::Pg> supports the C<table_info()> method.

The I<pg_attribute> table contains detailed information about all columns
of all the tables in the database, one row per table. 

The I<pg_index> table contains detailed information about all indexes in
the database, one row per index.

Primary keys are implemented as unique indexes. See I<pg_index> above.


=head2 Driver-specific Attributes and Methods

There are no significant C<DBD::Pg> driver-specific database handle attributes.

C<DBD::Pg> has the following driver-specific statement handle attributes:

=over 8

=item I<pg_size>

Returns a reference to an array of integer values for each column. The
integer shows the storage (not display) size of the column in bytes.
Variable length columns are indicated by -1.

=item I<pg_type>

Returns a reference to an array of strings for each column. The string
shows the name of the data type.

=item I<pg_oid_status>

Returns the OID of the last INSERT command.

=item I<pg_cmd_status>

Returns the name of the last command type. Possible types are: INSERT,
DELETE, UPDATE, SELECT.

=back


C<DBD::Pg> has no private methods.


=head2 Positioned updates and deletes

Postgresql does not support positioned updates or deletes.


=head2 Differences from the DBI Specification

C<DBD::Pg> has no significant differences in behavior from the
current DBI specification.

Note that C<DBD::Pg> does not fully parse the statement until
it's executed. Thus attributes like I<$sth-E<gt>{NUM_OF_FIELDS}> are not
available until after C<$sth-E<gt>execute> has been called. This is valid
behaviour but is important to note when porting applications
originally written for other drivers.


=head2 URLs to More Database/Driver Specific Information

  http://www.postgresql.org


=head2 Concurrent use of Multiple Handles

C<DBD::Pg> supports an unlimited number of concurrent database
connections to one or more databases.

It also supports the preparation and execution of a new statement
handle while still fetching data from another statement handle,
provided it is 
associated with the same database handle.


=head2 Other Significant Database or Driver Features

Postgres offers substantial additional power by incorporating the
following four additional basic concepts in such a way that users can
easily extend the system: classes, inheritance, types, and functions.

Other features provide additional power and flexibility: constraints,
triggers, rules, transaction integrity, procedural languages, and large objects.

It's also free Open Source Software with an active community of developers.

=cut

# This driver summary for DBD::Pg is Copyright (c) 1999 Tim Bunce
# and Edmund Mergl.
# $Id: dbd-pg.pod,v 1.1.2.1 2004-04-29 09:40:07 ivan Exp $