Ticket #4 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Allow `VALUES` Query in `assert_rows()`

Reported by: guest Owned by: fumanchu
Priority: major Milestone: 1.0
Component: assertions Keywords:
Cc:

Description

Here's another bug:

   BEGIN;

   SET client_min_messages=warning;

   CREATE TYPE foo AS ( id int, name text );

   CREATE OR REPLACE FUNCTION public.fooies()
    RETURNS SETOF foo LANGUAGE sql
    AS $$ SELECT 42, 'Fred'::text UNION SELECT 99, 'Bob'::text; $$;

   CREATE OR REPLACE FUNCTION test.test_fooies() RETURNS VOID AS $_$
   BEGIN
       PERFORM test.assert_rows(
           $$VALUES(42, 'Fred'), (99, 'Bob')$$,
           $$SELECT * FROM fooies()$$
       );
     RAISE EXCEPTION '[OK]';
   END;
   $_$ LANGUAGE plpgsql;

   SELECT * FROM test.test_fooies();

   ROLLBACK;

The output:

psql:try_epic.sql:21: ERROR:  syntax error at or near "("
LINE 1: SELECT * FROM VALUES(42, 'Fred'), (99, 'Bob') EXCEPT SELECT ...
                           ^
QUERY:  SELECT * FROM VALUES(42, 'Fred'), (99, 'Bob') EXCEPT SELECT * FROM fooies()
CONTEXT:  PL/pgSQL function "assert_rows" line 20 at FOR over EXECUTE statement
SQL statement "SELECT  test.assert_rows( $$VALUES(42, 'Fred'), (99, 'Bob')$$, $$SELECT * FROM fooies()$$ )"

The fix is to allow /VALUES([[:space:]]|\()/ at the beginning of the query:

Index: epic.sql
===================================================================
--- epic.sql	(revision 28)
+++ epic.sql	(working copy)
@@ -216,7 +216,7 @@
  result    text;
BEGIN
  result := rtrim(call, ';');
-  IF NOT result ~* '^[[:space:]]*(SELECT|EXECUTE)[[:space:]]' THEN
+  IF NOT result ~* E'^[[:space:]]*((SELECT|EXECUTE)[[:space:]]|VALUES([[:space:]]|\\())' THEN
    result := 'SELECT * FROM ' || result;
  END IF;
  RETURN result;

Change History

Changed 3 years ago by fumanchu

  • status changed from new to accepted
  • milestone set to 1.0

Changed 3 years ago by fumanchu

  • status changed from accepted to closed
  • resolution set to fixed

Fixed in [30].

Note: See TracTickets for help on using tickets.