Comments (3)
I think this might be an oversight from when I added nested blocks support. Whenever we initialize a new recordTypeVisitor
, we initialize its candidate type to types.Unknown
:
cockroach/pkg/sql/opt/optbuilder/plpgsql.go
Lines 1921 to 1925 in f796c91
In the case of a nested block, we may have already determined the return type, and should be using that instead.
from cockroach.
Reduced repro:
CREATE FUNCTION f() RETURNS RECORD LANGUAGE plpgsql AS $$
BEGIN
IF true THEN
RETURN (1:::INT8, NULL, -1.0:::DECIMAL);
ELSIF false THEN
BEGIN
RETURN (1:::INT8, 1.0:::DECIMAL, NULL);
END;
END IF;
END;
$$;
If the nested block in the ELSIF
branch is omitted, then we get a nice error message:
CREATE FUNCTION f() RETURNS RECORD LANGUAGE plpgsql AS $$
BEGIN
IF true THEN
RETURN (1:::INT8, NULL, -1.0:::DECIMAL);
ELSIF false THEN
-- BEGIN
RETURN (1:::INT8, 1.0:::DECIMAL, NULL);
-- END;
END IF;
END;
$$;
-- ERROR: unimplemented: returning different types from a RECORD-returning function is not yet supported
-- SQLSTATE: 0A000
-- HINT: You have attempted to use a feature that is not yet implemented.
-- See: https://go.crdb.dev/issue-v/115384/v24.1
-- --
-- try casting all RETURN statements to the same type
from cockroach.
I think the fix might be here:
cockroach/pkg/sql/opt/memo/typing.go
Lines 79 to 83 in f1758ec
Should this use EquivalentOrNull
instead of Equivalent
?
One question to ask, is why does a similar non-PL/pgSQL expression not also result in an internal error?
defaultdb> SELECT CASE WHEN i > 0 THEN (1, NULL) ELSE (2, 20) END FROM (VALUES (1), (0)) v(i);
case
----------
(1,)
(2,20)
(2 rows)
from cockroach.
Related Issues (20)
- sql: generic query plans result in (possibly?) unexpected index out of range errors HOT 1
- rpc: TestRemoteOffsetUnhealthy failed
- roachtest: vm_preemption failed HOT 201
- pkg/sql/logictest/tests/5node-disk/5node-disk_test: TestLogic_hash_join_dist failed
- pkg/sql/logictest/tests/cockroach-go-testserver-23.2/cockroach-go-testserver-23_2_test: TestLogic_upgrade_skip_version failed
- roachtest: cluster_creation failed HOT 3
- roachtest: hibernate failed
- roachtest: ssh_problem failed HOT 6
- roachtest: ruby-pg failed
- pkg/ccl/logictestccl/tests/multiregion-9node-3region-3azs/multiregion-9node-3region-3azs_test: TestCCLLogic_alter_table_locality failed
- kv/kvserver: TestNewRangefeedForceLeaseRetry failed HOT 5
- roachtest: cluster_creation failed HOT 76
- roachtest: activerecord failed HOT 1
- roachtest: hibernate-spatial failed HOT 2
- ccl/serverccl: TestAdminAPIChartCatalog failed HOT 1
- pkg/ccl/spanconfigccl/spanconfigsplitterccl/spanconfigsplitterccl_test: TestDataDriven failed [disk stall flake] HOT 2
- kv/kvserver: TestPromoteNonVoterInAddVoter failed HOT 2
- roachtest: hibernate failed HOT 2
- roachtest: hibernate-spatial failed HOT 2
- roachtest: pgjdbc failed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cockroach.