From c94732585647437291ec3f4a9902eeffc65a6945 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 17 Apr 2011 14:54:19 -0400 Subject: Support a COLLATE clause in plpgsql variable declarations. This allows the usual rules for assigning a collation to a local variable to be overridden. Per discussion, it seems appropriate to support this rather than forcing all local variables to have the argument-derived collation. --- doc/src/sgml/plpgsql.sgml | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index a04ab139123..1866e43e0e6 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -328,15 +328,17 @@ arow RECORD; The general syntax of a variable declaration is: -name CONSTANT type NOT NULL { DEFAULT | := } expression ; +name CONSTANT type COLLATE collation_name NOT NULL { DEFAULT | := } expression ; The DEFAULT clause, if given, specifies the initial value assigned to the variable when the block is entered. If the DEFAULT clause is not given then the variable is initialized to the SQL null value. The CONSTANT option prevents the variable from being - assigned to, so that its value will remain constant for the duration of - the block. + assigned to after initialization, so that its value will remain constant + for the duration of the block. + The COLLATE option specifies a collation to use for the + variable (see ). If NOT NULL is specified, an assignment of a null value results in a run-time error. All variables declared as NOT NULL @@ -768,9 +770,23 @@ $$ LANGUAGE plpgsql; - Explicit COLLATE clauses can be written inside a function - if it is desired to force a particular collation to be used regardless - of what the function is called with. For example, + A local variable of a collatable data type can have a different collation + associated with it by including the COLLATE option in its + declaration, for example + + +DECLARE + local_a text COLLATE "en_US"; + + + This option overrides the collation that would otherwise be + given to the variable according to the rules above. + + + + Also, of course explicit COLLATE clauses can be written inside + a function if it is desired to force a particular collation to be used in + a particular operation. For example, CREATE FUNCTION less_than_c(a text, b text) RETURNS boolean AS $$ @@ -779,6 +795,10 @@ BEGIN END; $$ LANGUAGE plpgsql; + + This overrides the collations associated with the table columns, + parameters, or local variables used in the expression, just as would + happen in a plain SQL command. -- cgit v1.2.3