sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Not able to create multiple tables in one schema.sql file

Open aaliomer opened this issue 3 years ago • 4 comments

Version

1.17.2

What happened?

I'm trying to create multiple tables without having to create multiple tables. i get a syntax error schema.sql:1:1: syntax error at or near "CREATE"

are there any solutions or best practices?

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

aaliomer avatar Mar 10 '23 20:03 aaliomer

@aaliomer could you include your schema.sql file?

Possibly, the issue is that you have no semicolon between your CREATE TABLE statements. In this case, the first CREATE TABLE statement is not finished, and the second "CREATE TABLE" is part of the first statement, but unexpected, hence the error.

sgielen avatar Mar 16 '23 12:03 sgielen

Facing the same issue! We do have semicolons. It works fine without locations table but getting error with it. 000001_create_tables.up.sql

CREATE TABLE IF NOT EXISTS trips (
   trip_id VARCHAR(50) NOT NULL
);


CREATE TABLE IF NOT EXISTS locations (
   car_id INTEGER NOT NULL
);

Error

000001_create_tables.up.sql:1:1: syntax error at or near "("

markhaur avatar May 16 '23 04:05 markhaur

@sgielen I'm sorry I had an issue with one of my column's data type. I had specified col INTEGER(20) NOT NULL. The problem disappears after changing it to col INTEGER NOT NULL :)

markhaur avatar May 16 '23 04:05 markhaur

the moral of the story is that the parser needs better error messages

aaliomer avatar May 16 '23 05:05 aaliomer