summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
AgeCommit message (Collapse)Author
2010-10-13Accept 'public' as a pseudo-role name in has_table_privilege() and friendsItagaki Takahiro
to see if a particular privilege has been granted to PUBLIC. The issue was reported by Jim Nasby. Patch by Alvaro Herrera, and reviewed by KaiGai Kohei.
2010-10-10Support triggers on views.Tom Lane
This patch adds the SQL-standard concept of an INSTEAD OF trigger, which is fired instead of performing a physical insert/update/delete. The trigger function is passed the entire old and/or new rows of the view, and must figure out what to do to the underlying tables to implement the update. So this feature can be used to implement updatable views using trigger programming style rather than rule hacking. In passing, this patch corrects the names of some columns in the information_schema.triggers view. It seems the SQL committee renamed them somewhere between SQL:99 and SQL:2003. Dean Rasheed, reviewed by Bernd Helmle; some additional hacking by me.
2010-10-08Fix sloppy usage of TRIGGER_FIRED_BEFORE/TRIGGER_FIRED_AFTER.Tom Lane
Various places were testing TRIGGER_FIRED_BEFORE() where what they really meant was !TRIGGER_FIRED_AFTER(), or vice versa. This needs to be cleaned up because there are about to be more than two possible states. We might want to note this in the 9.1 release notes as something for trigger authors to double-check. For consistency's sake I also changed some places that assumed that TRIGGER_FIRED_FOR_ROW and TRIGGER_FIRED_FOR_STATEMENT are necessarily mutually exclusive; that's not in immediate danger of breaking, but it's still sloppier than it should be. Extracted from Dean Rasheed's patch for triggers on views. I'm committing this separately since it's an identifiable separate issue, and is the only reason for the patch to touch most of these particular files.
2010-09-22Re-allow input of Julian dates prior to 0001-01-01 AD.Tom Lane
This was unintentionally broken in 8.4 while tightening up checking of ordinary non-Julian date inputs to forbid references to "year zero". Per bug #5672 from Benjamin Gigot.
2010-09-20Remove cvs keywords from all files.Magnus Hagander
2010-09-11SERIALIZABLE transactions are actually implemented beneath the covers withJoe Conway
transaction snapshots, i.e. a snapshot registered at the beginning of a transaction. Change variable naming and comments to reflect this reality in preparation for a future, truly serializable mode, e.g. Serializable Snapshot Isolation (SSI). For the moment transaction snapshots are still used to implement SERIALIZABLE, but hopefully not for too much longer. Patch by Kevin Grittner and Dan Ports with review and some minor wording changes by me.
2010-09-03Install a data-type-based solution for protecting pg_get_expr().REL9_1_ALPHA1Tom Lane
Since the code underlying pg_get_expr() is not secure against malformed input, and can't practically be made so, we need to prevent miscreants from feeding arbitrary data to it. We can do this securely by declaring pg_get_expr() to take a new datatype "pg_node_tree" and declaring the system catalog columns that hold nodeToString output to be of that type. There is no way at SQL level to create a non-null value of type pg_node_tree. Since the backend-internal operations that fill those catalog columns operate below the SQL level, they are oblivious to the datatype relabeling and don't need any changes.
2010-08-24Add string functions: concat(), concat_ws(), left(), right(), and reverse().Itagaki Takahiro
Pavel Stehule, reviewed by me.
2010-08-21Use a non-locale-dependent definition of isspace() in array_in/array_out.Tom Lane
array_in discards unquoted leading and trailing whitespace in array values, while array_out is careful to quote array elements that contain whitespace. This is problematic when the definition of "whitespace" varies between locales: array_in could drop characters that were meant to be part of the value. To avoid that, lock down "whitespace" to mean only the traditional six ASCII space characters. This change also works around a bug in OS X and some older BSD systems, in which isspace() could return true for character fragments in UTF8 locales. (There may be other places in PG where that bug could cause problems, but this is the only one complained of so far; see recent report from Steven Schlansker.) Back-patch to 9.0, but not further. Given the lack of previous reports of trouble, changing this behavior in stable branches seems to offer more risk of breaking applications than reward of avoiding problems.
2010-08-21Add vacuum and analyze counters to pg_stat_*_tables views.Magnus Hagander
2010-08-14Fix \ef and \sf to not fail on functions with nonnull probin.Tom Lane
Update comment about them in pg_get_functiondef.
2010-08-13Include the backend ID in the relpath of temporary relations.Robert Haas
This allows us to reliably remove all leftover temporary relation files on cluster startup without reference to system catalogs or WAL; therefore, we no longer include temporary relations in XLOG_XACT_COMMIT and XLOG_XACT_ABORT WAL records. Since these changes require including a backend ID in each SharedInvalSmgrMsg, the size of the SharedInvalidationMessage.id field has been reduced from two bytes to one, and the maximum number of connections has been reduced from INT_MAX / 4 to 2^23-1. It would be possible to remove these restrictions by increasing the size of SharedInvalidationMessage by 4 bytes, but right now that doesn't seem like a good trade-off. Review by Jaime Casanova and Tom Lane.
2010-08-13Add xml_is_well_formed, xml_is_well_formed_document, xml_is_well_formed_contentTom Lane
functions to the core XML code. Per discussion, the former depends on XMLOPTION while the others do not. These supersede a version previously offered by contrib/xml2. Mike Fowler, reviewed by Pavel Stehule
2010-08-12Extend psql's \e and \ef commands so that a line number can be specified,Tom Lane
and the editor's cursor will be initially placed on that line. In \e the lines are counted with respect to the query buffer, while in \ef they are counted with line 1 = first line of function body. These choices are useful for positioning the cursor on the line of a previously-reported error. To avoid assumptions about what switch the user's editor takes for this purpose, invent a new psql variable EDITOR_LINENUMBER_SWITCH with (at present) no default value. One incompatibility from previous behavior is that "\e 1234" will now take "1234" as a line number not a file name. There are at least two ways to select a numerically-named file if you really want to. Pavel Stehule, reviewed by Jan Urbanski, with further editing by Robert Haas and Tom Lane
2010-08-11The sanity check added to array_recv() wa a bit too tight; we mustHeikki Linnakangas
continue to accept an empty array with dimension information. array_send() can output such arrays. Per report from Vladimir Shakhov.
2010-08-10Add three-parameter forms of array_to_string and string_to_array, to allowTom Lane
better handling of NULL elements within the arrays. The third parameter is a string that should be used to represent a NULL element, or should be translated into a NULL element, respectively. If the third parameter is NULL it behaves the same as the two-parameter form. There are two incompatible changes in the behavior of the two-parameter form of string_to_array. First, it will return an empty (zero-element) array rather than NULL when the input string is of zero length. Second, if the field separator is NULL, the function splits the string into individual characters, rather than returning NULL as before. These two changes make this form fully compatible with the behavior of the new three-parameter form. Pavel Stehule, reviewed by Brendan Jurd
2010-08-08Add an xpath_exists() function. This is equivalent to XMLEXISTS except thatTom Lane
it offers support for namespace mapping. Mike Fowler, reviewed by David Fetter
2010-08-08Add stats functions and views to provide access to a transaction's ownTom Lane
statistics counts. These numbers are being accumulated but haven't yet been transmitted to the collector (and won't be, until the transaction ends). For some purposes, though, it's handy to be able to look at them. Joel Jacobson, reviewed by Itagaki Takahiro
2010-08-05Remove the single-argument form of string_agg(). It added nothing much inTom Lane
functionality, while creating an ambiguity in usage with ORDER BY that at least two people have already gotten seriously confused by. Also, add an opr_sanity test to check that we don't in future violate the newly minted policy of not having built-in aggregates with the same name and different numbers of parameters. Per discussion of a complaint from Thom Brown.
2010-08-05Standardize get_whatever_oid functions for other object types.Robert Haas
- Rename TSParserGetPrsid to get_ts_parser_oid. - Rename TSDictionaryGetDictid to get_ts_dict_oid. - Rename TSTemplateGetTmplid to get_ts_template_oid. - Rename TSConfigGetCfgid to get_ts_config_oid. - Rename FindConversionByName to get_conversion_oid. - Rename GetConstraintName to get_constraint_oid. - Add new functions get_opclass_oid, get_opfamily_oid, get_rewrite_oid, get_rewrite_oid_without_relid, get_trigger_oid, and get_cast_oid. The name of each function matches the corresponding catalog. Thanks to KaiGai Kohei for the review.
2010-08-05Standardize get_whatever_oid functions for object types withRobert Haas
unqualified names. - Add a missing_ok parameter to get_tablespace_oid. - Avoid duplicating get_tablespace_od guts in objectNamesToOids. - Add a missing_ok parameter to get_database_oid. - Replace get_roleid and get_role_checked with get_role_oid. - Add get_namespace_oid, get_language_oid, get_am_oid. - Refactor existing code to use new interfaces. Thanks to KaiGai Kohei for the review.
2010-08-05Add xmlexists functionPeter Eisentraut
by Mike Fowler, reviewed by Peter Eisentraut
2010-08-04Fix numeric_maximum_size() calculation.Robert Haas
The old computation can sometimes underestimate the necessary space by 2 bytes; however we're not back-patching this, because this result isn't used for anything critical. Per discussion with Tom Lane, make the typmod test in this function match the ones in numeric() and apply_typmod() exactly.
2010-08-03Allow numeric to use a more compact, 2-byte header in many cases.Robert Haas
Review by Brendan Jurd and Tom Lane.
2010-08-03Replace the naive HYPOT() macro with a standards-conformant hypotenuseTom Lane
function. This avoids unnecessary overflows and probably gives a more accurate result as well. Paul Matthews, reviewed by Andrew Geery
2010-08-03Code review for --quote-all-identifiers patch: add missing --help documentationTom Lane
for new pg_dump/pg_dumpall parameters, make a couple of trivial stylistic adjustments to make the code follow usual project style.
2010-08-03Add some comments to tinterval_cmp_internal pointing out its severeTom Lane
implementation deficiencies. Per discussion of bug #5592, we're not going to change it, but these things should be documented so that if anyone ever reimplements type tinterval, they will be more careful.
2010-08-03Be a little more careful with the shift computations in QT2QTN andTom Lane
makeTSQuerySign. The first of these is a live bug, on some platforms, as per bug #5590 from John Regehr. However the consequences seem limited because of the relatively narrow scope of use of QTNode.sign. The shift in makeTSQuerySign is actually safe because TSQS_SIGLEN is unsigned, but it seems like a good idea to insert an explicit cast rather than depend on that.
2010-08-03Fix core dump in QTNodeCompare when tsquery_cmp() is applied to two emptyTom Lane
tsqueries. CompareTSQ has to have a guard for the case rather than blindly applying QTNodeCompare to random data past the end of the datums. Also, change QTNodeCompare to be a little less trusting: use an actual test rather than just Assert'ing that the input is sane. Problem encountered while investigating another issue (I saw a core dump in autoanalyze on a table containing multiple empty tsquery values). Back-patch to all branches with tsquery support. In HEAD, also fix some bizarre (though not outright wrong) coding in tsq_mcontains().
2010-08-02Fix an ancient typo that prevented the detection of conflicting fields whenTom Lane
interval input "invalid" was specified together with other fields. Spotted by Neil Conway with the help of a clang warning. Although this has been wrong since the interval code was written more than 10 years ago, it doesn't affect anything beyond which error message you get for a wrong input, so not worth back-patching very far.
2010-07-30Make details of the Numeric representation private to numeric.c.Robert Haas
Review by Tom Lane.
2010-07-28Reduce lock levels of CREATE TRIGGER and some ALTER TABLE, CREATE RULE actions.Simon Riggs
Avoid hard-coding lockmode used for many altering DDL commands, allowing easier future changes of lock levels. Implementation of initial analysis on DDL sub-commands, so that many lock levels are now at ShareUpdateExclusiveLock or ShareRowExclusiveLock, allowing certain DDL not to block reads/writes. First of number of planned changes in this area; additional docs required when full project complete.
2010-07-22Add options to force quoting of all identifiers.Robert Haas
I've added a quote_all_identifiers GUC which affects the behavior of the backend, and a --quote-all-identifiers argument to pg_dump and pg_dumpall which sets the GUC and also affects the quoting done internally by those applications. Design by Tom Lane; review by Alex Hunsaker; in response to bug #5488 filed by Hartmut Goebel.
2010-07-22Centralize DML permissions-checking logic.Robert Haas
Remove bespoke code in DoCopy and RI_Initial_Check, which now instead fabricate call ExecCheckRTPerms with a manufactured RangeTblEntry. This is intended to make it feasible for an enhanced security provider to actually make use of ExecutorCheckPerms_hook, but also has the advantage that RI_Initial_Check can allow use of the fast-path when column-level but not table-level permissions are present. KaiGai Kohei. Reviewed (in an earlier version) by Stephen Frost, and by me. Some further changes to the comments by me.
2010-07-16Add support for dividing money by money (yielding a float8 result) and forTom Lane
casting between money and numeric. Andy Balholm, reviewed by Kevin Grittner
2010-07-13Teach EXPLAIN to print PARAM_EXEC Params as the referenced expressions,Tom Lane
rather than just $N. This brings the display of nestloop-inner-indexscan plans back to where it's been, and incidentally improves the display of SubPlan parameters as well. In passing, simplify the EXPLAIN code by having it deal primarily in the PlanState tree rather than separately searching Plan and PlanState trees. This is noticeably cleaner for subplans, and about a wash elsewhere. One small difference from previous behavior is that EXPLAIN will no longer qualify local variable references in inner-indexscan plan nodes, since it no longer sees such nodes as possibly referencing multiple tables. Vars referenced through PARAM_EXEC Params are still forcibly qualified, though, so I don't think the display is any more confusing than before. Adjust a couple of examples in the documentation to match this behavior.
2010-07-09Fix ruleutils' get_variable() to print something useful for Vars referencingTom Lane
resjunk outputs of subquery tlists, instead of throwing an error. Per bug #5548 from Daniel Grace. We might at some point find we ought to back-patch this further than 9.0, but I think that such Vars can only occur as resjunk members of upper-level tlists, in which case the problem can't arise because prior versions didn't print resjunk tlist items in EXPLAIN VERBOSE.
2010-07-06pgindent run for 9.0, second runBruce Momjian
2010-06-13Fix ALTER LARGE OBJECT and GRANT ... ON LARGE OBJECT for large OIDs.Robert Haas
The previous coding failed for OIDs too large to be represented by a signed integer.
2010-05-30Change the notation for calling functions with named parameters fromTom Lane
"val AS name" to "name := val", as per recent discussion. This patch catches everything in the original named-parameters patch, but I'm not certain that no other dependencies snuck in later (grepping the source tree for all uses of AS soon proved unworkable). In passing I note that we've dropped the ball at least once on keeping ecpg's lexer (as opposed to parser) in sync with the backend. It would be a good idea to go through all of pgc.l and see if it's in sync now. I didn't attempt that at the moment.
2010-05-28Fix oversight in the previous patch that made LIKE throw error for \ at theTom Lane
end of the pattern: the code path that handles \ just after % should throw error too. As in the previous patch, not back-patching for fear of breaking apps that worked before.
2010-05-28Rewrite LIKE's %-followed-by-_ optimization so it really works (this timeTom Lane
for sure ;-)). It now also optimizes more cases, such as %_%_. Improve comments too. Per bug #5478. In passing, also rename the TCHAR macro to GETCHAR, because pgindent is messing with the formatting of the former (apparently it now thinks TCHAR is a typedef name). Back-patch to 8.3, where the bug was introduced.
2010-05-09Adjust comments about avoiding use of printf's %.*s.Tom Lane
My initial impression that glibc was measuring the precision in characters (which is what the Linux man page says it does) was incorrect. It does take the precision to be in bytes, but it also tries to truncate the string at a character boundary. The bottom line remains the same: it will mess up if the string is not in the encoding it expects, so we need to avoid %.*s anytime there's a significant risk of that. Previous code changes are still good, but adjust the comments to reflect this knowledge. Per research by Hernan Gonzalez.
2010-05-08Work around a subtle portability problem in use of printf %s format.Tom Lane
Depending on which spec you read, field widths and precisions in %s may be counted either in bytes or characters. Our code was assuming bytes, which is wrong at least for glibc's implementation, and in any case libc might have a different idea of the prevailing encoding than we do. Hence, for portable results we must avoid using anything more complex than just "%s" unless the string to be printed is known to be all-ASCII. This patch fixes the cases I could find, including the psql formatting failure reported by Hernan Gonzalez. In HEAD only, I also added comments to some places where it appears safe to continue using "%.*s".
2010-04-26Add comments about why we set LC_CTYPE in WIN32 for time when we don'tBruce Momjian
actually access it, per information from Hiroshi.
2010-04-24Add C comments for recent to_char('L') fix for Win32.Bruce Momjian
2010-04-22Fix encoding issue when lc_monetary or lc_numeric are different encodingItagaki Takahiro
from lc_ctype, that could happen on Windows. We need to change lc_ctype together with lc_monetary or lc_numeric, and convert strings in lconv from lc_ctype encoding to the database encoding. The bug reported by Mikko, original patch by Hiroshi Inoue, with changes by Bruce and me.
2010-04-07Fix to_char YYY, YY, Y format codes so that FM zero-suppression really works,Tom Lane
rather than only sort-of working as the previous attempt had left it. Clean up some unnecessary differences between the way these were coded and the way the YYYY case was coded. Update the regression test cases that proved that it wasn't working.
2010-03-03Document that "Q" is ignored by to_date and to_timestamp. Add C commentBruce Momjian
about the behavior. Document that quotes in to_date, to_timestamp, to_number skip input characters.
2010-03-03Export xml.c's libxml-error-handling support so that contrib/xml2 can use itTom Lane
too, instead of duplicating the functionality (badly). I renamed xml_init to pg_xml_init, because the former seemed just a bit too generic to be safe as a global symbol. I considered likewise renaming xml_ereport to pg_xml_ereport, but felt that the reference to ereport probably made it sufficiently PG-centric already.