Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dolt table import does not understand a schema file with a primary key defined separately from the column #8683

Closed
timsehn opened this issue Dec 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working customer issue import

Comments

@timsehn
Copy link
Contributor

timsehn commented Dec 16, 2024

shema file:

CREATE TABLE mining (
`stacks_block_id` int NOT NULL,
`miner_won` VARCHAR(255),
`miner_won_bid` int,
`miner1` VARCHAR(255),
`miner1_bid` int,
`miner2` VARCHAR(255),
`miner2_bid` int,
`miner3` VARCHAR(255),
`miner3_bid` int,
`miner4` VARCHAR(255),
`miner4_bid` int,
`miner5` VARCHAR(255),
`miner5_bid` int,
`miner6` VARCHAR(255),
`miner6_bid` int,
`miner7` VARCHAR(255),
`miner7_bid` int,
PRIMARY KEY ('stacks_block_id')
);
$ dolt table import -c -s schema-original.sql mining example_file.json
Error creating reader for json file:example_file.json.
cause: syntax error at position 437 near 'stacks_block_id' in schema file schema-original.sql
When attempting to move data from json file:example_file.json to mining, could not open a reader.

Here is example_file.json:

example_file.json

If I change the schema to this:

CREATE TABLE mining (
	`stacks_block_id` int NOT NULL PRIMARY KEY,
	`miner_won` VARCHAR(255),
	`miner_won_bid` int,
	`miner1` VARCHAR(255),
	`miner1_bid` int,
	`miner2` VARCHAR(255),
	`miner2_bid` int,
	`miner3` VARCHAR(255),
	`miner3_bid` int,
	`miner4` VARCHAR(255),
	`miner4_bid` int,
	`miner5` VARCHAR(255),
	`miner5_bid` int,
	`miner6` VARCHAR(255),
	`miner6_bid` int,
	`miner7` VARCHAR(255),
	`miner7_bid` int

I can progress. I get a different error messgae

$ dolt table import -c -s schema.sql mining example_file.json
Rows Processed: 1, Additions: 1, Modifications: 0, Had No Effect: 0
An error occurred while moving data
cause: invalid character after object key:value pair: '"' [7,13]

This is due to column name incompatibility.

@timsehn
Copy link
Contributor Author

timsehn commented Dec 16, 2024

I can make the import work with the following file which has added commas and properly named columns.

example_file.json

@timsehn timsehn added bug Something isn't working customer issue import labels Dec 16, 2024
@jycor
Copy link
Contributor

jycor commented Dec 17, 2024

The primary key in the schema should be defined with backquotes not single quotes (no quotes works too).

CREATE TABLE mining (
`stacks_block_id` int NOT NULL,
`miner_won` VARCHAR(255),
`miner_won_bid` int,
`miner1` VARCHAR(255),
`miner1_bid` int,
`miner2` VARCHAR(255),
`miner2_bid` int,
`miner3` VARCHAR(255),
`miner3_bid` int,
`miner4` VARCHAR(255),
`miner4_bid` int,
`miner5` VARCHAR(255),
`miner5_bid` int,
`miner6` VARCHAR(255),
`miner6_bid` int,
`miner7` VARCHAR(255),
`miner7_bid` int,
PRIMARY KEY (`stacks_block_id`)
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer issue import
Projects
None yet
Development

No branches or pull requests

2 participants