Skip to content

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

Closed

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.

Activity

  1. carlosfarfangalindoNL222 commented on Jan 27, 2026

    @carlosfarfangalindoNL222

    I get ERROR: cannot insert multiple commands into a prepared statement (SQLSTATE 42601) when I used 'atomic' in an postgres function. I will just not use 'atomic' anymore

  2. blakyris commented on Feb 13, 2026

    @blakyris

    Still reproducible on CLI v2.76.8 (latest). Here's another reproduction case with a dollar-quoted PL/pgSQL function:

    Migration file:

    CREATE OR REPLACE FUNCTION register_subscription_atomic(
      p_user_id uuid
    ) RETURNS void
    LANGUAGE plpgsql
    AS $$
    BEGIN
      RAISE NOTICE 'hello';
    END;
    $$;
    
    SELECT 1;

    The parser treats atomic in the function name as the start of a BEGIN ATOMIC block, so it never sees the closing $$; as a statement terminator. All subsequent statements get merged into one.

    Workaround: Isolate any function/table/column containing atomic in its name into its own migration file.

  3. self-assigned this
    on Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions