`liam erd build` fails with “syntax error at end of input” when parsing large `structure.sql` files
Self Checks
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
Version Type
CLI Version (npm package)
Version (only for Self Hosted)
0.7.22
Steps to reproduce
- Run
liam erd build --input db/structure.sql --format postgres --output-dir erd - Ensure the SQL file is large (tens of thousands of lines) with a long INSERT INTO schema_migrations section.
- Observe the “syntax error at end of input” warning.
Expected Behavior
The parser should handle large files
Actual Behavior
When generating an ERD from a large Rails structure.sql, the CLI throws:
WARN: Error during parsing schema file: syntax error at end of input
After testing, it’s not an actual SQL syntax issue. The error happens because the structure.sql file (specifically the INSERT INTO schema_migrations VALUES (...) block at the end) is extremely long.
If I manually delete from any part ~700 lines from that block, the build completes successfully.
Additional Context
Environment: OS: macOS (can add yours) DB: PostgreSQL liam version: 0.7.22 Node.js version: v22.19.0
Temporary Workaround:
Manually remove INSERT INTO schema_migrations
@Said-MZ Thanks for creating issue!
Would you be able to provide a reproducible schema that exhibits this behavior? I'm imagining a schema with a very long INSERT INTO schema_migrations block.
That would be super helpful for debugging.
Hey @MH4GF, thanks for the quick response!
Unfortunately, I can’t share the actual structure.sql since it’s from a private company project and contains sensitive data.
From my testing, the issue seems related to input size, specifically by the very long INSERT INTO schema_migrations VALUES (...) statement at the end.
When I remove a few hundred lines from the file, the build succeeds, so it might be hitting a parser or buffer limit rather than an SQL syntax issue.
but i got it reproduced with some dummy data by generating about 3k INSERT INTO schema_migrations entries, and it triggers the same warning:
WARN: Error during parsing schema file: syntax error at end of input
For more information, see https://liambx.com/docs/parser/troubleshooting
You can reproduce it easily with this script:
#!/usr/bin/env bash
set -e
OUTPUT="structure.sql"
LINES=3000
echo "Creating dummy structure.sql with $LINES migration entries..."
cat > "$OUTPUT" <<'SQL'
-- Dummy PostgreSQL structure.sql for reproduction
CREATE EXTENSION IF NOT EXISTS "plpgsql" WITH SCHEMA pg_catalog;
CREATE TABLE public.users (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255)
);
CREATE TABLE public.posts (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES public.users(id),
title VARCHAR(255),
body TEXT
);
-- Insert migrations
INSERT INTO schema_migrations VALUES
SQL
for i in $(seq 1 $LINES); do
if [ "$i" -eq "$LINES" ]; then
echo "('migration_$i');" >> "$OUTPUT"
else
echo "('migration_$i')," >> "$OUTPUT"
fi
done
echo "✅ structure.sql generated successfully!"
echo "File: $OUTPUT (contains $LINES migration entries)"
Then run:
liam erd build --input structure.sql --format postgres --output-dir erd
It should reproduce the exact same parsing error.
if it didn't trigger the error just increase the lines to something like 5000-10000
I tested further and confirmed that the issue isn’t caused by file length alone.
I generated another large dummy structure.sql with 40k+ lines containing a mix of statements — CREATE TABLE, ALTER TABLE, COMMENT, and DO blocks — but no large single-line INSERT. That file built perfectly fine using liam erd build.
This strongly suggests the problem is specific to very long single-line INSERT statements, not overall file size.
to try the script for the working 40k+ line version:
#!/usr/bin/env bash
set -e
OUTPUT="structure.sql"
LINES=40000
echo "Generating large dummy structure.sql with $LINES lines..."
cat > "$OUTPUT" <<'SQL'
-- Large dummy PostgreSQL structure.sql for testing parser limits
CREATE EXTENSION IF NOT EXISTS "plpgsql" WITH SCHEMA pg_catalog;
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(100),
email VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
total NUMERIC(10,2),
status VARCHAR(50),
created_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_orders_user_id ON orders(user_id);
SQL
for i in $(seq 1 $LINES); do
case $((i % 5)) in
0) echo "CREATE TABLE t_${i} (id SERIAL PRIMARY KEY, value TEXT);" >> "$OUTPUT" ;;
1) echo "ALTER TABLE orders ADD COLUMN extra_field_${i} TEXT;" >> "$OUTPUT" ;;
2) echo "COMMENT ON TABLE users IS 'User table #${i}';" >> "$OUTPUT" ;;
3) echo "CREATE INDEX idx_${i}_orders_status ON orders(status);" >> "$OUTPUT" ;;
4) echo "DO \$\$ BEGIN PERFORM pg_sleep(0); END \$\$;" >> "$OUTPUT" ;;
esac
done
echo "✅ Done! Created $OUTPUT (~$LINES lines)."
Hi @Said-MZ Thank you for the very important information! The PostgreSQL parser may have an issue there because it parses after chunking due to a problem with the WASM being used. I'll look into this matter (Devin will), please wait a moment.
@MH4GF nice work, appreciate how fast you tackled this.