Skip to content

sql: views created using a DB context can't be selected from outside that DB context #9921

@a-robinson

Description

@a-robinson

This goes back to our original conversation about semantic vs syntactic encoding on the RFC PR. We're currently relying on the parser to format a text-based representation of the query to be saved for later, but it's not clear to me that the parser has enough context to qualify the table names in a view's query with their databases if they weren't fully qualified by the user.

It may require some awkward hoop-jumping to persist the properly-qualified name given that the parser doesn't have the session state. Any suggestions on this?

Basic repro example:

root@:26257> create database test;
CREATE DATABASE
root@:26257> set database = test;
SET
root@:26257> CREATE TABLE kv (k INT PRIMARY KEY, v INT);
CREATE TABLE
root@:26257> INSERT INTO kv VALUES (1, 2), (3, 4), (5, 6), (7, 8);
INSERT 4
root@:26257> CREATE VIEW kview AS SELECT * FROM kv;
CREATE VIEW
root@:26257> SELECT * FROM test.kview;
+---+---+
| k | v |
+---+---+
| 1 | 2 |
| 3 | 4 |
| 5 | 6 |
| 7 | 8 |
+---+---+
root@:26257> set database = foo;
SET
root@:26257> select * from test.kview;
pq: table "kv" does not exist

@dt @knz

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions