agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
5+ messages / 3 participants
[nested] [flat]

* Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
@ 2018-11-21 14:09 Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
  2018-11-21 18:19 ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Voillequin, Jean-Marc @ 2018-11-21 14:09 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>

Hello,

When I run the following script on a PG 11 psql:

select version();
show lc_collate;
create or replace function same_values_func(a text, b text) returns void as $body$
begin
                assert a = b;
end;$body$ language plpgsql;
select same_values_func(least('a','b'),'a');
create or replace procedure same_values_proc(a text, b text) as $body$
begin
                assert a = b;
end;$body$ language plpgsql;
call same_values_proc(least('a','b'),'a');



I get the following output and error at the end:

SIMPLE=> select version();
                                                version
--------------------------------------------------------------------------------------------------------
PostgreSQL 11.0 on x86_64-pc-mingw64, compiled by gcc.exe (Rev5, Built by MSYS2 project) 4.9.2, 64-bit
(1 row)


SIMPLE=>
SIMPLE=> show lc_collate;
lc_collate
------------
C
(1 row)


SIMPLE=>
SIMPLE=> create or replace function same_values_func(a text, b text) returns void as $body$
SIMPLE$> begin
SIMPLE$>        assert a = b;
SIMPLE$> end;$body$ language plpgsql;
CREATE FUNCTION
SIMPLE=>
SIMPLE=> select same_values_func(least('a','b'),'a');
same_values_func
------------------

(1 row)


SIMPLE=>
SIMPLE=> create or replace procedure same_values_proc(a text, b text) as $body$
SIMPLE$> begin
SIMPLE$>        assert a = b;
SIMPLE$> end;$body$ language plpgsql;
CREATE PROCEDURE
SIMPLE=>
SIMPLE=> call same_values_proc(least('a','b'),'a');
ERROR:  could not determine which collation to use for string comparison
HINT:  Use the COLLATE clause to set the collation explicitly.
SIMPLE=>

I tried to convert all void functions we have on a PG10 DB to procedures and I get this strange error.
The same error occurs with GREATEST.
Any idea?
Regards.



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

Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

This email was sent to you by Moody’s Investors Service EMEA Limited
Registered office address:
One Canada Square
Canary Wharf
London, E14 5FA
Registered in England and Wales No: 8922701

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


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
  2018-11-21 14:09 Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
@ 2018-11-21 18:19 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-02-05 14:11   ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2018-11-21 18:19 UTC (permalink / raw)
  To: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org; pgsql-sql@lists.postgresql.org

"Voillequin, Jean-Marc" <Jean-Marc.Voillequin@moodys.com> writes:
> SIMPLE=> create or replace procedure same_values_proc(a text, b text) as $body$
> SIMPLE$> begin
> SIMPLE$>        assert a = b;
> SIMPLE$> end;$body$ language plpgsql;
> CREATE PROCEDURE
> SIMPLE=>
> SIMPLE=> call same_values_proc(least('a','b'),'a');
> ERROR:  could not determine which collation to use for string comparison
> HINT:  Use the COLLATE clause to set the collation explicitly.

Yeah, same here.  I think somebody forgot to run assign_expr_collations()
on CALL arguments.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
  2018-11-21 14:09 Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
  2018-11-21 18:19 ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-02-05 14:11   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-02-05 14:46     ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2019-02-05 14:11 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; +Cc: pgsql-bugs@lists.postgresql.org; pgsql-sql@lists.postgresql.org

On 21/11/2018 19:19, Tom Lane wrote:
> "Voillequin, Jean-Marc" <Jean-Marc.Voillequin@moodys.com> writes:
>> SIMPLE=> create or replace procedure same_values_proc(a text, b text) as $body$
>> SIMPLE$> begin
>> SIMPLE$>        assert a = b;
>> SIMPLE$> end;$body$ language plpgsql;
>> CREATE PROCEDURE
>> SIMPLE=>
>> SIMPLE=> call same_values_proc(least('a','b'),'a');
>> ERROR:  could not determine which collation to use for string comparison
>> HINT:  Use the COLLATE clause to set the collation explicitly.
> 
> Yeah, same here.  I think somebody forgot to run assign_expr_collations()
> on CALL arguments.

This appears to fix it.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 5c68d4c057f2ed41d03faf46e20e33df24990305 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 5 Feb 2019 15:08:53 +0100
Subject: [PATCH] Add collation assignment to CALL statement

Otherwise functions that require collation information will not have
it if they are called in arguments to a CALL statement.

Reported-by: Jean-Marc Voillequin <Jean-Marc.Voillequin@moodys.com>
Discussion: https://www.postgresql.org/message-id/flat/1EC8157EB499BF459A516ADCF135ADCE39FFAC54%40LON-WGMSX712.a...
---
 src/backend/parser/analyze.c                   |  2 ++
 src/test/regress/expected/create_procedure.out |  7 +++++++
 src/test/regress/sql/create_procedure.sql      | 11 +++++++++++
 3 files changed, 20 insertions(+)

diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 7f5773582b..e3544efb6f 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -2636,6 +2636,8 @@ transformCallStmt(ParseState *pstate, CallStmt *stmt)
 							 true,
 							 stmt->funccall->location);
 
+	assign_expr_collations(pstate, node);
+
 	stmt->funcexpr = castNode(FuncExpr, node);
 
 	result = makeNode(Query);
diff --git a/src/test/regress/expected/create_procedure.out b/src/test/regress/expected/create_procedure.out
index 5b9b83839c..211a42cefa 100644
--- a/src/test/regress/expected/create_procedure.out
+++ b/src/test/regress/expected/create_procedure.out
@@ -139,6 +139,13 @@ AS $$
 SELECT NULL::int;
 $$;
 CALL ptest6(1, 2);
+-- collation assignment
+CREATE PROCEDURE ptest7(a text, b text)
+LANGUAGE SQL
+AS $$
+SELECT a = b;
+$$;
+CALL ptest7(least('a', 'b'), 'a');
 -- various error cases
 CALL version();  -- error: not a procedure
 ERROR:  version() is not a procedure
diff --git a/src/test/regress/sql/create_procedure.sql b/src/test/regress/sql/create_procedure.sql
index b64293ed66..89b96d580f 100644
--- a/src/test/regress/sql/create_procedure.sql
+++ b/src/test/regress/sql/create_procedure.sql
@@ -101,6 +101,17 @@ CREATE PROCEDURE ptest6(a int, b anyelement)
 CALL ptest6(1, 2);
 
 
+-- collation assignment
+
+CREATE PROCEDURE ptest7(a text, b text)
+LANGUAGE SQL
+AS $$
+SELECT a = b;
+$$;
+
+CALL ptest7(least('a', 'b'), 'a');
+
+
 -- various error cases
 
 CALL version();  -- error: not a procedure
-- 
2.20.1



Attachments:

  [text/plain] 0001-Add-collation-assignment-to-CALL-statement.patch (2.3K, ../../66209b1a-db5b-d578-6674-1be789c581f5@2ndquadrant.com/2-0001-Add-collation-assignment-to-CALL-statement.patch)
  download | inline diff:
From 5c68d4c057f2ed41d03faf46e20e33df24990305 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 5 Feb 2019 15:08:53 +0100
Subject: [PATCH] Add collation assignment to CALL statement

Otherwise functions that require collation information will not have
it if they are called in arguments to a CALL statement.

Reported-by: Jean-Marc Voillequin <Jean-Marc.Voillequin@moodys.com>
Discussion: https://www.postgresql.org/message-id/flat/1EC8157EB499BF459A516ADCF135ADCE39FFAC54%40LON-WGMSX712.ad.moodys.net
---
 src/backend/parser/analyze.c                   |  2 ++
 src/test/regress/expected/create_procedure.out |  7 +++++++
 src/test/regress/sql/create_procedure.sql      | 11 +++++++++++
 3 files changed, 20 insertions(+)

diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 7f5773582b..e3544efb6f 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -2636,6 +2636,8 @@ transformCallStmt(ParseState *pstate, CallStmt *stmt)
 							 true,
 							 stmt->funccall->location);
 
+	assign_expr_collations(pstate, node);
+
 	stmt->funcexpr = castNode(FuncExpr, node);
 
 	result = makeNode(Query);
diff --git a/src/test/regress/expected/create_procedure.out b/src/test/regress/expected/create_procedure.out
index 5b9b83839c..211a42cefa 100644
--- a/src/test/regress/expected/create_procedure.out
+++ b/src/test/regress/expected/create_procedure.out
@@ -139,6 +139,13 @@ AS $$
 SELECT NULL::int;
 $$;
 CALL ptest6(1, 2);
+-- collation assignment
+CREATE PROCEDURE ptest7(a text, b text)
+LANGUAGE SQL
+AS $$
+SELECT a = b;
+$$;
+CALL ptest7(least('a', 'b'), 'a');
 -- various error cases
 CALL version();  -- error: not a procedure
 ERROR:  version() is not a procedure
diff --git a/src/test/regress/sql/create_procedure.sql b/src/test/regress/sql/create_procedure.sql
index b64293ed66..89b96d580f 100644
--- a/src/test/regress/sql/create_procedure.sql
+++ b/src/test/regress/sql/create_procedure.sql
@@ -101,6 +101,17 @@ CREATE PROCEDURE ptest6(a int, b anyelement)
 CALL ptest6(1, 2);
 
 
+-- collation assignment
+
+CREATE PROCEDURE ptest7(a text, b text)
+LANGUAGE SQL
+AS $$
+SELECT a = b;
+$$;
+
+CALL ptest7(least('a', 'b'), 'a');
+
+
 -- various error cases
 
 CALL version();  -- error: not a procedure
-- 
2.20.1



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
  2018-11-21 14:09 Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
  2018-11-21 18:19 ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
  2019-02-05 14:11   ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2019-02-05 14:46     ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-02-07 07:29       ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-02-05 14:46 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; pgsql-bugs@lists.postgresql.org; pgsql-sql@lists.postgresql.org

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 21/11/2018 19:19, Tom Lane wrote:
>> Yeah, same here.  I think somebody forgot to run assign_expr_collations()
>> on CALL arguments.

> This appears to fix it.

I think this should be fine as a band-aid patch.  As I mentioned
previously, I'm not really happy with our generally-unprincipled
approach to where collation assignment is called from ... but a
bug-fix patch should probably not be tasked with making that
better.  Especially not with less than a week till 11.2.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure
  2018-11-21 14:09 Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
  2018-11-21 18:19 ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
  2019-02-05 14:11   ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-02-05 14:46     ` Re: Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-02-07 07:29       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Peter Eisentraut @ 2019-02-07 07:29 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; pgsql-bugs@lists.postgresql.org; pgsql-sql@lists.postgresql.org

On 05/02/2019 15:46, Tom Lane wrote:
> Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
>> On 21/11/2018 19:19, Tom Lane wrote:
>>> Yeah, same here.  I think somebody forgot to run assign_expr_collations()
>>> on CALL arguments.
> 
>> This appears to fix it.
> 
> I think this should be fine as a band-aid patch.  As I mentioned
> previously, I'm not really happy with our generally-unprincipled
> approach to where collation assignment is called from ... but a
> bug-fix patch should probably not be tasked with making that
> better.  Especially not with less than a week till 11.2.

committed

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-02-07 07:29 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-21 14:09 Weird "could not determine which collation to use for string comparison" with LEAST/GREATEST on PG11 procedure Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
2018-11-21 18:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-02-05 14:11   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-02-05 14:46     ` Tom Lane <tgl@sss.pgh.pa.us>
2019-02-07 07:29       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox