Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
120674: sql: allow procedures to call other procedures r=mgartner a=mgartner

#### sql/logictest: add more tests for UDFs calling UDFs

This commit rearranges some existing tests and adds a few new tests for
UDFs that invoke other UDFs.

Release note: None

#### sql: allow procedures to call other procedures

Fixes #88198

Release note (sql change): Stored procedures can now invoke other
stored procedures via `CALL` statements.


120767: go.mod: bump Pebble to 7b8b3d5a8211 r=RaduBerinde a=jbowens

Changes:

 * [`7b8b3d5a`](cockroachdb/pebble@7b8b3d5a) *,sstable: upgrade zstd to v1.5.6
 * [`3a7021c5`](cockroachdb/pebble@3a7021c5) db: reuse backings for external ingestions

This commit bumps the zstd dependency as well, working around #105568 by disabling the assembly routines for now.

Informs #105568.
Release note: none.
Epic: none.

120776: cli: add support for remote files in debug range-data r=RaduBerinde a=itsbilal

Previously, if a Checkpoint was created due to a storage-level replica corruption, we wouldn't be able to read the checkpoint if it contained any remote (shared or external) files as the pebble instance opened with `debug range-data` would not be started with the relevant RemoteStorageFactory.

This change adds the same SharedStorage/RemoteStorageFactory params as the usual Pebble start in pkg/server/config.go, so that these checkpoints can be opened.

Fixes #119960.

Epic: None.
Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Jackson Owens <[email protected]>
Co-authored-by: Bilal Akhtar <[email protected]>
  • Loading branch information
4 people committed Mar 20, 2024
4 parents ecedafa + a5954ad + 62ac1a9 + c948c34 commit 3e9ea42
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 52 deletions.
16 changes: 10 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1693,10 +1693,10 @@ def go_deps():
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
],
sha256 = "cb1e1504fc2d8548b1dbae787425fa923dfd87310733ddc3e1d99b42b2b42482",
strip_prefix = "github.com/cockroachdb/[email protected]20240319202935-9d0109cfee7a",
sha256 = "e258498e380ea2266386054a1277c98dc58f58bbe5df29f5f91d3c163a9e5231",
strip_prefix = "github.com/cockroachdb/[email protected]20240320172852-7b8b3d5a8211",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20240319202935-9d0109cfee7a.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20240320172852-7b8b3d5a8211.zip",
],
)
go_repository(
Expand Down Expand Up @@ -2233,10 +2233,14 @@ def go_deps():
name = "com_github_datadog_zstd",
build_file_proto_mode = "disable_global",
importpath = "github.com/DataDog/zstd",
sha256 = "00989c1f3f3426aa6ed41f641193ff6a0d81031ba0b7fd81250e7e923d2f18a4",
strip_prefix = "github.com/DataDog/[email protected]",
patch_args = ["-p1"],
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_datadog_zstd.patch",
],
sha256 = "e4924158bd1abf765a016d2c728fc367b32d20b86a268ef25743ba404c55e097",
strip_prefix = "github.com/DataDog/[email protected]",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DataDog/zstd/com_github_datadog_zstd-v1.5.0.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DataDog/zstd/com_github_datadog_zstd-v1.5.6-0.20230824185856-869dae002e5e.zip",
],
)
go_repository(
Expand Down
4 changes: 2 additions & 2 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/Codefor/geohash/com_github_codefor_geohash-v0.0.0-20140723084247-1b41c28e3a9d.zip": "1f9d85fc86919143b53f8c3078fd4d2ed0271faf2eabba4460d7709f4f94c1e7",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DATA-DOG/go-sqlmock/com_github_data_dog_go_sqlmock-v1.5.0.zip": "25720bfcbd739305238408ab54263224b69ff6934923dfd9caed76d3871d0151",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DataDog/datadog-go/com_github_datadog_datadog_go-v3.2.0+incompatible.zip": "ede4a024d3c106b2f57ca04d7bfc7610e0c83f4d8a3bace2cf87b42fd5cf66cd",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DataDog/zstd/com_github_datadog_zstd-v1.5.0.zip": "00989c1f3f3426aa6ed41f641193ff6a0d81031ba0b7fd81250e7e923d2f18a4",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/DataDog/zstd/com_github_datadog_zstd-v1.5.6-0.20230824185856-869dae002e5e.zip": "e4924158bd1abf765a016d2c728fc367b32d20b86a268ef25743ba404c55e097",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/GeertJohan/go.incremental/com_github_geertjohan_go_incremental-v1.0.0.zip": "ce46b3b717f8d2927046bcfb99c6f490b1b547a681e6b23240ac2c2292a891e8",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/GeertJohan/go.rice/com_github_geertjohan_go_rice-v1.0.0.zip": "2fc48b9422bf356c18ed3fe32ec52f6a8b87ac168f83d2eed249afaebcc3eeb8",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/GoogleCloudPlatform/cloudsql-proxy/com_github_googlecloudplatform_cloudsql_proxy-v0.0.0-20190129172621-c8b1d7a94ddf.zip": "d18ff41309efc943c71d5c8faa5b1dd792700a79fa4f61508c5e50f17fc9ca6f",
Expand Down Expand Up @@ -330,7 +330,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20230118201751-21c54148d20b.zip": "ca7776f47e5fecb4c495490a679036bfc29d95bd7625290cfdb9abb0baf97476",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20240319202935-9d0109cfee7a.zip": "cb1e1504fc2d8548b1dbae787425fa923dfd87310733ddc3e1d99b42b2b42482",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20240320172852-7b8b3d5a8211.zip": "e258498e380ea2266386054a1277c98dc58f58bbe5df29f5f91d3c163a9e5231",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.5.zip": "11b30528eb0dafc8bc1a5ba39d81277c257cbe6946a7564402f588357c164560",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",
Expand Down
12 changes: 12 additions & 0 deletions build/patches/com_github_datadog_zstd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -urN a/BUILD.bazel b/BUILD.bazel
--- a/BUILD.bazel 1969-12-31 19:00:00.000000000 -0500
+++ b/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
@@ -98,7 +98,7 @@
"zstdmt_compress.h",
],
cgo = True,
- copts = ["-DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1"],
+ copts = ["-DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1 -DZSTD_DISABLE_ASM=1"],
importpath = "github.com/DataDog/zstd",
visibility = ["//visibility:public"],
)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ require (
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
github.com/cockroachdb/gostdlib v1.19.0
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b
github.com/cockroachdb/pebble v0.0.0-20240319202935-9d0109cfee7a
github.com/cockroachdb/pebble v0.0.0-20240320172852-7b8b3d5a8211
github.com/cockroachdb/redact v1.1.5
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b
Expand Down Expand Up @@ -428,7 +428,7 @@ require (
)

require (
github.com/DataDog/zstd v1.5.0 // indirect
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.5.0 h1:+K/VEwIAaPcHiMtQvpLD4lqW7f0Gk3xdYZmI1hD+CXo=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e h1:ZIWapoIRN1VqT8GR8jAwb1Ie9GyehWjVcGh32Y2MznE=
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo=
Expand Down Expand Up @@ -507,8 +507,8 @@ github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZe
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
github.com/cockroachdb/pebble v0.0.0-20240319202935-9d0109cfee7a h1:AHshyH+1NaSYtOmihiR7i8E9Z7K4vB54ETYzL7rLKvU=
github.com/cockroachdb/pebble v0.0.0-20240319202935-9d0109cfee7a/go.mod h1:g0agBmtwky6biPBw0MO+GkiYRv9krOTZgpPw2rfha8c=
github.com/cockroachdb/pebble v0.0.0-20240320172852-7b8b3d5a8211 h1:P4IriHxRJeIGtpzJSbWtw+FzM07k09Hpi8f7f/Lo3yE=
github.com/cockroachdb/pebble v0.0.0-20240320172852-7b8b3d5a8211/go.mod h1:4vn8KzcL6D2yW6hZAabweFFHVYSIL6z9BKTAEBvAmS4=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
Expand Down
7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,22 @@ state like the raft HardState. With --replicated, only includes data covered by
}

func runDebugRangeData(cmd *cobra.Command, args []string) error {
ctx := context.Background()
stopper := stop.NewStopper()
defer stopper.Stop(context.Background())
defer stopper.Stop(ctx)

db, err := OpenEngine(args[0], stopper, fs.ReadOnly, storage.MustExist)
earlyBootAccessor := cloud.NewEarlyBootExternalStorageAccessor(serverCfg.Settings, serverCfg.ExternalIODirConfig)
opts := []storage.ConfigOption{storage.MustExist, storage.RemoteStorageFactory(earlyBootAccessor)}
if serverCfg.SharedStorage != "" {
es, err := cloud.ExternalStorageFromURI(ctx, serverCfg.SharedStorage,
base.ExternalIODirConfig{}, serverCfg.Settings, nil, username.RootUserName(), nil,
nil, cloud.NilMetrics)
if err != nil {
return err
}
opts = append(opts, storage.SharedStorage(es))
}
db, err := OpenEngine(args[0], stopper, fs.ReadOnly, opts...)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ func init() {
f := debugRangeDataCmd.Flags()
cliflagcfg.BoolFlag(f, &debugCtx.replicated, cliflags.Replicated)
cliflagcfg.IntFlag(f, &debugCtx.maxResults, cliflags.Limit)
cliflagcfg.StringFlag(f, &serverCfg.SharedStorage, cliflags.SharedStorage)
}
{
f := debugGossipValuesCmd.Flags()
Expand Down
92 changes: 92 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/proc_invokes_proc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# LogicTest: !local-mixed-23.1 !local-mixed-23.2

statement ok
CREATE PROCEDURE a() LANGUAGE SQL AS $$
SELECT 1;
$$

statement ok
CREATE PROCEDURE b() LANGUAGE SQL AS $$
CALL a();
$$

# Mutual recursion is not currently allowed.
statement error pgcode 42P13 cannot add dependency from descriptor \d+ to function b \(\d+\) because there will be a dependency cycle
CREATE OR REPLACE PROCEDURE a() LANGUAGE SQL AS $$
CALL b();
$$

statement error pgcode 2BP01 cannot drop function \"a\" because other objects \(\[test.public.b\]\) still depend on it
DROP PROCEDURE a

statement ok
DROP PROCEDURE b;
DROP PROCEDURE a;

statement ok
CREATE TYPE e AS ENUM ('foo', 'bar');

statement ok
CREATE PROCEDURE a() LANGUAGE SQL AS $$
SELECT 'foo'::e;
$$

statement ok
CREATE PROCEDURE b() LANGUAGE SQL AS $$
CALL a();
$$

statement error pgcode 2BP01 cannot drop type \"e\" because other objects \(\[test.public.a\]\) still depend on it
DROP TYPE e

statement ok
DROP PROCEDURE b;
DROP PROCEDURE a;
DROP TYPE e;

statement ok
CREATE TABLE ab (
a INT PRIMARY KEY,
b INT
)

statement ok
CREATE PROCEDURE ins_ab(new_a INT, new_b INT) LANGUAGE SQL AS $$
INSERT INTO ab VALUES (new_a, new_b);
$$

statement ok
CREATE PROCEDURE ins3() LANGUAGE SQL AS $$
CALL ins_ab(1, 10);
CALL ins_ab(2, 20);
CALL ins_ab(3, 30);
$$

statement ok
CALL ins_ab(4, 40)

statement ok
CALL ins3()

statement error pgcode 23505 duplicate key value violates unique constraint \"ab_pkey\"
CALL ins3()

query II rowsort
SELECT * FROM ab
----
1 10
2 20
3 30
4 40

# TODO(#102771): Add dependency tracking that causes this to error.
# statement error pgcode 2BP01 cannot drop table ab because other objects depend on it
# DROP TABLE ab;

statement error pgcode 2BP01 cannot drop function \"ins_ab\" because other objects \(\[test.public.ins3\]\) still depend on it
DROP PROCEDURE ins_ab

statement ok
DROP PROCEDURE ins3;
DROP PROCEDURE ins_ab;
DROP TABLE ab;
26 changes: 0 additions & 26 deletions pkg/sql/logictest/testdata/logic_test/procedure
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,9 @@ CALL p(foo())
statement error pgcode 42723 function "p" already exists with same argument types
CREATE FUNCTION p() RETURNS VOID LANGUAGE SQL AS ''

# TODO(mgartner): The error should state "procedure definition" too.
statement error pgcode 0A000 unimplemented: CALL usage inside a function definition
CREATE OR REPLACE PROCEDURE p2() LANGUAGE SQL AS $$
CALL p();
$$

statement error pgcode 42809 p\(\) is a procedure
CREATE FUNCTION err(i INT) RETURNS VOID LANGUAGE SQL AS 'SELECT p()'

statement error pgcode 0A000 unimplemented: CALL usage inside a function definition
CREATE FUNCTION err(i INT) RETURNS VOID LANGUAGE SQL AS 'CALL p()'

statement error pgcode 42809 p\(\) is a procedure\nHINT: To call a procedure, use CALL.
CREATE TABLE err (i INT DEFAULT p())

Expand Down Expand Up @@ -412,20 +403,3 @@ statement error pgcode 42P13 null input attribute not allowed in procedure defin
CREATE PROCEDURE pv() AS 'SELECT 1' STRICT LANGUAGE SQL;

subtest end


subtest udf_calling_udfs

# Validate we can have UDF's both in the select and from clauses.
statement ok
CREATE FUNCTION udfCall(i int) RETURNS INT LANGUAGE SQL AS 'SELECT 100+i';
CREATE FUNCTION udfCallNest(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(i) + j';
CREATE FUNCTION udfCallNest_2(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(i) + udfCall(j) + udfCallNest(i, j)';
CREATE FUNCTION udfCallNest_3(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(j) + udfCallNest(i, j) + udfCallNest_2(i, j) + 1 FROM udfCallNest_2(i, j)';

query I
SELECT * FROM udfCallNest_3(1, 2)
----
512

subtest end
92 changes: 92 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_calling_udf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LogicTest: !local-mixed-23.1

statement ok
CREATE FUNCTION lower_hello() RETURNS STRING LANGUAGE SQL AS $$ SELECT lower('hello') $$;

Expand All @@ -15,10 +17,100 @@ SELECT upper_hello(), nested_udf_for_from(), lower_hello(), concat_hello()
----
HELLO HELLO hello HELLOHELLOhello

# Validate we can have UDF's both in the select and from clauses.
statement ok
CREATE FUNCTION udfCall(i int) RETURNS INT LANGUAGE SQL AS 'SELECT 100+i';
CREATE FUNCTION udfCallNest(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(i) + j';
CREATE FUNCTION udfCallNest_2(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(i) + udfCall(j) + udfCallNest(i, j)';
CREATE FUNCTION udfCallNest_3(i int, j int) RETURNS INT LANGUAGE SQL AS 'SELECT udfCall(j) + udfCallNest(i, j) + udfCallNest_2(i, j) + 1 FROM udfCallNest_2(i, j)';

query I
SELECT * FROM udfCallNest_3(1, 2)
----
512

# Validate recursion doesn't work today.
statement error pgcode 42883 unknown function: recursion_check\(\)
CREATE FUNCTION recursion_check() RETURNS STRING LANGUAGE SQL AS $$ SELECT recursion_check() $$;

# Validate that function renaming is blocked.
statement error pgcode 0A000 cannot rename function \"lower_hello\" because other functions \(\[test.public.upper_hello, test.public.concat_hello\]\) still depend on it
ALTER FUNCTION lower_hello rename to lower_hello_new

statement ok
CREATE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$
SELECT 1;
$$

statement ok
CREATE FUNCTION g() RETURNS INT LANGUAGE SQL AS $$
SELECT f();
$$

# Mutual recursion is not currently allowed.
statement error pgcode 42P13 cannot add dependency from descriptor \d+ to function g \(\d+\) because there will be a dependency cycle
CREATE OR REPLACE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$
SELECT g();
$$

statement ok
DROP FUNCTION g();
DROP FUNCTION f();

statement ok
CREATE TABLE ab (
a INT PRIMARY KEY,
b INT
)

statement ok
CREATE FUNCTION ins_ab(new_a INT, new_b INT) RETURNS INT LANGUAGE SQL AS $$
INSERT INTO ab VALUES (new_a, new_b) RETURNING a;
$$

statement ok
CREATE FUNCTION ins(new_a INT) RETURNS INT LANGUAGE SQL AS $$
SELECT ins_ab(new_a, new_a * 10);
SELECT b FROM ab WHERE a = new_a;
$$

query I rowsort
SELECT ins(i) FROM generate_series(1, 3) g(i)
----
10
20
30

query II
SELECT ins(5), ins(6) FROM (VALUES (1)) v(i) WHERE i < ins(4)
----
50 60

query II rowsort
SELECT * FROM ab
----
1 10
2 20
3 30
4 40
5 50
6 60

statement error pgcode 23505 duplicate key value violates unique constraint \"ab_pkey\"
SELECT ins(4)

skipif config local-legacy-schema-changer
statement error pgcode 2BP01 cannot drop table ab because other objects depend on it
DROP TABLE ab

onlyif config local-legacy-schema-changer
statement error pgcode 2BP01 pq: cannot drop relation \"ab\" because function \"ins\" depends on it\nHINT: consider dropping \"ins\" first.
DROP TABLE ab

statement error pgcode 2BP01 cannot drop function \"ins_ab\" because other objects \(\[test.public.ins\]\) still depend on it
DROP FUNCTION ins_ab

statement ok
DROP FUNCTION ins;
DROP FUNCTION ins_ab;
DROP TABLE ab;
Loading

0 comments on commit 3e9ea42

Please sign in to comment.