1

I have 2 tables, for example:

table X, columns:
 A integer
 B string
 C number

table X2, columns:
 A integer
 C number

how to copy contents of X to X2 (excluding the missing columns) in Tarantool?

tried, but didn't work:

  • INSERT INTO "X2" SELECT "A", "C" FROM "X"
  • SELECT "A", "C" INTO "X2" FROM "X"

(version used: 2.6.2)

Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

1

What kind of error do you get? I don't have 2.6.2 at hand, but when I try on 2.7.0 everything works just fine:

tarantool> \set language sql
tarantool> \set delimiter ;
tarantool> CREATE TABLE x (col1 INTEGER PRIMARY KEY, col2 VARCHAR(20), col3 INTEGER);
tarantool> CREATE TABLE x2 (col1 INTEGER PRIMARY KEY, col2 INTEGER);
tarantool> INSERT INTO x VALUES (1, 'a', 10), (2, 'b', 20), (3, 'c', 30);

tarantool> SELECT * FROM x;
---
- metadata:
  - name: COL1
    type: integer
  - name: COL2
    type: string
  - name: COL3
    type: integer
  rows:
  - [1, 'a', 10]
  - [2, 'b', 20]
  - [3, 'c', 30]
...

tarantool> SELECT * FROM x2;
---
- metadata:
  - name: COL1
    type: integer
  - name: COL2
    type: integer
  rows: []
...

tarantool> INSERT INTO x2 SELECT col1, col3 FROM x;

tarantool> SELECT * FROM x2;
---
- metadata:
  - name: COL1
    type: integer
  - name: COL2
    type: integer
  rows:
  - [1, 10]
  - [2, 20]
  - [3, 30]
...
Eugene Leonovich
  • 884
  • 1
  • 9
  • 15
  • weirdly your code snippet works '__') last time i tried it was showing "unknown column 'a'" – Kokizzu Apr 07 '21 at 01:37
  • 1
    Be aware that when you enclose a column name in quotes, you have to put it in uppercase. For example, `select "col1" from x` will give `Can’t resolve field 'col1'`, while `select "COL1" from x` will work as expected. – Eugene Leonovich Apr 07 '21 at 06:49