Reference proper table names when using schema prefix

If you have your kysely tables defined a schema.table, when you want to selectFrom('schema.table') the actual name that should be used to refer to the table later in the query, should be table and not schema.table. Using the complete path results in errors depending on the actual query shape. From my understanding, when you refer to a table by its full path, adding the schema prefix, you're just referencing it, but the name that's actually saved in the query scope to refer back to it, doesn't have the schema prefix anymore. An example would be:
db.selectFrom('schema.table').select(eb => [sql`row_to_json(${eb.table('schema.table'}}`.as('column')]) // error ❌
db.selectFrom('schema.table').select(eb => [sql`row_to_json(${eb.table('table'}}`.as('column')]) // correct ✅
db.selectFrom('schema.table').select(eb => [sql`row_to_json(${eb.table('schema.table'}}`.as('column')]) // error ❌
db.selectFrom('schema.table').select(eb => [sql`row_to_json(${eb.table('table'}}`.as('column')]) // correct ✅
Is this something that could be worked on or "too fancy, too specific, too <something>" and that's it 😦 ? (at least on postgres)
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?