sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.65k stars 813 forks source link

Can't run CREATE TEMPORARY TABLE queries with sqlc. #1599

Open Jille opened 2 years ago

Jille commented 2 years ago

Version

1.13.0

What happened?

All DDL statements in queries.sql are parsed as schema definition, rather than as queries that can be executed at runtime.

I want to create temporary tables at runtime, so I can then CopyFrom into them and use UPDATE .. FROM .. to efficiently write back to a non-temp table.

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

https://play.sqlc.dev/p/9a91120870ebfb6e91ab726c9495822a6403c2db27fbf036c07e976af9f794d3

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

kyleconroy commented 2 years ago

Tracking here https://github.com/kyleconroy/sqlc/issues/1661

sgielen commented 10 months ago

I believe this is resolved in sqlc v1.25.0, although the release notes don't directly mention it - only that a different PostgreSQL query parser is now used, which may be relevant. If you open the Playground link on v1.24.0 you'll see the CreateTempTable query is not generated, but on v1.25.0, it is. (You may need to make a tiny change to the query.sql to get the playground to rerun codegen.)