-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit implements `[FUNCTION xxxx]` OID references syntax of functions. With this change, functions can be called with the new OID numerical representation. For example `SELECT [FUNCTION 123]('helloworld')`. The intention of this syntax is only for internal serialization of references to UDFs. But it's general enough for builtin functions as well. A new implementation of the `ResolvableFunctionReference` interface, `OIDFunctionReference` is introduced for function resolution purpose for the new syntax. The `ResolveFunctionByOID` method is also refactored to return a qualified name. Fixes: cockroachdb#83231 Release note: None
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
query T | ||
SELECT [FUNCTION 1074]('hello,world', ',') | ||
---- | ||
{hello,world} | ||
|
||
statement ok | ||
CREATE TABLE t1(a INT PRIMARY KEY, b STRING DEFAULT ([FUNCTION 1074]('hello,world', ','))) | ||
|
||
statement ok | ||
INSERT INTO t1(a) VALUES (1) | ||
|
||
query IT | ||
SELECT * FROM t1 | ||
---- | ||
1 {hello,world} | ||
|
||
statement ok | ||
INSERT INTO t1 VALUES (2, 'hello,new,world') | ||
|
||
statement ok | ||
CREATE INDEX idx ON t1([FUNCTION 1074](b,',')) | ||
|
||
query IT | ||
SELECT * FROM t1@idx WHERE [FUNCTION 1074](b, ',') = ARRAY['hello','new','world'] | ||
---- | ||
2 hello,new,world | ||
|
||
statement ok | ||
ALTER TABLE t1 ADD CONSTRAINT c_len CHECK ([FUNCTION 814](b) > 2) | ||
|
||
statement error pq: failed to satisfy CHECK constraint \(length\(b\) > 2:::INT8\) | ||
INSERT INTO t1 VALUES (3, 'a') | ||
|
||
statement ok | ||
CREATE FUNCTION f1() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$ | ||
|
||
let $fn_oid | ||
SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f1' | ||
|
||
query I | ||
SELECT [FUNCTION $fn_oid]() | ||
---- | ||
1 | ||
|
||
statement ok | ||
CREATE FUNCTION f2(a STRING) RETURNS STRING LANGUAGE SQL AS $$ SELECT a $$ | ||
|
||
let $fn_oid | ||
SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f2' | ||
|
||
query T | ||
SELECT [FUNCTION $fn_oid]('hello world') | ||
---- | ||
hello world | ||
|
||
# Make sure that renaming does not break the reference. | ||
statement ok | ||
ALTER FUNCTION f2(STRING) RENAME TO f2_new; | ||
|
||
query T | ||
SELECT [FUNCTION $fn_oid]('hello world') | ||
---- | ||
hello world | ||
|
||
statement ok | ||
CREATE SCHEMA sc1; | ||
|
||
statement ok | ||
ALTER FUNCTION f2_new(STRING) SET SCHEMA sc1; | ||
|
||
query T | ||
SELECT [FUNCTION $fn_oid]('hello world') | ||
---- | ||
hello world | ||
|
||
# Make sure that function dropped cannot be resolved. | ||
statement ok | ||
DROP FUNCTION sc1.f2_new(STRING); | ||
|
||
statement error function undefined | ||
SELECT [FUNCTION $fn_oid]('maybe') | ||
|
||
subtest cross_db_reference_should_fail | ||
|
||
statement ok | ||
CREATE DATABASE db1; | ||
|
||
statement ok | ||
USE db1; | ||
|
||
statement ok | ||
CREATE FUNCTION f_db1(a STRING) RETURNS STRING LANGUAGE SQL AS $$ SELECT a $$ | ||
|
||
let $fn_oid | ||
SELECT oid FROM pg_catalog.pg_proc WHERE proname = 'f_db1' | ||
|
||
statement ok | ||
USE test; | ||
|
||
statement error pq: cross database function references are not supported | ||
SELECT [FUNCTION $fn_oid]('hello world') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.