#๐Ÿ”’ SQLitePython-Duplicating data after executing program, despite assigning a unique ID to the ID col

17 messages ยท Page 1 of 1 (latest)

undone terraceBOT
#

Hey @spring moon!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@spring moon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mental shell
#

you are not assigning anything to the ID column?

it'll just auto generate a new ID for each row if you do not specify a value for it yourself

#

did you mean to create an unique constraint over (month, day) or something

spring moon
#

i was thinking about doing it but theres duplicate values in month and day so if i were to apply a unique constraint, it would mess up the table

mental shell
#

Wtf are you expecting for your program to do then?

#

As in, what even is your desired outcome

#
  • you have duplicated data
  • you do not want duplicated rows
spring moon
#

my program does what I need it to do which is to get data from a csv files and put it into an sql table; theres 178 rows of data from the csv that its able to put into the sql table. however, when i run the program multiple times, it keeps adding the same set of data after the 178th row. thats why i want to use the unique id so that whenever i run the program, it doesnt duplicate that data again

mental shell
#

You have to create that "Unique ID" yourself, the way it is working right now it generates an ID for each row automatically by literally doing id = previous_id + 1

#
>py -m sqlite3
sqlite3 shell, running on SQLite version 3.42.0
Connected to a transient in-memory database

Each command will be run using execute() on the cursor.
Type ".help" for more information; type ".quit" or CTRL-Z to quit.
sqlite> create table test (id integer primary key, name string);
sqlite> insert into test (name) values ('dog');
sqlite> insert into test (name) values ('cat');
sqlite> insert into test (name) values ('bird');
sqlite> select * from test;
(1, 'dog')
(2, 'cat')
(3, 'bird')
sqlite> insert into test (name) values ('bird');
sqlite> insert into test (name) values ('bird');
sqlite> insert into test (name) values ('bird');
sqlite> select * from test;
(1, 'dog')
(2, 'cat')
(3, 'bird')
(4, 'bird')
(5, 'bird')
(6, 'bird')
spring moon
#

is there a way I can create a unique id automatically?

mental shell
#

That is what is happening right now.

spring moon
#

ive done that and created a unique id for it but it still keeps duplicating the data after the 178th row. like you said, the only itll stop doing it is if i manually input 178 ids and make them unique

undone terraceBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ SQLitePython-Duplicating data after executing program, despite assigning a unique ID to the ID col