Commit Graph

14688 Commits

Author SHA1 Message Date
Bruce Momjian f86c63ab6a Reverse pg_malloc patch because psql/print.c is used in scripts files
that don't have pg_malloc.
2005-07-10 15:53:42 +00:00
Bruce Momjian 8c9393c640 Use failure-safe pg_malloc consistently in psql/print.c. 2005-07-10 15:48:14 +00:00
Bruce Momjian b135508c98 Following up a previous thought I had, yesterday I realised how to
return arays nicely without having to make the plperl programmer aware
of anything. The attached patch allows plperl to return an arrayref
where the function returns an array type. It silently calls a perl
function to stringify the array before passing it to the pg array
parser. Non-array returns are handled as before (i.e. passed through
this process) so it is backwards compatible. I will presently submit
regression tests and docs.

example:

andrew=# create or replace function blah() returns text[][] language
plperl as $$ return [['a"b','c,d'],['e\\f','g']]; $$;
CREATE FUNCTION
andrew=# select blah();
            blah
-----------------------------
 {{"a\"b","c,d"},{"e\\f",g}}


This would complete half of the TODO item:

  . Pass arrays natively instead of as text between plperl and postgres

(The other half is translating pg array arguments to perl arrays - that
will have to wait for 8.1).

Some of this patch is adapted from a previously submitted patch from
Sergej Sergeev. Both he and Abhijit Menon-Sen have looked it over
briefly and tentatively said it looks ok.

Andrew Dunstan
2005-07-10 15:32:47 +00:00
Bruce Momjian 6d92f2106f The attached patch implements spi_query() and spi_fetchrow() functions
for PL/Perl, to avoid loading the entire result set into memory as the
existing spi_exec_query() function does.

Here's how one might use the new functions:

    $x = spi_query("select ...");
    while (defined ($y = spi_fetchrow($x))) {
        ...
        return_next(...);
    }

The changes do not affect the spi_exec_query() interface in any way.

Abhijit Menon-Sen
2005-07-10 15:19:43 +00:00
Bruce Momjian d1cffe2f77 Add --encoding to pg_dump.
The Problem:  Occassionally a DBA needs to dump a database to a new
encoding.   In instances where the current encoding, (or lack of an
encoding, like SQL_ASCII) is poorly supported on the target  database
server, it can be useful to dump into a particular  encoding.  But,
currently the only way to set the encoding of  a pg_dump file is to
change  client_encoding in postgresql.conf and restart postmaster.
This is more  than a little awkward for production systems.

Magnus Hagander
2005-07-10 15:08:52 +00:00
Bruce Momjian 0793108036 This patch implements putting language handlers for the optional PLs
into pg_catalog rather than public, and supports dumping languages whose
handlers are found there. This will make it easier to drop the public
schema if desired.

Unlike the previous patch, the comments have been updated and I have
reformatted some code to meet Alvarro's request to stick to 80 cols. (I
actually aghree with this - it makes printing the code much nicer).

I think I did the right thing w.r.t versions earlier than 7.3, but I
have no real way of checking, so that should be checked by someone with
more/older knowledge than me ;-)

Andrew Dunstan
2005-07-10 14:26:30 +00:00
Bruce Momjian 37f11c3081 This patch addresses the problem mentioned in the "process crash
when a plpython function returns unicode" thread:

http://archives.postgresql.org/pgsql-bugs/2005-06/msg00105.php

In several places PL/Python was calling PyObject_Str() and then
PyString_AsString() without checking if the former had returned
NULL to indicate an error.  PyString_AsString() doesn't expect a
NULL argument, so passing one causes a segmentation fault.  This
patch adds checks for NULL and raises errors via PLy_elog(), which
prints details of the underlying Python exception.  The patch also
adds regression tests for these checks.  All tests pass on my
Solaris 9 box running HEAD and Python 2.4.1.

In one place the patch doesn't call PLy_elog() because that could
cause infinite recursion; see the comment I added.  I'm not sure
how to test that particular case or whether it's even possible to
get an error there: the value that the code should check is the
Python exception type, so I wonder if a NULL value "shouldn't
happen."  This patch converts NULL to "Unknown Exception" but I
wonder if an Assert() would be appropriate.

The patch is against HEAD but the same changes should be applied
to earlier versions because they have the same problem.  The patch
might not apply cleanly against earlier versions -- will the committer
take care of little differences or should I submit different versions
of the patch?

Michael Fuhr
2005-07-10 04:56:55 +00:00
Bruce Momjian 75a64eeb4b I made the patch that implements regexp_replace again.
The specification of this function is as follows.

regexp_replace(source text, pattern text, replacement text, [flags
text])
returns text

Replace string that matches to regular expression in source text to
replacement text.

 - pattern is regular expression pattern.
 - replacement is replace string that can use '\1'-'\9', and '\&'.
    '\1'-'\9': back reference to the n'th subexpression.
    '\&'     : entire matched string.
 - flags can use the following values:
    g: global (replace all)
    i: ignore case
    When the flags is not specified, case sensitive, replace the first
    instance only.

Atsushi Ogawa
2005-07-10 04:54:33 +00:00
Bruce Momjian 73a7c322c3 Add psql \pset numericsep to allow output numbers like 100,000.0 or
100.000,0.

Eugen Nedelcu
2005-07-10 03:46:13 +00:00
Tom Lane 40d091b818 Fix config file lexer to not barf if postgresql.conf ends with a comment
that has no terminating newline.  Per report from maps.on at gmx.net.
2005-07-08 18:41:40 +00:00
Tom Lane 0ed5f90d73 Try connecting to both postgres and template1 databases to do the initial
inspection of shared catalogs.  This allows pg_dumpall to continue to
work with pre-8.1 servers that likely won't have a database named postgres.
Also, suppress output of SYSID options for users and groups, since server
no longer does anything with these except emit a rude message.
There is much more to be done to update pg_dumpall for the roles feature,
but this at least makes it usable again.  Per gripe from Chris K-L.
2005-07-08 16:51:30 +00:00
Tom Lane 70f7da3e6e Make libpq_gettext save and restore errno in a Windows-compatible way.
Also, back-patch fix into back branches.
2005-07-08 15:24:41 +00:00
PostgreSQL Daemon 85f97937d2 testing activitymail 2005-07-08 15:13:09 +00:00
Neil Conway 40ffa1a14c Remove some dead code for handling XLOG_DBASE_CREATE_OLD and
XLOG_DBASE_DROP_OLD WAL records -- these records are no longer created in
current sources. Adjust numbering of XLOG_DBASE_CREATE and XLOG_DBASE_DROP
and bump the catversion. Patch from Gavin Sherry, adjusted by Neil Conway.
2005-07-08 04:12:27 +00:00
Tom Lane d7207cfc6b Even though I'd like to see full_page_writes go away before 8.1,
a minimum requirement is that it not completely break the system
meanwhile.  Put the test in the right place.
2005-07-08 04:07:26 +00:00
Tom Lane 59d1b3d99e Track dependencies on shared objects (which is to say, roles; we already
have adequate mechanisms for tracking the contents of databases and
tablespaces).  This solves the longstanding problem that you can drop a
user who still owns objects and/or has access permissions.
Alvaro Herrera, with some kibitzing from Tom Lane.
2005-07-07 20:40:02 +00:00
Bruce Momjian 1c883366ef Fix plperl expected output.
Andrew Dunstan
2005-07-07 04:41:01 +00:00
Bruce Momjian 294de2dc01 pg_column_size() cleanup for messages and code cleanup.
Mark Kirkwood
2005-07-07 04:36:08 +00:00
Bruce Momjian eefdbba062 Currently, nonfatal warnings are not trapped (as they should be) by
plperl - the attached small patch remedies that omission, and adds a
small regression test for error and warning output - the new regression
input and expected output are in separate attached files.

Andrew Dunstan
2005-07-06 22:44:49 +00:00
Bruce Momjian 77838f7380 Currently, nonfatal warnings are not trapped (as they should be) by
plperl - the attached small patch remedies that omission.

Andrew Dunstan
2005-07-06 22:33:39 +00:00
Bruce Momjian 970bb03c3c Complete zic patch backout by removing NO_PGPORT workaround. 2005-07-06 21:40:09 +00:00
Bruce Momjian 261ffd03f7 Reverse out because the lack of using pgport in timezone/ is causing
problems:

---------------------------------------------------------------------------

Support cross compilation by compiling "zic" with a native compiler.
This relies on the output of zic being platform independent, but that is
currently the case.
2005-07-06 21:04:14 +00:00
Bruce Momjian a923602855 Add pg_column_size() to return storage size of a column, including
possible compression.

Mark Kirkwood
2005-07-06 19:02:54 +00:00
Tom Lane b9cb132648 Sync dlopen error handling for the *BSDs ... seems to me I've done this
before, but they were out of sync again.  Per Kris Jurka.
2005-07-06 16:55:58 +00:00
Tom Lane 6e2ff6e89a Add a check for trigger function with declared arguments. This path
could not be reached before, but now that there is a plpgsql validator
function, it can be.  Check is needed to prevent core dump reported by
Satoshi Nagayasu.  Besides, this gives a more specific and useful
error message for a fairly common novice error.
2005-07-06 16:42:10 +00:00
Tom Lane 99382f4581 Save and restore errno across bindtextdomain call, per discussion. 2005-07-06 16:25:59 +00:00
Bruce Momjian c3a69c3b3b Attached is a patch that enhances the "\h" capability in psql. I often
find myself typing a command and then wanting to get the syntax for it.
So I do a ctrl-a and add a \h: but psql does not recognize the command,
because I have stuff attached to it (e.g. "alter table foobar"), so I
have to scroll over and delete everything except the name of the command
itself. This patch gives \h three chances to match: if nothing matches
the complete string (current behavior), it tries to match the first two
words (e.g. "ALTER TABLE"). If that fails, it tries to match the first
word (e.g. "DELETE").

Greg Sabino Mullane
2005-07-06 03:14:48 +00:00
Bruce Momjian 326a7a0788 Add GUC full_page_writes to control writing full pages to WAL. 2005-07-05 23:18:10 +00:00
Tom Lane c19aa704c8 Fix contrib/pgcrypto to autoconfigure for OpenSSL when --with-openssl
is used in the toplevel configure.  Per Marko Kreen.
2005-07-05 23:13:57 +00:00
Bruce Momjian 2d6c375c5f Back out patch. This should be done like other server-side languages.
---------------------------------------------------------------------------

This patch allows the PL/Python module to do (SRF) functions.

The patch was taken from the CVS version.

I have modified the plpython.c file and have added a test sql script for
testing the functionality. It was actually the script that was in the
8.0.3 version but have since been removed.

In order to signal the end of a set, the called python function must
simply return plpy.EndOfSet and the set would be returned.

Gerrit van Dyk
2005-07-05 18:15:51 +00:00
Bruce Momjian 7e33fae3c1 Add NO_PGPORT defines to fix win32/cygwin builds for new target platform
build of zic.
2005-07-05 17:24:30 +00:00
Bruce Momjian 4f979e8bac Restructure zic #define fprintf checks to use a NO_PGPORT macro instead. 2005-07-04 19:54:51 +00:00
Bruce Momjian 8a79451152 I have to admit that I got the case of the preprocessor symbol on amd64
wrong. __AMD64__ is not defined, __amd64__ is.

Christof Petig
2005-07-04 19:05:45 +00:00
Bruce Momjian af8756713f This patch allows the PL/Python module to do (SRF) functions.
The patch was taken from the CVS version.

I have modified the plpython.c file and have added a test sql script for
testing the functionality. It was actually the script that was in the
8.0.3 version but have since been removed.

In order to signal the end of a set, the called python function must
simply return plpy.EndOfSet and the set would be returned.

Gerrit van Dyk
2005-07-04 19:03:30 +00:00
Bruce Momjian 109f079be6 I made the patch that improved the performance of replace_text().
The content of the patch is as follows:

(1)Create shortcut when subtext was not found.

(2)Stop using LEFT and RIGHT macro.
In LEFT and RIGHT macro, TEXTPOS is executed by the same content as
execution immediately before. The execution frequency of TEXTPOS can be
reduced by using text_substring instead of LEFT and RIGHT macro.

(3)Add appendStringInfoText, and use it instead of
appendStringInfoString.
There is an overhead of PG_TEXT_GET_STR when appendStringInfoString is
executed by text type. This can be reduced by appendStringInfoText.

(4)Reduce execution of TEXTDUP.

The effect of the patch that I measured is as follows:

- The Data for test was created by 'pgbench -i'.

- Test SQL:
 select replace(aid, '9', 'A') from accounts;

- Test results: Linux(CPU: Pentium III, Compiler option: -O2)
 original: 1.515s
 patched:  1.250s

Atsushi Ogawa
2005-07-04 18:56:44 +00:00
Bruce Momjian 4b97d51c0a Fix compile if zic because it now doesn't use libpgport. 2005-07-04 18:21:40 +00:00
Bruce Momjian b9fe8ee225 Fix date_trunct for December dates that are in the next year, e.g.:
SELECT date_trunc('week', '2002-12-31'::date);

Backpatch to 8.0.X.

Per report from Nick Johnson.
2005-07-04 14:38:31 +00:00
Tom Lane eb5949d190 Arrange for the postmaster (and standalone backends, initdb, etc) to
chdir into PGDATA and subsequently use relative paths instead of absolute
paths to access all files under PGDATA.  This seems to give a small
performance improvement, and it should make the system more robust
against naive DBAs doing things like moving a database directory that
has a live postmaster in it.  Per recent discussion.
2005-07-04 04:51:52 +00:00
Bruce Momjian 7504f0bae8 Reverse this patch:
---------------------------------------------------------------------------

> A quick look shows that when you use --with-libraries=/foo/bar the
> generated link line for libraries says
>
>  -L/foo/bar -lpq
>
> and it should probably be the other way around (as it is for the
> executables).
>
> So I suspect we need some makefile tuning.

You were correct. This patch fixes it.

Jim C. Nasby
2005-07-04 04:17:00 +00:00
Neil Conway 3f39cbdce1 Fix build break for out of tree (vpath) builds, induced by recent zic
changes.
2005-07-04 02:55:59 +00:00
Tom Lane bee9aef43b Fix memory leak in plperl_hash_from_tuple(), per report from Jean-Max Reymond. 2005-07-03 21:56:16 +00:00
Tom Lane ae9a07bf9e Don't try to constant-fold functions returning RECORD. We were never
able to do this before, but I had tried to make an exception for functions
with OUT parameters.  Michael Fuhr found one problem with it already, and
I found another, which was it didn't work for strict functions with a
NULL input.  While both of these could be worked around, the probability
that there are more gotchas seems high; I think prudence dictates just
reverting to the former behavior for now.  Accordingly, remove the kluge
added to get_expr_result_type() for Michael's case.
2005-07-03 21:14:18 +00:00
Peter Eisentraut 85884cb1de Support cross compilation by compiling "zic" with a native compiler. This
relies on the output of zic being platform independent, but that is
currently the case.
2005-07-03 18:54:28 +00:00
Tom Lane cc9bcbc8a4 Improve outer-join-deduction logic to be able to propagate equalities
through multiple join clauses.
2005-07-03 18:26:32 +00:00
Bruce Momjian 16661d60ab > A quick look shows that when you use --with-libraries=/foo/bar the
> generated link line for libraries says
>
>  -L/foo/bar -lpq
>
> and it should probably be the other way around (as it is for the
> executables).
>
> So I suspect we need some makefile tuning.

You were correct. This patch fixes it.

Jim C. Nasby
2005-07-02 23:28:22 +00:00
Tom Lane cc5e80b8d1 Teach planner about some cases where a restriction clause can be
propagated inside an outer join.  In particular, given
LEFT JOIN ON (A = B) WHERE A = constant, we cannot conclude that
B = constant at the top level (B might be null instead), but we
can nonetheless put a restriction B = constant into the quals for
B's relation, since no inner-side rows not meeting that condition
can contribute to the final result.  Similarly, given
FULL JOIN USING (J) WHERE J = constant, we can't directly conclude
that either input J variable = constant, but it's OK to push such
quals into each input rel.  Per recent gripe from Kim Bisgaard.
Along the way, remove 'valid_everywhere' flag from RestrictInfo,
as on closer analysis it was not being used for anything, and was
defined backwards anyway.
2005-07-02 23:00:42 +00:00
Bruce Momjian 87e01d1eed Improve wrapping of long lines in postgresql.conf. 2005-07-02 18:46:45 +00:00
Bruce Momjian 6aa0fdc4aa Use on/off consistently for GUC variables in postgresql.conf and the
documentation, to match SHOW.
2005-07-02 18:29:04 +00:00
Bruce Momjian 74b49a8129 Add E'' to internally created SQL strings that contain backslashes.
Improve code clarity by using macros for E'' processing.
2005-07-02 17:01:59 +00:00
Neil Conway c425dcb4ec In PL/PgSQL, allow a block's label to be optionally specified at the
end of the block:

<<label>>
begin
    ...
end label;

Similarly for loops. This is per PL/SQL. Update the documentation and
add regression tests. Patch from Pavel Stehule, code review by Neil
Conway.
2005-07-02 08:59:48 +00:00