-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax rules for ambiguous name resolution #8439
Comments
Packages cannot contain tables and view, what's the point to include them into the specifications? |
Obviously they cannot be inside packages, but they participate in rules in the possible cases. |
If constants are introduced at the package level, this can be expanded. That is, I propose to make the syntax more general. In this case, there is a conflict between the package name and the table/view name.
name1 - package, name2 -const or name1 - table, name2- column Name resolution:
or
|
Please specify full example where you see the ambiguity, i.e., query and its metadata (or some comments making it clear). |
I believe when deciding upon how to handle schema vs package naming, we must first answer what we are using schema for? For most developers, we either need to emulate existing data structures for porting from one sql engine to another, or we need clean name spaces for organizing our systems. Some databases have limited depth in their schema ie mssql or postgress where you have one level of schema under the database, while others have a recursive structure where you have multiple levels of schema depth. If you have schema, especially with a recursive structure, you need certain session/user parameters, very much like a directory structure on a file system. Examples include "current schema", "search path", "home schema" etc., An example of this, lets say we are trying to emulate a MSSQL configuration This would allow Firebird to emulate many of the existing structures in a MSSQL installation. For another example, Oracle, with multi level schema, and default schema paths, allows for a classroom to have a series of sub-schema for students. Each student has their own home schema for the class, where they create their own tables, but, can select from tables, not in their personal schema, but which exist in the classroom shared schema, without specifying the full path to the table ie select * from common_table would work, even though the common_table is in the shared schema, and not in the local schema. Doing a select from a table in the local (users current) schema, does not need the schema specified. In the case of name conflicts, the first matching name in the search path is the one chosen. This is why keeping the search path and using synonyms inside the search structure removes ambiguity (full path is always better, but, in case of the classroom example, that is how it was setup at a college) If a default schema (ie like MSSQL [Database].[...].[Table] syntax, the [...] would be replaced with the users default schema. So, packages, for the purpose of name collision, can not be in a schema path beside a sub-schema with the same name. So [root].[schema1].[schema2].[schema3]..... works Once this type of structure is implemented, packages become less important. Having package/name conflicts, along with a recursive schema structure would allow for emulating anyone of the existing sql engines, while giving flexibility beyond most engines in regards to organizational structures and name spaces. Just a suggestion |
Is it really better than just |
Easy as pie. CREATE PACKAGE SOME
BEGIN
CONST A INTEGER = 1;
END
CREATE TABLE SOME (
A INTEGER,
B INTEGER
);
CREATE TABLE T (
B INTEGER,
C INTEGER
);
SELECT *
FROM T JOIN SOME ON T.B = SOME.B
WHERE T.C = SOME.A; Here |
It is better to ask what advantages Firebird packages have over Firebird schemas? Currently I see no advantages so packages can be declared deprecated and disregarded. |
@@aafemt , packages can have 'private' (not published) methods. (visibility control) |
ROW TYPE (named) and CONST are going to be added at the package level. There is no need to include these objects in the schema. I would like to point out that the name resolution operator in the program code is rather an exception to the rule. That is, we should try to avoid ambiguous names, but since we cannot prohibit the creation of conflicting entities, in some cases we should somehow indicate to the parser what exactly was meant if a rule other than the default is required. |
They can, but they don't. This feature is not implemented and it is better (and simpler) to make procedures in schema which user don't have execution rights on invisible to them than private package members.
But can you name a good reason NOT to include these objects into schemas? |
Name resoultion will happen at compile time or exection time? |
@aafemt? 'private' method is not about visibility to the user (user grant perspective), but about code visibility to other code (developer perspective). We don't publish every method from packages body to the head, this feature already exists in FB30 and we use this. |
At least because in this case these objects will require additional privileges. At the package level, everything is simpler, there are rights to use the package - then there are rights to everything that is declared in its header. Packages solve three problems:
And do not forget that packages significantly simplify the work of those who came from the Oracle world. Secondly, in the case of constants, you do not solve anything in terms of name conflicts, they will also conflict with unspecified column names. |
Then just replace |
@aafemt , also schema is not about access (grant) control. |
Compile (SQL->BLR) time. |
The current syntax has choosen because:
|
We're actively discussing it in fb-devel by a year, and no, it's not based in MSSQL, we had a number of problems to resolve even without its "flexibility". |
@asfernandes , suggestion for a new firebird.conf option : NameAmbiguityError. |
Name resolution (FB 6.0)
With the introduction of schemas in Firebird 6.0, the syntax
<name>.<name>
- used for tables, views, procedures,and functions (both standalone and packaged) - introduces ambiguity when resolving object names using the schema
search path. The ambiguity arises between:
<schema>.<object>
(a schema and its object)<package>.<object>
(a package and its object)This document focuses on name resolution rules for tables, views, procedures, and functions within queries and
code blocks.
Scope specifier (
%
)To resolve these ambiguities, Firebird introduces a scope specifier, represented by the
%
symbol. Thisallows unambiguous referencing of objects.
Syntax
Examples
Detailed name resolution rules
Firebird resolves object names following a structured sequence of rules. Once an object is located, the resolution
process halts, ensuring no ambiguity errors occur.
name1.name2.name3
name3
inside packagename2
, inside schemaname1
.name1%schema.name2
name2
inside schemaname1
.name1%package.name2
name2
inside a packagename1
using the schema search path.name1.name2
name1
, look for routinename2
in the same package.name1
for objectname2
.name2
inside a packagename1
using the schema search path.name
name
.name
in the same package.name
using the schema search path.The text was updated successfully, but these errors were encountered: