| 306 | |
| 307 | |
| 308 | def _emit_on(ctx: SuggestContext) -> list[Suggestion]: |
| 309 | tables = _tables(ctx) # [(schema, table, alias), ...] |
| 310 | parent = _parent_name(ctx) |
| 311 | if parent: |
| 312 | # "ON parent.<suggestion>" |
| 313 | # parent can be either a schema name or table alias |
| 314 | # todo recognize and separate schema and table suggestions |
| 315 | # todo remove function suggestions here |
| 316 | tables = [t for t in tables if identifies(parent, *t)] |
| 317 | return [ |
| 318 | {'type': 'column', 'tables': tables}, |
| 319 | {'type': 'table', 'schema': parent}, |
| 320 | {'type': 'view', 'schema': parent}, |
| 321 | {'type': 'function', 'schema': parent}, |
| 322 | ] |
| 323 | |
| 324 | # ON <suggestion> |
| 325 | # Use table alias if there is one, otherwise the table name |
| 326 | aliases = _aliases(tables) |
| 327 | suggest: list[Suggestion] = [{'type': 'fk_join', 'tables': tables}, {'type': 'alias', 'aliases': aliases}] |
| 328 | |
| 329 | # The lists of 'aliases' could be empty if we're trying to complete |
| 330 | # a GRANT query. eg: GRANT SELECT, INSERT ON <tab> |
| 331 | # In that case we just suggest all schemata and all tables. |
| 332 | if not aliases: |
| 333 | suggest.append({'type': 'database'}) |
| 334 | suggest.append({'type': 'table', 'schema': parent}) |
| 335 | return suggest |
| 336 | |
| 337 | |
| 338 | def _emit_database(_ctx: SuggestContext) -> list[Suggestion]: |