Revision 10160
Added by Aaron Marcuse-Kubitza over 11 years ago
schemas/util.sql | ||
---|---|---|
1457 | 1457 |
-- Name: typeof(text, regtype); Type: FUNCTION; Schema: util; Owner: - |
1458 | 1458 |
-- |
1459 | 1459 |
|
1460 |
CREATE FUNCTION typeof(expr text, table_ regtype) RETURNS regtype |
|
1461 |
LANGUAGE plpgsql STABLE STRICT
|
|
1460 |
CREATE FUNCTION typeof(expr text, table_ regtype DEFAULT NULL::regtype) RETURNS regtype
|
|
1461 |
LANGUAGE plpgsql STABLE |
|
1462 | 1462 |
AS $_$ |
1463 | 1463 |
DECLARE |
1464 | 1464 |
type regtype; |
1465 | 1465 |
BEGIN |
1466 |
EXECUTE $$SELECT pg_typeof($$||expr||$$) FROM (SELECT (NULL::$$||table_||
|
|
1467 |
$$).*) _s$$ INTO STRICT type;
|
|
1466 |
EXECUTE $$SELECT pg_typeof($$||expr||$$)$$||
|
|
1467 |
COALESCE($$ FROM (SELECT (NULL::$$||table_||$$).*) _s$$, '') INTO STRICT type;
|
|
1468 | 1468 |
RETURN type; |
1469 | 1469 |
END; |
1470 | 1470 |
$_$; |
Also available in: Unified diff
schemas/util.sql: typeof(): support expressions that are not relative to a table (which do not have a table_ param). note that this requires removing the STRICT qualifier, so that NULL expressions will now produce an error instead of passing through as NULL.