Postgresql: Support tables from non-default schema (#95636)

* Postgresql: Support tables from non-default schema

- Add support for schema-qualified table names.
- Partially resolve an issue where the column type of a table from the
  wrong schema with the same table name was incorrectly used. Now
  limited to tables of schemas within the search_path.

* Support schema in raw query editor

---------

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
MAFLO321
2024-11-12 10:18:29 +01:00
committed by GitHub
parent 8d74296b6c
commit ab813cb601
2 changed files with 36 additions and 7 deletions

View File

@ -2,8 +2,10 @@ import {
ColumnDefinition,
getStandardSQLCompletionProvider,
LanguageCompletionProvider,
LinkedToken,
TableDefinition,
TableIdentifier,
TokenType,
} from '@grafana/experimental';
import { DB, SQLQuery } from '@grafana/sql';
@ -20,6 +22,23 @@ export const getSqlCompletionProvider: (args: CompletionProviderGetterArgs) => L
resolve: async () => {
return await getTables.current();
},
// Default parser doesn't handle schema.table syntax
parseName: (token: LinkedToken | undefined | null) => {
if (!token) {
return { table: '' };
}
let processedToken = token;
let tablePath = processedToken.value;
// Parse schema.table syntax
while (processedToken.next && processedToken.next.type !== TokenType.Whitespace) {
tablePath += processedToken.next.value;
processedToken = processedToken.next;
}
return { table: tablePath };
},
},
columns: {
resolve: async (t?: TableIdentifier) => {