drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Support for PostgreSQL Temporary Tables
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
It would be highly useful (at least in the app I'm building) to support the creation of PostgreSQL temporary tables directly from a Drizzle query. Here's a potential API design:
```ts
const myTemporaryTable = await db
.temp('my_temporary_table') // maybe we could use the provided name as a prefix ?
.as(
db
.select()
.from(AnotherTable)
);
const rows = await db.select().from(myTemporaryTable);
// drop it early if you want
await myTemporaryTable.drop();
```
We would also be able to define the table and use it like any other table.
```ts
import { pgTempTable } from 'drizzle-orm/pg-core';
const myTemporaryTable = pgTempTable(
'my_temporary_table',
... // schema definition
);
// run this asap
await db.execute(myTemporaryTable.create);
// or
await db.execute(myTemporaryTable.createIfNotExists);
// then later in your app
const rows = await db.select().from(myTemporaryTable);
```
Contributor guide
Assessment
This issue has not been assessed yet.