It's a bit silly to have test functions that aren't tested, so test
them.
In passing, rename int44in/int44out to city_budget_in/_out so that they
match how the regression tests use them. Also, fix city_budget_out
so that it emits the format city_budget_in expects to read; otherwise
we'd have dump/reload failures when testing pg_dump against the
regression database. (We avoided that in the past only because no
data of type city_budget was actually stored anywhere.)
Discussion: https://postgr.es/m/29322.
1519701006@sss.pgh.pa.us
INSERT INTO equipment_r (name, hobby) VALUES ('peet''s coffee', 'posthacking');
INSERT INTO equipment_r (name, hobby) VALUES ('hightops', 'basketball');
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
+INSERT INTO city VALUES
+('Podunk', '(1,2),(3,4)', '100,127,1000'),
+('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
+TABLE city;
+ name | location | budget
+--------+----------------------+-----------------------
+ Podunk | (3,4),(1,2) | 100,127,1000,0
+ Gotham | (1100,334),(1000,34) | 123456,127,-1000,6789
+(2 rows)
+
SELECT *
INTO TABLE ramp
FROM road
leftarg = int8, -- right unary
procedure = numeric_fac
);
+-- Test operator created above
+SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
+ point '(1,2)' <% widget '(0,0,1)' AS f;
+ t | f
+---+---
+ t | f
+(1 row)
+
-- Test comments
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
ERROR: operator does not exist: integer ######
);
CREATE TYPE city_budget (
internallength = 16,
- input = int44in,
- output = int44out,
+ input = city_budget_in,
+ output = city_budget_out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = true -- ditto
widget(42,13)
(1 row)
+-- might as well exercise the widget type while we're here
+INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
+TABLE mytab;
+ foo
+--------------
+ (1,2,3)
+ (-44,5.5,12)
+(2 rows)
+
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
-CREATE FUNCTION int44in(cstring)
+CREATE FUNCTION city_budget_in(cstring)
RETURNS city_budget
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
-CREATE FUNCTION int44out(city_budget)
+CREATE FUNCTION city_budget_out(city_budget)
RETURNS cstring
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
NOTICE: argument type widget is only a shell
-CREATE FUNCTION int44in(cstring)
+CREATE FUNCTION city_budget_in(cstring)
RETURNS city_budget
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
NOTICE: type "city_budget" is not yet defined
DETAIL: Creating a shell type definition.
-CREATE FUNCTION int44out(city_budget)
+CREATE FUNCTION city_budget_out(city_budget)
RETURNS cstring
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT IMMUTABLE;
/*
- * Type int44 has no real-world use, but the regression tests use it.
+ * Type city_budget has no real-world use, but the regression tests use it.
* It's a four-element vector of int4's.
*/
/*
- * int44in - converts "num num ..." to internal form
+ * city_budget_in - converts "num, num, ..." to internal form
*
* Note: Fills any missing positions with zeroes.
*/
-PG_FUNCTION_INFO_V1(int44in);
+PG_FUNCTION_INFO_V1(city_budget_in);
Datum
-int44in(PG_FUNCTION_ARGS)
+city_budget_in(PG_FUNCTION_ARGS)
{
char *input_string = PG_GETARG_CSTRING(0);
int32 *result = (int32 *) palloc(4 * sizeof(int32));
}
/*
- * int44out - converts internal form to "num num ..."
+ * city_budget_out - converts internal form to "num, num, ..."
*/
-PG_FUNCTION_INFO_V1(int44out);
+PG_FUNCTION_INFO_V1(city_budget_out);
Datum
-int44out(PG_FUNCTION_ARGS)
+city_budget_out(PG_FUNCTION_ARGS)
{
int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
- char *result = (char *) palloc(16 * 4); /* Allow 14 digits + sign */
- int i;
- char *walk;
+ char *result = (char *) palloc(16 * 4);
+
+ snprintf(result, 16 * 4, "%d,%d,%d,%d",
+ an_array[0],
+ an_array[1],
+ an_array[2],
+ an_array[3]);
- walk = result;
- for (i = 0; i < 4; i++)
- {
- pg_ltoa(an_array[i], walk);
- while (*++walk != '\0')
- ;
- *walk++ = ' ';
- }
- *--walk = '\0';
PG_RETURN_CSTRING(result);
}
Datum
test_fdw_handler(PG_FUNCTION_ARGS)
{
+ elog(ERROR, "test_fdw_handler is not implemented");
PG_RETURN_NULL();
}
INSERT INTO equipment_r (name, hobby) VALUES ('guts', 'skywalking');
+INSERT INTO city VALUES
+('Podunk', '(1,2),(3,4)', '100,127,1000'),
+('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789');
+TABLE city;
+
SELECT *
INTO TABLE ramp
FROM road
procedure = numeric_fac
);
+-- Test operator created above
+SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
+ point '(1,2)' <% widget '(0,0,1)' AS f;
+
-- Test comments
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
CREATE TYPE city_budget (
internallength = 16,
- input = int44in,
- output = int44out,
+ input = city_budget_in,
+ output = city_budget_out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = true -- ditto
SELECT format_type(atttypid,atttypmod) FROM pg_attribute
WHERE attrelid = 'mytab'::regclass AND attnum > 0;
+
+-- might as well exercise the widget type while we're here
+INSERT INTO mytab VALUES ('(1,2,3)'), ('(-44,5.5,12)');
+TABLE mytab;