Skip to content

Database migration fails on local server when table or column name contains 'atomic' #4746

@kierrr5

Description

@kierrr5

Describe the bug

When running database migrations locally using the Supabase CLI (supabase db reset --local), a migration file that contains multiple SQL statements fails to execute if any table or identifier name contains the substring 'atomic'.

This issue seems to originate in the parser (/pkg/parser/state.go), which incorrectly interprets the substring ATOMIC inside identifiers as the start of a BEGIN ATOMIC block. Once this state is entered, the parser stops treating semicolons as statement terminators until an END token is encountered, causing multiple statements in the migration file to be merged and executed as one.

To Reproduce

  1. Create a new DB migration
  2. Write SQL script to create a table with atomic in the name
  3. Execute another query (eg. select 1)
  4. Push migration to local DB or reset local database and run migrations with

Migration file:

create table public.atomic_test (id int);
select 1;

Expected behaviour

The migration to execute successfully.

Observed behaviour

The migration fails to execute. When running with the —debug flag, this is the output:

2026/01/21 11:04:18 PG Send: {"Type":"Parse","Name":"","Query":"create table public.atomic_test (id int);\nselect 1","ParameterOIDs":null}
2026/01/21 11:04:18 PG Send: {"Type":"Bind","DestinationPortal":"","PreparedStatement":"","ParameterFormatCodes":null,"Parameters":[],"ResultFormatCodes":[]}
2026/01/21 11:04:18 PG Send: {"Type":"Describe","ObjectType":"P","Name":""}
2026/01/21 11:04:18 PG Send: {"Type":"Execute","Portal":"","MaxRows":0}
2026/01/21 11:04:18 PG Send: {"Type":"Parse","Name":"","Query":"INSERT INTO supabase_migrations.schema_migrations(version, name, statements) VALUES($1, $2, $3)","ParameterOIDs":[25,25,1009]}
2026/01/21 11:04:18 PG Send: {"Type":"Bind","DestinationPortal":"","PreparedStatement":"","ParameterFormatCodes":[0,0,1],"Parameters":[{"text":"20260120173701"},{"text":"bug_report"},{"binary":"000000010000000000000019000000010000000100000032637265617465207461626c65207075626c69632e61746f6d69635f746573742028696420696e74293b0a73656c6563742031"}],"ResultFormatCodes":[]}
2026/01/21 11:04:18 PG Send: {"Type":"Describe","ObjectType":"P","Name":""}
2026/01/21 11:04:18 PG Send: {"Type":"Execute","Portal":"","MaxRows":0}
2026/01/21 11:04:18 PG Send: {"Type":"Sync"}
2026/01/21 11:04:18 PG Recv: {"Type":"ErrorResponse","Severity":"ERROR","SeverityUnlocalized":"ERROR","Code":"42601","Message":"cannot insert multiple commands into a prepared statement","Detail":"","Hint":"","Position":0,"InternalPosition":0,"InternalQuery":"","Where":"","SchemaName":"","TableName":"","ColumnName":"","DataTypeName":"","ConstraintName":"","File":"postgres.c","Line":1478,"Routine":"exec_parse_message","UnknownFields":null}
2026/01/21 11:04:18 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"}
2026/01/21 11:04:18 PG Send: {"Type":"Terminate"}
ERROR: cannot insert multiple commands into a prepared statement (SQLSTATE 42601)
At statement: 0                                                                  
create table public.atomic_test (id int);                                        
select 1

System information

  • CLI v2.72.8

Workaround
Splitting each statement with the word 'atomic' into its own migration causes the migrations to succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions