|
1 | 1 |
|
2 | 2 | Frequently Asked Questions (FAQ) for PostgreSQL
|
3 | 3 |
|
4 |
| - Last updated: Sat Apr 23 14:59:01 EDT 2005 |
| 4 | + Last updated: Sat Apr 23 16:49:43 EDT 2005 |
5 | 5 |
|
6 | 6 | Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
|
7 | 7 |
|
|
67 | 67 | 4.11.3) Doesn't currval() lead to a race condition with other users?
|
68 | 68 | 4.11.4) Why aren't my sequence numbers reused on transaction abort?
|
69 | 69 | Why are there gaps in the numbering of my sequence/SERIAL column?
|
70 |
| - 4.12) What is an OID? What is a TID? |
| 70 | + 4.12) What is an OID? What is a CTID? |
71 | 71 | 4.13) Why do I get the error "ERROR: Memory exhausted in
|
72 | 72 | AllocSetAlloc()"?
|
73 | 73 | 4.14) How do I tell what PostgreSQL version I am running?
|
74 |
| - 4.15) Why does my large-object operations get "invalid large obj |
75 |
| - descriptor"? |
76 |
| - 4.16) How do I create a column that will default to the current time? |
77 |
| - 4.17) How do I perform an outer join? |
78 |
| - 4.18) How do I perform queries using multiple databases? |
79 |
| - 4.19) How do I return multiple rows or columns from a function? |
80 |
| - 4.20) Why do I get "relation with OID ##### does not exist" errors |
| 74 | + 4.15) How do I create a column that will default to the current time? |
| 75 | + 4.16) How do I perform an outer join? |
| 76 | + 4.17) How do I perform queries using multiple databases? |
| 77 | + 4.18) How do I return multiple rows or columns from a function? |
| 78 | + 4.19) Why do I get "relation with OID ##### does not exist" errors |
81 | 79 | when accessing temporary tables in PL/PgSQL functions?
|
82 |
| - 4.21) What encryption options are available? |
83 |
| - |
84 |
| - Extending PostgreSQL |
85 |
| - |
86 |
| - 5.1) I wrote a user-defined function. When I run it in psql, why does |
87 |
| - it dump core? |
88 |
| - 5.2) How can I contribute some nifty new types and functions to |
89 |
| - PostgreSQL? |
90 |
| - 5.3) How do I write a C function to return a tuple? |
91 |
| - 5.4) I have changed a source file. Why does the recompile not see the |
92 |
| - change? |
| 80 | + 4.20) What encryption options are available? |
93 | 81 | _________________________________________________________________
|
94 | 82 |
|
95 | 83 | General Questions
|
|
529 | 517 | LIMIT 1;
|
530 | 518 |
|
531 | 519 | If you believe the optimizer is incorrect in choosing a sequential
|
532 |
| - scan, use SET enable_seqscan TO 'off' and run tests to see if an index |
533 |
| - scan is indeed faster. |
| 520 | + scan, use SET enable_seqscan TO 'off' and run query again to see if an |
| 521 | + index scan is indeed faster. |
534 | 522 |
|
535 | 523 | When using wild-card operators such as LIKE or ~, indexes can only be
|
536 | 524 | used in certain circumstances:
|
|
576 | 564 | 4.9) In a query, how do I detect if a field is NULL? How can I sort on
|
577 | 565 | whether a field is NULL or not?
|
578 | 566 |
|
579 |
| - You test the column with IS NULL and IS NOT NULL. |
| 567 | + You test the column with IS NULL and IS NOT NULL, like this: |
580 | 568 | SELECT *
|
581 | 569 | FROM tab
|
582 | 570 | WHERE col IS NULL;
|
583 | 571 |
|
584 | 572 | To sort by the NULL status, use the IS NULL and IS NOT NULL modifiers
|
585 |
| - in your WHERE clause. Things that are true will sort higher than |
| 573 | + in your ORDER BY clause. Things that are true will sort higher than |
586 | 574 | things that are false, so the following will put NULL entries at the
|
587 | 575 | top of the resulting list:
|
588 | 576 | SELECT *
|
|
603 | 591 |
|
604 | 592 | The first four types above are "varlena" types (i.e., the first four
|
605 | 593 | bytes on disk are the length, followed by the data). Thus the actual
|
606 |
| - space used is slightly greater than the declared size. However, these |
607 |
| - data types are also subject to compression or being stored out-of-line |
608 |
| - by TOAST, so the space on disk might also be less than expected. |
| 594 | + space used is slightly greater than the declared size. However, long |
| 595 | + values are also subject to compression, so the space on disk might |
| 596 | + also be less than expected. |
609 | 597 | VARCHAR(n) is best when storing variable-length strings and it limits
|
610 | 598 | how long a string can be. TEXT is for strings of unlimited length,
|
611 | 599 | with a maximum of one gigabyte.
|
|
647 | 635 | You would then also have the new value stored in new_id for use in
|
648 | 636 | other queries (e.g., as a foreign key to the person table). Note that
|
649 | 637 | the name of the automatically created SEQUENCE object will be named
|
650 |
| - <table>_<serialcolumn>_seq, where table and serialcolumn are the names |
651 |
| - of your table and your SERIAL column, respectively. |
| 638 | + <table>_< serialcolumn>_seq, where table and serialcolumn are the |
| 639 | + names of your table and your SERIAL column, respectively. |
652 | 640 |
|
653 | 641 | Alternatively, you could retrieve the assigned SERIAL value with the
|
654 | 642 | currval() function after it was inserted by default, e.g.,
|
|
667 | 655 | transactions as needed and are not locked until the transaction
|
668 | 656 | completes. This causes gaps in numbering from aborted transactions.
|
669 | 657 |
|
670 |
| - 4.12) What is an OID? What is a TID? |
| 658 | + 4.12) What is an OID? What is a CTID? |
671 | 659 |
|
672 | 660 | Every row that is created in PostgreSQL gets a unique OID unless
|
673 | 661 | created WITHOUT OIDS. OIDs are autotomatically assigned unique 4-byte
|
|
680 | 668 | single table. and are therefore less likely to overflow. SERIAL8 is
|
681 | 669 | available for storing eight-byte sequence values.
|
682 | 670 |
|
683 |
| - TIDs are used to identify specific physical rows with block and offset |
684 |
| - values. TIDs change after rows are modified or reloaded. They are used |
685 |
| - by index entries to point to physical rows. |
| 671 | + CTIDs are used to identify specific physical rows with block and |
| 672 | + offset values. CTIDs change after rows are modified or reloaded. They |
| 673 | + are used by index entries to point to physical rows. |
686 | 674 |
|
687 | 675 | 4.13) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()"?
|
688 | 676 |
|
|
703 | 691 |
|
704 | 692 | From psql, type SELECT version();
|
705 | 693 |
|
706 |
| - 4.15) Why does my large-object operations get "invalid large obj descriptor"? |
707 |
| - |
708 |
| - You need to put BEGIN WORK and COMMIT around any use of a large object |
709 |
| - handle, that is, surrounding lo_open ... lo_close. |
710 |
| - |
711 |
| - Currently PostgreSQL enforces the rule by closing large object handles |
712 |
| - at transaction commit. So the first attempt to do anything with the |
713 |
| - handle will draw invalid large obj descriptor. So code that used to |
714 |
| - work (at least most of the time) will now generate that error message |
715 |
| - if you fail to use a transaction. |
716 |
| - |
717 |
| - If you are using a client interface like ODBC you may need to set |
718 |
| - auto-commit off. |
719 |
| - |
720 |
| - 4.16) How do I create a column that will default to the current time? |
| 694 | + 4.15) How do I create a column that will default to the current time? |
721 | 695 |
|
722 | 696 | Use CURRENT_TIMESTAMP:
|
723 | 697 | CREATE TABLE test (x int, modtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
|
724 | 698 |
|
725 |
| - 4.17) How do I perform an outer join? |
| 699 | + 4.16) How do I perform an outer join? |
726 | 700 |
|
727 | 701 | PostgreSQL supports outer joins using the SQL standard syntax. Here
|
728 | 702 | are two examples:
|
|
740 | 714 | is assumed in LEFT, RIGHT, and FULL joins. Ordinary joins are called
|
741 | 715 | INNER joins.
|
742 | 716 |
|
743 |
| - 4.18) How do I perform queries using multiple databases? |
| 717 | + 4.17) How do I perform queries using multiple databases? |
744 | 718 |
|
745 | 719 | There is no way to query a database other than the current one.
|
746 | 720 | Because PostgreSQL loads database-specific system catalogs, it is
|
|
750 | 724 | course, a client can also make simultaneous connections to different
|
751 | 725 | databases and merge the results on the client side.
|
752 | 726 |
|
753 |
| - 4.19) How do I return multiple rows or columns from a function? |
| 727 | + 4.18) How do I return multiple rows or columns from a function? |
754 | 728 |
|
755 | 729 | It is easy using set-returning functions,
|
756 | 730 | http://techdocs.postgresql.org/guides/SetReturningFunctions
|
757 | 731 | .
|
758 | 732 |
|
759 |
| - 4.20) Why do I get "relation with OID ##### does not exist" errors when |
| 733 | + 4.19) Why do I get "relation with OID ##### does not exist" errors when |
760 | 734 | accessing temporary tables in PL/PgSQL functions?
|
761 | 735 |
|
762 | 736 | PL/PgSQL caches function scripts, and an unfortunate side effect is
|
|
767 | 741 | table access in PL/PgSQL. This will cause the query to be reparsed
|
768 | 742 | every time.
|
769 | 743 |
|
770 |
| - 4.21) What encryption options are available? |
| 744 | + 4.20) What encryption options are available? |
771 | 745 |
|
772 | 746 | * contrib/pgcrypto contains many encryption functions for use in SQL
|
773 | 747 | queries.
|
|
779 | 753 | or ssh, rather than PostgreSQL's native SSL connections.)
|
780 | 754 | * Database user passwords are automatically encrypted when stored in
|
781 | 755 | the system tables.
|
782 |
| - * The server can run using an encrypted file system. |
783 |
| - _________________________________________________________________ |
784 |
| - |
785 |
| - Extending PostgreSQL |
786 |
| - |
787 |
| - 5.1) I wrote a user-defined function. When I run it in psql, why does it dump |
788 |
| - core? |
789 |
| - |
790 |
| - The problem could be a number of things. Try testing your user-defined |
791 |
| - function in a stand-alone test program first. |
792 |
| - |
793 |
| - 5.2) How can I contribute some nifty new types and functions to PostgreSQL? |
794 |
| - |
795 |
| - Send your extensions to the pgsql-hackers mailing list, and they will |
796 |
| - eventually end up in the contrib/ subdirectory. |
797 |
| - |
798 |
| - 5.3) How do I write a C function to return a tuple? |
799 |
| - |
800 |
| - In versions of PostgreSQL beginning with 7.3, table-returning |
801 |
| - functions are fully supported in C, PL/PgSQL, and SQL. See the |
802 |
| - Programmer's Guide for more information. An example of a |
803 |
| - table-returning function defined in C can be found in |
804 |
| - contrib/tablefunc. |
805 |
| - |
806 |
| - 5.4) I have changed a source file. Why does the recompile not see the change? |
807 |
| - |
808 |
| - The Makefiles do not have the proper dependencies for include files. |
809 |
| - You have to do a make clean and then another make. If you are using |
810 |
| - GCC you can use the --enable-depend option of configure to have the |
811 |
| - compiler compute the dependencies automatically. |
| 756 | + * The server can also run using an encrypted file system. |
0 commit comments