Changeset 24
- Timestamp:
- 09/09/08 14:50:41 (4 years ago)
- Files:
-
- 1 modified
-
trunk/epic/epic.sql (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/epic/epic.sql
r23 r24 731 731 -- 732 732 -- 'call' can be any table, view, or procedure that returns records. 733 -- 'expected' MUST be an array of the same type as colname. 733 -- 'expected' MUST be an array of the same type as colname. If necessary, cast it using :: to avoid 734 -- the error 'type of "record1._assert_column_result" does not match that when preparing the plan'. 735 -- TODO: can this function detect the type and cast it for the user? 734 736 -- 735 737 -- Example: … … 745 747 firstname text; 746 748 found_1 boolean; 749 lower_bound int; 750 base_type text; 747 751 BEGIN 748 752 -- Dump the call output into a temp table … … 761 765 'SELECT ' || colname || ' AS _assert_column_result FROM ' || call || ';'; 762 766 END IF; 767 SELECT INTO base_type pgt.typname 768 FROM pg_attribute pga LEFT JOIN pg_type pgt ON pga.atttypid = pgt.oid 769 WHERE pga.attrelid = (SELECT oid FROM pg_class WHERE relname = '_test_assert_column_base') 770 AND pga.attnum = 1; 771 -- Casting to ::name doesn't work so well. 772 IF base_type = 'name' THEN 773 base_type := 'text'; 774 END IF; 763 775 764 776 -- Dump the provided array into a temp table … … 766 778 -- doesn't get cached and re-used (or subsequent calls will fail). 767 779 EXECUTE 'CREATE TEMPORARY TABLE _test_assert_column_expected (LIKE _test_assert_column_base);'; 768 IF array_lower(expected, 1) iS NOT NULL THEN 769 FOR i IN array_lower(expected, 1)..array_upper(expected, 1) 780 lower_bound = array_lower(expected, 1); 781 IF lower_bound iS NOT NULL THEN 782 FOR i IN lower_bound..array_upper(expected, 1) 770 783 LOOP 771 784 IF expected[i] IS NULL THEN 772 785 EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (NULL);'; 773 ELSEIF typename(expected[i])IN ('text', 'varchar', 'char', 'bytea', 'date', 'timestamp', 'timestamptz', 'time', 'timetz') THEN786 ELSEIF base_type IN ('text', 'varchar', 'char', 'bytea', 'date', 'timestamp', 'timestamptz', 'time', 'timetz') THEN 774 787 EXECUTE 'INSERT INTO _test_assert_column_expected (_assert_column_result) VALUES (' 775 788 || quote_literal(expected[i]) || ');';
