cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

IMPORT BUG : failed to import a table whoes schema is with 'id INT DEFAULT unique_rowid() NOT NULL PRIMARY KEY '

Open yangliang9004 opened this issue 8 years ago • 1 comments

Is this a question, feature request, or bug report?

BUG REPORT my schema file and data file is like below:

$ cat old.sql
CREATE TABLE old (
	id INT NOT NULL DEFAULT unique_rowid() ,
	begin_time TIMESTAMP NOT NULL,
	"date" STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC)
);

$ cat old.csv
271017418273456130,2017-08-12 20:01:45.651456+00:00,2017-08-13

then , I run :

$ ./cockroach sql --insecure -e 'set database =temp2 ; IMPORT TABLE old CREATE USING '\''nodelocal:///nfs-backup/20180130/gp_log/old.sql'\'' CSV DATA ('\''nodelocal:///nfs-backup/20180130/gp_log/old.csv'\'') WITH temp = '\''nodelocal:///nfs-backup/20180130/temp/'\'' '

but , it report :

# Server version: CockroachDB CCL v1.1.3 (linux amd64, built 2017/11/27 13:59:10, go1.8.3) (same version as client)
# Cluster ID: 90bbef71-cf20-4c40-9c1b-3c6600b41508
Error: pq: DEFAULT expressions not supported: id INT NOT NULL DEFAULT unique_rowid()
Failed running "sql"

so , I change the table schema to be like below:

CREATE TABLE old (
	id SERIAL NOT NULL ,
	begin_time TIMESTAMP NOT NULL,
	"date" STRING NULL,
	CONSTRAINT "primary" PRIMARY KEY (id ASC)
);

strangely,It succeed. IN the document, https://www.cockroachlabs.com/docs/stable/serial.html#syntax , it said that " The SERIAL type is equivalent to INT DEFAULT unique_rowid()."

I think this is a bug.

yangliang9004 avatar Jan 30 '18 12:01 yangliang9004

@yangliang9004 thank you for your report!

@mjibson please triage.

knz avatar Jan 30 '18 15:01 knz