214
214
available for discussion of matters pertaining to PostgreSQL. To
215
215
subscribe, send mail with the following lines in the body (not the
216
216
subject line)
217
- subscribe
218
- end
217
+ subscribe
218
+ end
219
219
220
220
to pgsql-general-request@PostgreSQL.org.
221
221
222
222
There is also a digest list available. To subscribe to this list, send
223
223
email to: pgsql-general-digest-request@PostgreSQL.org with a body of:
224
- subscribe
225
- end
224
+ subscribe
225
+ end
226
226
227
227
Digests are sent out to members of this list whenever the main list
228
228
has received around 30k of messages.
229
229
230
230
The bugs mailing list is available. To subscribe to this list, send
231
231
email to pgsql-bugs-request@PostgreSQL.org with a body of:
232
-
233
- subscribe
234
- end
232
+ subscribe
233
+ end
235
234
236
235
There is also a developers discussion mailing list available. To
237
236
subscribe to this list, send email to
238
237
pgsql-hackers-request@PostgreSQL.org with a body of:
239
-
240
- subscribe
241
- end
238
+ subscribe
239
+ end
242
240
243
241
Additional mailing lists and information about PostgreSQL can be found
244
242
via the PostgreSQL WWW home page at:
284
282
http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM.
285
283
286
284
Another one is "Teach Yourself SQL in 21 Days, Second Edition" at
287
- http://members.tripod.com/er4ebus/sql/index.htm
285
+ http://members.tripod.com/er4ebus/sql/index.htm
288
286
289
287
Many of our users like The Practical SQL Handbook, Bowman, Judith S.,
290
288
et al., Addison-Wesley. Others like The Complete Reference SQL, Groff
558
556
Both postmaster and postgres have several debug options available.
559
557
First, whenever you start the postmaster, make sure you send the
560
558
standard output and error to a log file, like:
561
- cd /usr/local/pgsql
562
- ./bin/postmaster >server.log 2>&1 &
559
+ cd /usr/local/pgsql
560
+ ./bin/postmaster >server.log 2>&1 &
563
561
564
562
This will put a server.log file in the top-level PostgreSQL directory.
565
563
This file contains useful information about problems or errors
668
666
4.5) How do you remove a column from a table?
669
667
670
668
We do not support ALTER TABLE DROP COLUMN, but do this:
671
- SELECT ... -- select all columns but the one you want to remove
672
- INTO TABLE new_table
673
- FROM old_table;
674
- DROP TABLE old_table;
675
- ALTER TABLE new_table RENAME TO old_table;
669
+ SELECT ... -- select all columns but the one you want to remove
670
+ INTO TABLE new_table
671
+ FROM old_table;
672
+ DROP TABLE old_table;
673
+ ALTER TABLE new_table RENAME TO old_table;
676
674
677
675
4.6) What is the maximum size for a row, table, database?
678
676
679
677
These are the limits:
680
678
Maximum size for a database? unlimited (60GB databases exist)
681
679
Maximum size for a table? unlimited on all operating systems
682
680
Maximum size for a row? 8k, configurable to 32k
683
- Maximum number of rows in a table? unlimited
681
+ Maximum number of rows in a table? unlimited
684
682
Maximum number of columns in a table? unlimited
685
683
Maximum number of indexes on a table? unlimited
686
684
@@ -798,7 +796,7 @@ Maximum number of indexes on a table? unlimited
798
796
case-insensitive regular expression matching. There is no
799
797
case-insensitive variant of the LIKE operator, but you can get the
800
798
effect of case-insensitive LIKE with this:
801
- WHERE lower(textfield) LIKE lower(pattern)
799
+ WHERE lower(textfield) LIKE lower(pattern)
802
800
803
801
4.14) In a query, how do I detect if a field is NULL?
804
802
@@ -818,27 +816,27 @@ BYTEA bytea variable-length byte array (null-safe)
818
816
some error messages.
819
817
820
818
The last four types above are "varlena" types (i.e., the first four
821
- bytes on disk are the length, followed by the data). Thus the actual
822
- space used is slightly greater than the declared size. However, these
819
+ bytes on disk are the length, followed by the data). Thus the actual
820
+ space used is slightly greater than the declared size. However, these
823
821
data types are also subject to compression or being stored out-of-line
824
822
by TOAST, so the space on disk might also be less than expected.
825
823
826
824
4.16.1) How do I create a serial/auto-incrementing field?
827
825
828
826
PostgreSQL supports a SERIAL data type. It auto-creates a sequence and
829
827
index on the column. For example, this:
830
- CREATE TABLE person (
831
- id SERIAL,
832
- name TEXT
833
- );
828
+ CREATE TABLE person (
829
+ id SERIAL,
830
+ name TEXT
831
+ );
834
832
835
833
is automatically translated into this:
836
- CREATE SEQUENCE person_id_seq;
837
- CREATE TABLE person (
838
- id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
839
- name TEXT
840
- );
841
- CREATE UNIQUE INDEX person_id_key ON person ( id );
834
+ CREATE SEQUENCE person_id_seq;
835
+ CREATE TABLE person (
836
+ id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
837
+ name TEXT
838
+ );
839
+ CREATE UNIQUE INDEX person_id_key ON person ( id );
842
840
843
841
See the create_sequence manual page for more information about
844
842
sequences. You can also use each row's OID field as a unique value.
@@ -853,8 +851,8 @@ BYTEA bytea variable-length byte array (null-safe)
853
851
object with the nextval() function before inserting and then insert it
854
852
explicitly. Using the example table in 4.16.1, that might look like
855
853
this:
856
- $newSerialID = nextval('person_id_seq');
857
- INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
854
+ $newSerialID = nextval('person_id_seq');
855
+ INSERT INTO person (id, name) VALUES ($newSerialID, 'Blaise Pascal');
858
856
859
857
You would then also have the new value stored in $newSerialID for use
860
858
in other queries (e.g., as a foreign key to the person table). Note
@@ -864,8 +862,8 @@ BYTEA bytea variable-length byte array (null-safe)
864
862
865
863
Alternatively, you could retrieve the assigned SERIAL value with the
866
864
currval() function after it was inserted by default, e.g.,
867
- INSERT INTO person (name) VALUES ('Blaise Pascal');
868
- $newID = currval('person_id_seq');
865
+ INSERT INTO person (name) VALUES ('Blaise Pascal');
866
+ $newID = currval('person_id_seq');
869
867
870
868
Finally, you could use the OID returned from the INSERT statement to
871
869
look up the default value, though this is probably the least portable
@@ -933,8 +931,8 @@ BYTEA bytea variable-length byte array (null-safe)
933
931
It is possible you have run out of virtual memory on your system, or
934
932
your kernel has a low limit for certain resources. Try this before
935
933
starting the postmaster:
936
- ulimit -d 65536
937
- limit datasize 64m
934
+ ulimit -d 65536
935
+ limit datasize 64m
938
936
939
937
Depending on your shell, only one of these may succeed, but it will
940
938
set your process data segment limit much higher and perhaps allow the
@@ -964,21 +962,21 @@ BYTEA bytea variable-length byte array (null-safe)
964
962
4.22) How do I create a column that will default to the current time?
965
963
966
964
Use now():
967
- CREATE TABLE test (x int, modtime timestamp DEFAULT now() );
965
+ CREATE TABLE test (x int, modtime timestamp DEFAULT now() );
968
966
969
967
4.23) Why are my subqueries using IN so slow?
970
968
971
969
Currently, we join subqueries to outer queries by sequentially
972
970
scanning the result of the subquery for each row of the outer query. A
973
971
workaround is to replace IN with EXISTS:
974
- SELECT *
975
- FROM tab
976
- WHERE col1 IN (SELECT col2 FROM TAB2)
972
+ SELECT *
973
+ FROM tab
974
+ WHERE col1 IN (SELECT col2 FROM TAB2)
977
975
978
976
to:
979
- SELECT *
980
- FROM tab
981
- WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
977
+ SELECT *
978
+ FROM tab
979
+ WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
982
980
983
981
We hope to fix this limitation in a future release.
984
982
@@ -988,14 +986,14 @@ BYTEA bytea variable-length byte array (null-safe)
988
986
can be simulated using UNION and NOT IN. For example, when joining
989
987
tab1 and tab2, the following query does an outer join of the two
990
988
tables:
991
- SELECT tab1.col1, tab2.col2
992
- FROM tab1, tab2
993
- WHERE tab1.col1 = tab2.col1
994
- UNION ALL
995
- SELECT tab1.col1, NULL
996
- FROM tab1
997
- WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
998
- ORDER BY tab1.col1
989
+ SELECT tab1.col1, tab2.col2
990
+ FROM tab1, tab2
991
+ WHERE tab1.col1 = tab2.col1
992
+ UNION ALL
993
+ SELECT tab1.col1, NULL
994
+ FROM tab1
995
+ WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
996
+ ORDER BY tab1.col1
999
997
_________________________________________________________________
1000
998
1001
999
Extending PostgreSQL
0 commit comments