Index: doc/src/FAQ/FAQ.html =================================================================== RCS file: /cvsroot/pgsql-server/doc/src/FAQ/FAQ.html,v retrieving revision 1.155 diff -c -c -r1.155 FAQ.html *** doc/src/FAQ/FAQ.html 10 Oct 2002 03:15:19 -0000 1.155 --- doc/src/FAQ/FAQ.html 11 Oct 2002 04:05:56 -0000 *************** *** 143,148 **** --- 143,149 ---- from a function?
4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL functions?
+ 4.27) What replication options are available?

Extending PostgreSQL

*************** *** 1346,1357 ****

4.24) How do I perform queries using multiple databases?

!

There is no way to query any database except the current one. Because PostgreSQL loads database-specific system catalogs, it is uncertain how a cross-database query should even behave.

!

Of course, a client can make simultaneous connections to ! different databases and merge the information that way.

4.25) How do I return multiple rows or columns from a function?

--- 1347,1360 ----

4.24) How do I perform queries using multiple databases?

!

There is no way to query a database other than the current one. Because PostgreSQL loads database-specific system catalogs, it is uncertain how a cross-database query should even behave.

!

/contrib/dblink allows cross-database queries using ! function calls. Of course, a client can make simultaneous ! connections to different databases and merge the results on the ! client side.

4.25) How do I return multiple rows or columns from a function?

*************** *** 1364,1376 ****

4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL functions?

! PL/PgSQL caches function contents, and an unfortunate side effect is that if a PL/PgSQL function accesses a temporary table, and that table is later dropped and recreated, and the function called again, the function will fail because the cached function contents still point to the old temporary table. The solution is to use EXECUTE for temporary table access in PL/PgSQL. This ! will cause the query to be reparsed every time.
--- 1367,1385 ----

4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL functions?

!

PL/PgSQL caches function contents, and an unfortunate side effect is that if a PL/PgSQL function accesses a temporary table, and that table is later dropped and recreated, and the function called again, the function will fail because the cached function contents still point to the old temporary table. The solution is to use EXECUTE for temporary table access in PL/PgSQL. This ! will cause the query to be reparsed every time.

! !

4.27) What replication options are available? !

!

There are several master/slave replication solutions available. ! These allow only one server to make database changes and the slave ! merely allow database reading.


Index: src/backend/nodes/nodes.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/nodes/nodes.c,v retrieving revision 1.15 diff -c -c -r1.15 nodes.c *** src/backend/nodes/nodes.c 20 Jun 2002 20:29:29 -0000 1.15 --- src/backend/nodes/nodes.c 11 Oct 2002 04:05:58 -0000 *************** *** 28,42 **** * macro makeNode. eg. to create a Resdom node, use makeNode(Resdom) * */ ! Node * ! newNode(Size size, NodeTag tag) ! { ! Node *newNode; - Assert(size >= sizeof(Node)); /* need the tag, at least */ - - newNode = (Node *) palloc(size); - MemSet((char *) newNode, 0, size); - newNode->type = tag; - return newNode; - } --- 28,32 ---- * macro makeNode. eg. to create a Resdom node, use makeNode(Resdom) * */ ! Node *newNodeMacroHolder; Index: src/backend/utils/mmgr/mcxt.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/utils/mmgr/mcxt.c,v retrieving revision 1.32 diff -c -c -r1.32 mcxt.c *** src/backend/utils/mmgr/mcxt.c 12 Aug 2002 00:36:12 -0000 1.32 --- src/backend/utils/mmgr/mcxt.c 11 Oct 2002 04:06:02 -0000 *************** *** 453,458 **** --- 453,481 ---- } /* + * MemoryContextAllocZero + * Like MemoryContextAlloc, but clears allocated memory + * + * We could just call MemoryContextAlloc then clear the memory, but this + * function is called too many times, so we have a separate version. + */ + void * + MemoryContextAllocZero(MemoryContext context, Size size) + { + void *ret; + + AssertArg(MemoryContextIsValid(context)); + + if (!AllocSizeIsValid(size)) + elog(ERROR, "MemoryContextAllocZero: invalid request size %lu", + (unsigned long) size); + + ret = (*context->methods->alloc) (context, size); + MemSet(ret, 0, size); + return ret; + } + + /* * pfree * Release an allocated chunk. */ Index: src/include/nodes/nodes.h =================================================================== RCS file: /cvsroot/pgsql-server/src/include/nodes/nodes.h,v retrieving revision 1.118 diff -c -c -r1.118 nodes.h *** src/include/nodes/nodes.h 31 Aug 2002 22:10:47 -0000 1.118 --- src/include/nodes/nodes.h 11 Oct 2002 04:06:05 -0000 *************** *** 261,266 **** --- 261,284 ---- #define nodeTag(nodeptr) (((Node*)(nodeptr))->type) + /* + * There is no way to dereference the palloc'ed pointer to assign the + * tag, and return the pointer itself, so we need a holder variable. + * Fortunately, this function isn't recursive so we just define + * a global variable for this purpose. + */ + extern Node *newNodeMacroHolder; + + #define newNode(size, tag) \ + ( \ + AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \ + \ + newNodeMacroHolder = (Node *) palloc0(size), \ + newNodeMacroHolder->type = (tag), \ + newNodeMacroHolder \ + ) + + #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_)) #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t)) *************** *** 281,291 **** * extern declarations follow * ---------------------------------------------------------------- */ - - /* - * nodes/nodes.c - */ - extern Node *newNode(Size size, NodeTag tag); /* * nodes/{outfuncs.c,print.c} --- 299,304 ---- Index: src/include/utils/palloc.h =================================================================== RCS file: /cvsroot/pgsql-server/src/include/utils/palloc.h,v retrieving revision 1.19 diff -c -c -r1.19 palloc.h *** src/include/utils/palloc.h 20 Jun 2002 20:29:53 -0000 1.19 --- src/include/utils/palloc.h 11 Oct 2002 04:06:06 -0000 *************** *** 46,53 **** --- 46,56 ---- * Fundamental memory-allocation operations (more are in utils/memutils.h) */ extern void *MemoryContextAlloc(MemoryContext context, Size size); + extern void *MemoryContextAllocZero(MemoryContext context, Size size); #define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz)) + + #define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz)) extern void pfree(void *pointer); Index: src/interfaces/libpq/fe-connect.c =================================================================== RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.206 diff -c -c -r1.206 fe-connect.c *** src/interfaces/libpq/fe-connect.c 3 Oct 2002 17:09:42 -0000 1.206 --- src/interfaces/libpq/fe-connect.c 11 Oct 2002 04:06:15 -0000 *************** *** 1131,1137 **** return 0; } ! remains.tv_sec = finish_time - current_time; remains.tv_usec = 0; } } --- 1131,1140 ---- return 0; } ! if (finish_time > current_time) ! remains.tv_sec = finish_time - current_time; ! else ! remains.tv_sec = 0; remains.tv_usec = 0; } }