RedBeardLab / rediSQL

Redis module that provides a completely functional SQL database

Home Page:https://redisql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The sequence of data columns returned by "select * ..." is wrong

dong524dong opened this issue · comments

Hello, I created the following table:
CREATE TABLE C_KAKOU(C_CPH VARCHAR,C_ID INT,C_NAME VARCHAR,C_TS TIMESTAMP);
But I am executing:
REDISQL.EXEC DB "SELECT * FROM C_KAKOU;"
20 pieces of data are returned, but the order of the columns in the data is out of order:
10) 1) "AB3990"
2) (integer) 10
3) "2019-01-01 00:01:10.0"
4) "jingzhou"
11) 1) "AD3981"
2) (integer) 1
3) "huangshi"
4) "2019-01-01 00:01:01.0"
You can see that the data in the third column and the fourth column have exchanged positions. The data in 11) ~ 20) is in the order of the columns that created the table, but the C_TS column in the data in rows 1) ~ 9) is in the third column. Why is this?
Thank you!

Hi there,

it seems very very weird.

Can you post the database?

Can it be that you have the data swapped in the database?

Cheers,
Simone

You can create a new database backed by a file:

REDISQL.CREATE_DB new test.sqlite

And then copy your db to the new one.

REDISQL.COPY DB new

And now in test.sqlite there should be your original database.

Another alternative is running:

REDISQL.EXEC DB "SELECT C_TS FROM C_KAKOU;`

And print the result.

I'm very sorry, I don't understand what you mean too much. Could you please guide me in the specific operation?

Can you run this command:

REDISQL.EXEC DB "SELECT C_TS FROM C_KAKOU;"

What is the result?

According to the steps you know, the result of the execution is still the same, and the order of the columns is out of order.

    1. "AB3981"
    2. (integer) 1
    3. "2019-01-01 00:01:01.0"
    4. "jingzhou"
    1. "AB3982"
    2. (integer) 2
    3. "2019-01-01 00:01:02.0"
    4. "jingzhou"
    1. "AB3983"
    2. (integer) 3
    3. "2019-01-01 00:01:03.0"
    4. "jingzhou"
    1. "AB3984"
    2. (integer) 4
    3. "2019-01-01 00:01:04.0"
    4. "jingzhou"
    1. "AB3985"
    2. (integer) 5
    3. "2019-01-01 00:01:05.0"
    4. "jingzhou"
    1. "AB3986"
    2. (integer) 6
    3. "2019-01-01 00:01:06.0"
    4. "jingzhou"
    1. "AB3987"
    2. (integer) 7
    3. "2019-01-01 00:01:07.0"
    4. "jingzhou"
    1. "AB3988"
    2. (integer) 8
    3. "2019-01-01 00:01:08.0"
    4. "jingzhou"
    1. "AB3989"
    2. (integer) 9
    3. "2019-01-01 00:01:09.0"
    4. "jingzhou"
    1. "AB3990"
    2. (integer) 10
    3. "2019-01-01 00:01:10.0"
    4. "jingzhou"
    1. "AD3981"
    2. (integer) 1
    3. "huangshi"
    4. "2019-01-01 00:01:01.0"
    1. "AD3982"
    2. (integer) 2
    3. "huangshi"
    4. "2019-01-01 00:01:02.0"
    1. "AD3983"
    2. (integer) 3
    3. "huangshi"
    4. "2019-01-01 00:01:03.0"
    1. "AD3984"
    2. (integer) 4
    3. "huangshi"
    4. "2019-01-01 00:01:04.0"
    1. "AD3985"
    2. (integer) 5
    3. "huangshi"
    4. "2019-01-01 00:01:05.0"
    1. "AD3986"
    2. (integer) 6
    3. "huangshi"
    4. "2019-01-01 00:01:06.0"
    1. "AD3987"
    2. (integer) 7
    3. "huangshi"
    4. "2019-01-01 00:01:07.0"
    1. "AD3988"
    2. (integer) 8
    3. "huangshi"
    4. "2019-01-01 00:01:08.0"
    1. "AD3989"
    2. (integer) 9
    3. "huangshi"
    4. "2019-01-01 00:01:09.0"
    1. "AD3990"
    2. (integer) 10
    3. "huangshi"
    4. "2019-01-01 00:01:10.0"

Hello,

can you please run this query?

REDISQL.EXEC DB "SELECT C_TS FROM C_KAKOU;"

Note that we are selecting only the C_TS column, not all.

Thanks,
Simone

After your sorting out, I seriously suspect that my code has a bug when inserting data, thank you very much!

SQLite has dynamic typing for the columns of the database. So the type that you declare is an invite, it is not really a constraint.

Sometimes is very useful, some time can end up in this kind of problem.

Cheers,
Simone

Thank you for your detailed answers. I have located a bug that caused me to be out of order when inserting data. Thanks again!

Great!

I will close the issue.

Aw congrats on opening your first issue on github!