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

[YSQL] Please support insert multiple values #2489

Closed
teochenglim opened this issue Oct 2, 2019 · 5 comments
Closed

[YSQL] Please support insert multiple values #2489

teochenglim opened this issue Oct 2, 2019 · 5 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) community/request Issues created by external users

Comments

@teochenglim
Copy link

INSERT INTO [mask_table] ( COLUME ) VALUES ( value1 ) , ( value2 ) is not working. 

Please support this popular feature.

@yugabyte-ci yugabyte-ci added the community/request Issues created by external users label Oct 2, 2019
@ndeodhar ndeodhar self-assigned this Oct 2, 2019
@ndeodhar ndeodhar added the area/ysql Yugabyte SQL (YSQL) label Oct 2, 2019
@ndeodhar
Copy link
Contributor

ndeodhar commented Oct 2, 2019

@teochenglim This is already supported, for example:

yugabyte=# create table foo(a int primary key, b int);
CREATE TABLE
yugabyte=# insert into foo(a) values (1),(2),(3);
INSERT 0 3
yugabyte=# select * from foo;
 a | b 
---+---
 1 |  
 2 |  
 3 |  
(3 rows)

Can you add more details on the query that you tried and the error that you got?

@teochenglim
Copy link
Author

teochenglim commented Oct 2, 2019

Sure. But my case is slightly complex than yours.

drop table a;
drop table b;
drop table c;
CREATE TABLE B (
    id SERIAL PRIMARY KEY,
    name VARCHAR(3) UNIQUE
);

CREATE TABLE C (
    id SERIAL PRIMARY KEY,
    num INT UNIQUE
);

INSERT INTO B (name) VALUES ('1'), ('2'), ('3'), ('4');
INSERT INTO C (num) VALUES (1), (2), (3), (4);

CREATE TABLE A (
    id SERIAL PRIMARY KEY,
    AA VARCHAR(3) NOT NULL REFERENCES B ( name ),
    AB INTEGER NOT NULL REFERENCES C ( num ),
    AC TIMESTAMP WITHOUT TIME ZONE DEFAULT now()
);

INSERT INTO A (AB, AA) VALUES
(4, 'AAA'),
(4, 'AAB'),
(4, 'AAC'),
(4, 'AAD'),
(4, 'AAE'),
(4, 'AAF'),
(4, 'AAG'),
(4, 'AAH'),
(4, 'AAI'),
(4, 'AAJ'),
(4, 'AAK');
ERROR:  Operation only supported in SERIALIZABLE isolation level
HINT:  See https://github.com/YugaByte/yugabyte-db/issues/1199. Click '+' on the description to raise its priority

@ndeodhar
Copy link
Contributor

ndeodhar commented Oct 2, 2019

That error is related to foreign keys and not to multiple insert values.
Currently, we only support foreign keys in serializable isolation. (We will change that soon to work with any isolation level).

To make this work, you can do

SET default_transaction_isolation='serializable';

INSERT INTO A (AB, AA) VALUES
(4, 'AAA'),
(4, 'AAB'),
(4, 'AAC'),
(4, 'AAD'),
(4, 'AAE'),
(4, 'AAF'),
(4, 'AAG'),
(4, 'AAH'),
(4, 'AAI'),
(4, 'AAJ'),
(4, 'AAK');

@teochenglim
Copy link
Author

Good to know. thanks.

@hectorgcr
Copy link
Contributor

The foreign keys issue with default isolation level is being tracked by #1199. Closing this particular issue since INSERT with multiple value lists is already supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) community/request Issues created by external users
Projects
None yet
Development

No branches or pull requests

4 participants