Open-source APMGolang HTTP routerGolang ClickHouseBlog
BunBun
Getting started
PostgreSQL
Reference open in new window
GitHub open in new window
Getting started
PostgreSQL
Reference open in new window
GitHub open in new window
  • Guide

    • Introduction
    • Getting started
    • Drivers and dialects
    • Defining models
  • Querying

    • Writing queries
    • SQL placeholders
    • SELECT
    • WHERE
    • CTE and VALUES
    • MERGE
    • INSERT
    • UPDATE
    • DELETE
    • CREATE TABLE
    • DROP TABLE
    • TRUNCATE TABLE
      • API
      • Example
    • ORM relations
  • Essentials

    • Starter kit
    • Migrations
    • Fixtures
    • Debugging
  • Tutorials

    • Running Bun in production
    • Monitoring performance and errors
    • Transactions
    • Soft deletes
    • Hooks
    • Custom types
    • Cursor pagination
    • Writing complex queries
    • Migrating from go-pg

Golang Truncate Table PostgreSQL MySQL

  • API
  • Example

# API

To see the full list of supported methods, see TruncateTableQueryopen in new window.

db.NewTruncateTable().

	Model(&strct).

	Table("table1"). // quotes table names
	TableExpr("table1"). // arbitrary unsafe expression
	ModelTableExpr("table1"). // overrides model table name

	ContinueIdentity().
	Cascade().
	Restrict().

	Exec(ctx)

# Example

To drop a table:

_, err := db.NewTruncateTable().Model((*Book)(nil)).Exec(ctx)
if err != nil {
	panic(err)
}
Edit this page open in new window
Last Updated:

DROP TABLE ORM relations