db=mysql.connector.connect(host="localhost",user="ishan",passwd="nashid73",db="testdatabase")
users=[("tim","techwithtim"),("joe","joe123"),("sarah","sarah1234")]
user_scores=[(45,100),(30,200),(46,124)]
mycursor=db.cursor()
q1="CREATE TABLE Users (id int PRIMARY KEY AUTO_INCREMENT,name varchar(50),password varchar(50))"
q2="CREATE TABLE Scores(userID int PRIMARY KEY,FOREIGN KEY(userID) REFERENCES Users(id),game1 int DEFAULT 0,game2 int DEFAULT 0)"
#mycursor.executemany("INSERT INTO Users(name,password) VALUES (%s,%s)",users)
q3="INSERT INTO Users(name,password) VALUES (%s,%s)"
q4="INSERT INTO SCORES(userID,game1,game2) VALUES (%s,%s,%s)"
for x,user in enumerate(users):
mycursor.execute(q3,user)
last_id=mycursor.lastrowid
mycursor.execute(q4,(last_id,)+user_scores[x])
mycursor.execute("SELECT * FROM Users")
for x in mycursor:
print(x)
#databases
1 messages · Page 169 of 1
this is the code
the error is shown at line 20
it says data is too long for 'password'
any fix?
Check if the table really does look like q1 is hinting at.
And it's a bad idea to store passwords in plain text, very unsafe (= bad) idea.
are you using atlas? @stark sparrow
maybe he is talking about this mongo_url = 'keep dreaming' there is a space between keep and dreaming
that's not a valid url
yea, it's not a valid URL @stark sparrow
no
it is not the url. there is no space in the real url
local db?
i think it is
i used my public ip in security. does it cause problem?
make sure you have your ip whitelisted in the database config
can u pls tell me how to do that?
sorry I have to go
your error is basically ReplicaSetNotPrimary
means?
google about the error
ok
it is also ServerSelectionTimeoutError
ig
Can perhaps yall know about something in #help-mushroom ?
Anyone here using sqlalchemy with encode/databases ? Is it just me or tables created thru declarative_base are completely incompatible with anything requiring raw sqlalchemy core (eg, async stuff)
metadata = sqlalchemy.MetaData()
TableBase = declarative_base(metadata)
class Cat(TableBase):
__tablename__ = "cat"
id = Column(primary_key=True)
# ...
database = databases.Database(DATABASE_URL)
# ... snip... database connect etc
# None of this works
await database.execute(Cat.id == 1)
await database.execute(Cat.c.id == 1)
from sqlalchemy import select
await database.execute(select(Cat).where(Cat.id == 1))
Answering myself: https://github.com/encode/databases/issues/105
Hi Everyone! Quick question: Is there a way to create a db using sqlite3 for a virtualenv only?
Meaning, once I delete the virtualenv the db will be gone as well or keep multiple instances of the same db across different envs
i have never seen VISIBLE. where did you get that from?
channels = await conn.fetchrow('SELECT modlog, publicmodlog FROM channels WHERE guildid = $1', guild.id)
Will asyncpg return None if for example modlog is available but publicmodlog isn't?
By available, do you mean publicmodlog is null?
If modlog is null but publicmodlog isn't, channels will be a Record object that contains both values
Hi i just started using asyncpg, and postgres I just switched from aiosqlite. I want to INSERT OR IGNORE INTO but i'm getting error
here is my code
sql = ('INSERT OR IGNORE INTO logging (guild_id,message_edit,message_deletion,role_changes,name_update,member_movement,avatar_changes,bans,channels,pins,purge) VALUES ($1,$2,$2,$2,$2,$2,$2,$2,$2)')
val = (guild.id,False,False,False,False,False,False,False,False,False,False,False)
await self.bot.conn.execute(sql,val)
the error
File "asyncpg/protocol/protocol.pyx", line 168, in prepare
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "OR"
postgres has different syntax to express conflict resolution
youre looking for on conflict do nothing
it goes at the end of your query (there are examples in the docs)
Hello All,
At the risk of saturating the ecosystem "even more" with a model management tools, I am happy to share another uni-model approach I have been working on to address the issue of db model management, access, migrations, and caching. Much like sqlmodel, there is only a single model to manage( which happens to be pydantic) but with further abstractions to try and make model creation & relationships a bit easier. Happy to hear your thoughts, I hope this makes your lives a little easier 🙂
Not sure if this is a database question but here goes.
How do I store permanent data in my application. For example in my banking website, I know that the list of supported banks will always be added to. But every time I change the database, this list of banks gets deleted obviously. One possible solution is database seeding but I was wondering if there are better ones.
In development it is common to blow away your tables and start from scratch. using drop and create. Though for production systems its required to run db migration scripts with alter statements etc to keep the data safe. django has migrations built in, and sqlalchemy has alembic to manage migrations.
So there is not other better method to do this except databases?
I'm confused, what do you mean by 'change the database'?
Heyy does anyone know how to create a quiz using python and mysql connectivity ?
Delete the existing one and creating a new one
yea so you shouldn't delete the database if you don't want to lose the data 😄
if you want to persist the data regardless you can make a backup, but why are you deleting it in the first place?
you shouldn't develop against the production database, as mentioned above - for local development you would start a local, temporary database, and once your code is ready, it is shipped to production where it connects to the real database
if you need to make changes in the structure of the production database, that's where you'd use migrations
what database should i use for my discord bot, may you provide a tutorial video with it
does anyone know how to fix this unexpected argument thingy?
im following a tutorial to the dot but it seems to error for me
C:\Users\name\AppData\Local\Programs\Python\Python39\lib\site-packages\flask_sqlalchemy\__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. warnings.warn(FSADeprecationWarning( Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\name\FlaskMarket\market.py", line 7, in <module> class Item(db.Model): File "C:\Users\name\FlaskMarket\market.py", line 9, in Item id = db.Column(db.Integer(), primary_key=True) TypeError: Column() got an unexpected keyword argument 'primary_key'```
this is the error
is it added to by non-developers as well?
in that scenario you could be forced to hand-write migration scripts, which is no fun
No they aren't. Is there any solution?
how many items are in one of these tables and how often do they get changed?
So it's for a banking application, and the table is for supported partner banks. So they get changed occasionally
it's basically configuration data then?
personally i would prefer a JSON flat file or XML file for semi-static data, if the only people doing changes to the DB are developers. then it's impossible for it to get out of sync with the application code
Yes you could say that
But I need foreign keys to this data so i decided the database approach.
maybe primary_key=True goes into the db.Integer() constructor, not the db.Column() constructor ?
Hi guys , I need a little help. I am new to mongodb and I have been trying to understand mongodb atlas so I can set it up with nodejs and express for a react app backend.
I would really appreciate some help or a walkthrough of what I should do because I am stuck
You sure it's
id = db.Column(db.Integer(), primary_key=True)
and not
id = db.Column(db.Integer, primary_key=True)
hey
@bot.command()
@commands.has_role('key')
async def deletekey(ctx, *, arg):
rkey = int(arg)
print(arg)
cursor.execute(f"DELETE FROM `sheesh` WHERE {rkey}")
await ctx.send(f"There we're no errors, check to make sure key was deleted.")
This won't delete
I get no errors it just doesn't delete
it's phpmyadmin btw
@upper rampart that‘s not how you write the condition, you want to do something like „WHERE x = 3“, also if the argument is a truthy value you will delete anything on the table
what you‘re missing to actually perform the delete though is a connection.commit() call
can you show in code
it works just fine
now
sync def deletekey(ctx, *, arg):
rkey = int(arg)
print(arg)
cursor.execute(f"DELETE FROM sheesh WHERE ekey={rkey};")
I did this
oh but the connection.commit
made it actually execute after
i do the command
instead of me having to add something new onto the list
ty @ionic pecan
There shouldn't really be a reason why you'd need to delete the table just to update or create new records in it.
(If you're dropping tables and needing to recreate them for your application to work, this should be a smell - and means you're doing something wrong)
Additionally, since you're creating a banking application - I would highly encourage you to read up on the laws that pertain to the geographical areas in which you plan on releasing your application. It's quite possible you aren't allowed to delete information from your database and would need to do a soft-delete instead.
Often times when working with financial data, you'd need to store that for a certain period of time, under specific, strict circumstances, and keep records that could be audited.
Hey guys, do you know how to set greek collation in django for a specific table? I just need it to be sorted correctly according to the greek alphabet in django admin. I'm using postgres.
Hey, can you check this code out and see whats wrong. This is sqlite3 code
This works:
userinfo = [usernameinput, passwordinput]
database.execute("INSERT INTO Basic_Credentials (username, password) VALUES (?, ?)", userinfo)
But this doesnt:
userinfo = ['Basic_Credentials' , usernameinput, passwordinput]
database.execute("INSERT INTO ? (username, password) VALUES (?, ?)", userinfo)
can you tell me why I can't pass the list with 3 elements for each of the 3 '?' marks?
The qmark placeholders work only for values I believe, not stuff like table/column names
ah ok, i fixed this by adding the variable itself into the string
I just started MongoDB and made a basic collection with array
Now I want to query all elements in the array, how do I do that?
new_server = {"server": guild.id, "xp_per_message": 10,
"double_xp_role": "NA", "level_channel": "✨・level-ups",
"talk_channel": "❄・alex", "quote_channel": "💯・quotes",
"ignored_channel": []
}
db.insert_one(new_server)
ignored_list = db.find_one({"server": message.guild.id}, {"ignored_channel"})
if message.channel in ignored_list:
ignored_list = db.find_one({"server": message.guild.id}, {"ignored_channel"}) is probably wrong.. can someone tell me how do I get all elements in ignored_list key?
This is wat collection looks like
use XAMPP and Heidisql and then enable mysql
example vid?
because i've never even hurd ofbit
of it
Hey I have an ec2 instance and I installed xampp and now I am able to access it using it's IP on port 80, however I want to connect to mysql using python which I am not able to, can anyone help me on this?
Python script won’t be running on the localhost, I want to run it remotely
Anyone here who could help me with query optimization? Maybe in DM
How can I access mysql hosted using xampp on aws from python? I can access xampp using AWS public IP
Use the IP as the domain name
any idea on how to make a flexible connection to different databases?
mysql.connect(
host='12.323.43.12',
username='root',
password='password',
database=mydb
)
This is what I have been using but it isn’t working
it should be py mysql.connector.connect(host='12.323.43.12', username='root', password='password', database="mydb" )
module 'mysql.connector' has no attribute 'connecter'
I have imported mysql.connector as mysql
So the one I have written above is just fine I guess
What happens when you try to connect? Is there an error? "Isn't working" is not something anyone can help with
Can you elaborate? Normally in my applications, I write functions and classes that accept a database connection object as a parameter, so i can do things like pass in a mock database connection in my test suite. So maybe that design pattern would be useful here
raise errors.InterfaceError(\nmysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '12.323.43.12:3306' (61 Connection refused)
SELECT * FROM series WHERE title 'th';
what do I add between title and 'th'; to search for titles with 'th' in them?
Does it work if you use some other client? Like sequel pro or mysql workbench etc
title LIKE '%th%' in most databases
The % is a wildcard, matching zero or more letters
thankyou i tried like but not the % bit
I would like to start learning about databases, what database should i learn first
sqlite is a good one to start with because you don't need to run a separate server, it's just a file
Is MySQL a good database with django
i have a home server, can i use that
it's fine, it does the job
the "server" is just a separate program, you can even run it on the same computer you use for development. if you want to try using a full server database, personally i think postgresql is easier to use than mysql
do you know a good source I can go to learn
there are some in the pinned messages. also read the documentation, it's there for a reason
okay
thru pymongo how do I emulate collections.distinct but return all fields?
Guys, SQL or NoSQL?
I am trying to learn PostgreSQL, but it's TO BORING
Tables are not my style. Should I try NoSQL?
PostgreSQL can hold semi structured data through some types of columns such as Json and Xml, but you will need of SQL knowledge even in some NoSQL programs
Which type of database you should use depends on what you want to do, what your data looks like and how much you care about that data, but it is important to know both SQL and NoSQL if you want to work with Big Data
(and just to clarify about "how much you care about that data" - sometimes businesses will just store a lot of data, usually in a NoSQL database (or data "lake" / "ocean"), because they want to have that data available in the future, but do not want to bother with cleaning or processing it at the moment)
connection = pymysql.connect(host='sql105.epizy.com',
user='XXX',
password='XXX',
database='XXX',)
Error:
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'sql105.epizy.com'
I'm trying to connect to infinity free database
But it wont work
in the first page of google results about epize, I found a link to a Quora question in which all answers say that it is awful and has lots of downtime, so I would probably advise for you not to use that hosting service
maybe try to add the https:// before the host domain though
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has
expired (_ssl.c:1124)')>]>
wtf
Are you sure that your certificate end date is not in the past?
i have no clue what that means
Can you give more details what are you doing rn?
trying to use mongodb
It says nothing to me
What tool are you using? Are you trying to type a command or what? I am not an oracle
You need to write what you are doing to get help
my mongodb database just failed idk it was just working fine minutes ago and started saying this
did to me too
found a fix yet?
odd, check if your database has any settings, and if so, look for anything related to certificates there
how?
nawl
Go to whichever site hosts your database (or if you host it yourself, open whichever GUI app you have) and look for some sort of "settings" or "configuration" page
nothing
no clue then, you might want to try contacting support but they might just fix it soon-ish
omg
or see if there's some discord server for mongo db
it might be affecting everyone on your cluster / region assuming that it's an issue in their side
i dont even know why its saying a vertificate is expired im not even sing a cert
can someone help with some pymongo stuff? I get this error: pymongo.errors.ServerSelectionTimeoutError ... [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123) when trying to connect to an atlas db but it was working fine a few hours earlier. The db itself is fine as i'm connected w/ a cmd line but pymongo doesn't want to work.
it looks like your certificate expired
same ☝️
@frail glade @torn sphinx where is the db hosted?
hosted on atlas
maybe atlas goofed
dunno, i can connect with cmd line
if the ssl cert expired, that's on them
so I doubt
ah
i guess i can try this
if it was working fine a few hours earlier that's suspect. but did you change the code?
no
and you can open a new cli connection, right now?
yep
just reopened
i just did client = pymongo.MongoClient(uri, ssl_cert_reqs=ssl.CERT_NONE) but i'm just confused why it's acting weirdly now
hm, that's odd
the reason i suspected a problem w/ the host is that 2 people just posted the same issue in short succession
i guessed that they were using the same misconfigured host
so does this not work?
client = pymongo.MongoClient(uri, ssl_cert_reqs=ssl.CERT_NONE)
that should disable ssl cert checking entirely, as far as i know
it's fine
it's possible that the cli is just not doing ssl checking by default, although that'd be weird
idk maybe
to use database in discord bot.. do we need to keep database online separately?.. or it works some other way?
i'm new to db thing..., so no booliee
also, ping me when u reply
The same thing has happned to me
like out of no where it stop working
locally
but on my host it works fine
🔸 How can I store and delete image files on MongoDB ?
- I want to make an admin panel with Flask for a website I'm developping.
Have you seen this? https://www.mongodb.com/developer/how-to/storing-large-objects-and-files/
Also check this answer on StackOverflow: https://stackoverflow.com/a/40017346
Same error but no wonder why it is working no heroku
like It was also working on my PC around <t:1632975185:R>
and I tried restarting the app on heroku, and it works
Thx
I am guessing that there are no people around which are waiting for questions and respond immediately so give us some time
Check usage page in docs - https://magicstack.github.io/asyncpg/current/usage.html#asyncpg-usage
Here you have how to get row, create table and insert data
idk how they are specifying and changing a specific row
Do you know SQL?
i am using postgres
Update INSERT INTO query into UPDATE
Good question 
idk why i am not understanding the docs they have different syntaxes as i saw in yt
What do you mean different syntaxes?
disabling ssl cert is not a good option right?
Yes, asyncpg uses a slightly different interface compared to the standard db-api in python
It's okay for local development
I can think of more dangerous things you can do, but if you are running this in some kind of production environment you probably don't want to disable it
Disabling certificate verification is equivalent to not using SSL
@harsh pulsar do you have fix to the [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: error yet?
no, i can only guess
its weird becuase it doesn't work on my local machine
but works on my host provider?
same so I used ssl_cert_reqs=ssl.CERT_NONE for local machine
Maybe it has it somethinbg to do with: DST Root CA X3 will expire on September 30, 2021.
your host probably has the new cert but your local machine doesn't
so how can i get the new cert?
well, hold on
the cert should be sent by the server
then the client verifies it
you would only need a "new cert" if the root certificate or one of the intermediates changed
so ignore what i said
pymongo.errors.ServerSelectionTimeoutError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired
why is it happening :/
My director at work sent out a team-wide email saying to join a tech conference session about PostgreSQL and how it's way better than the Oracle DB servers we do use
@ me who took a database course in uni over 4 years ago where we used Postgres: "yeah this was obvious, are you only learning this now?"
It's all fun and games until you realize you're more qualified than some of your superiors
you're the 3rd person reporting this here in 2 days. if you're using mongodb atlas, it sounds like they messed up their certificates
oof
hi
i am working with postgres
asyncpg
and it is showing this
when i am loading a row's object
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: Connection not available.
i am getting this error when connecting with mysql any suggestions
yes, that's correct, asyncpg returns Record objects
do you have a mysql database running locally?
that is solved ty
how to connect postgres with heroku
i was using
pgadmin 4
but when update in heroku
it is saying address not connected
show the full error
Has anyone connected to a power bi dataset with python?
considering your error code is trying to access a database on localhost, then yes you would need to run a mysql server locally
Ive been pondering about this for hours..
Trying to make a Quest system where users can select 1 quest at a time to pursue...
I was thinking having 3 possible quests for each game I have.
How horrible is it doing it this way?
CREATE TABLE `Quests` (
'DiscordID' varchar(64) DEFAULT NULL,
'ActiveQuest' varchar(30) DEFAULT NULL,
'BlackjackWins' tinyint(2) DEFAULT 0,
'BlackjackGames' tinyint(2) DEFAULT 0,
'BlackjackProfit' tinyint(2) DEFAULT 0,
'CoinflipWins' tinyint(2) DEFAULT 0,
'CoinflipGames' tinyint(2) DEFAULT 0,
'CoinflipProfit' tinyint(2) DEFAULT 0,
```I have around 6 games in total... so it'd be 6*3=18 columns for games + the DiscordID and ActiveQuest. 20 columns total.
The one they choose, ActiveQuest will be set to that name (such as CoinflipWins). Every time they win in coinflip, that number goes up for CoinflipWins. Once they reach x amount of wins, they complete the quest and can choose another one to start.
@arctic badger ```sql
CREATE TABLE quests (
discord_id varchar(64),
quest varchar(255),
is_active boolean DEFAULT false,
games integer default 0,
wins integer default 0,
profit integer default 0,
PRIMARY KEY (discord_id, quest)
)
make this "long" format, not "wide"
WOW IM FUCKING STUPID.
Yea, quest will also be telling me what game it is lmao. 🤦 Instead of making 3 variables for EACH game
then you don't have to add or remove a column any time you want to change or add a game
you can't get smart if you don't get stupid first
facts.
and wdym, make this "long" format, not "wide"
like are u just talking about my spacing?
and unfortunately, SQLite doesnt have boolean :p thats why i did tinyint(1)
"wide" format is having one column per quest, "long" format is having a quest column
ahh, ok. good to know. well, thank u so much! u just saved my database a lot of storage 😄
i don't think you save any space this way, just your sanity
consider that tinyint(2) is very restrictive. nobody can play a game more than 99 times
or wait
is this mysql?
SQLite only knows integer for whole numbers.
oh you said sqlite
it also only knows "text" and not "varchar", right?
i get all my databases mixed up
yeah, text only.
CREATE TABLE quests (
discord_id text,
quest text,
is_active integer DEFAULT 0,
games integer DEFAULT 0,
wins integer DEFAULT 0,
profit integer DEFAULT 0,
PRIMARY KEY (discord_id, quest)
)
but is discord_id text?
apparently in their application it is
CREATE TABLE quests (
discord_id text NOT NULL,
quest text NOT NULL,
is_active integer NOT NULL DEFAULT 0 CHECK (is_active in (0, 1)),
games integer NOT NULL DEFAULT 0,
wins integer NOT NULL DEFAULT 0,
profit integer NOT NULL DEFAULT 0,
PRIMARY KEY (discord_id, quest)
)
I would make that quest a quest_id and link to a second table where I would define the games.
thanks
How do I do this: py cursor.execute("ALTER TABLE main RENAME COLUMN user_ovr TO user_rating INT")
sqlite3 btw
Lets say this is my document in a mongodb collection
uid = await self.coll.find_one({"user_id": str(user_id)} I am doing that to find the document how would I now return the reaction in that document?
reaction1 = uid["reaction"]
await message.add_reaction(reaction1)
So doing that should work right?
try it and see
hm...
so im doing
questName = "Quest1"
conn = sqlite3.connect(config.db)
sql = f"""INSERT INTO Quests(DiscordID, ActiveQuest)
VALUES ({ctx.author.id}, {newQuest});"""
conn.execute(sql)
conn.commit()
```but it's saying `no such column: Quest1`
I've never had this issue before.. o.0
It clearly says the questName is a value lol... and im inserting THAT VALUE into the ActiveQuest column..
Don't use string formatting for SQL queries, you should be doing something like
sql = "INSERT INTO Quests(DiscordID, ActiveQuest) VALUES(?, ?)"
conn.execute(sql, (ctx.author.id, "Quest1"))
conn.commit()
Apart from the issues that could occur from not properly quoting the values (which is the issue you're having), it is also vulnerable to SQL injection
#databases message explains what SQL injection is
ah, ok. i was trying to convert it a different, incorrect way
thanks for the code!
reaction1 = uid["reaction"]
TypeError: 'NoneType' object is not subscriptable
how to connect pgadmin 4 with heroku?
That means your find_one query returned None, because there were no matching documents with that user id
Yeah I figured it out thanks
Guys, the SUM() function is not working. What happened?
I made a test, and the problem is the argument.
Everything okay with the function. Sorry guys(NOOB HERE)
Hello,
I use sqlAlchemy, and a try to create a Generic class for some query.
for the update query I've got a problem.
when I use
self.session.query(self.table).filter(filter).update()
this method commit automatically my query, and a would like commit later.
I try to use
session.add()
but since my class is generic, I can't use
def update(self, update, filter):
up = self.session.query(self.table).filter(filter)
for row in up:
for key in update.keys():
row.name = update[key] # it's impossible beaucuse I would like use generic methode
self.session.add(row)
update({TableTest.name:"Arthur"}, TableTest.name=="Jean")
If someone has an idea?
should be VALUES
-- CreateTable
CREATE TABLE "SentEmail" (
"id" UUID NOT NULL,
"type" TEXT,
"sentOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"status" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "SentEmail_pkey" PRIMARY KEY ("id")
);
In this table, how can use ALTER (or anything else) to change the datatype of type to TEXT[]?
ob ok
it still that
whats the error?
change . to ,
oh ok thanks
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 135, in on_message
currentownerxp = d[0][0]
IndexError: list index out of range
what
Your price column is from type varchar which can not be summed.
.
Take a look at d. Looks like your fetchall() didn't select anything which makes d and empty list and d[0] and index error.
else:
xp = generateXP()
abc = userleveldb.cursor()
abc.execute(f"SELECT xp FROM exp WHERE client_id = {str(message.author.id)}")
d = abc.fetchall()
currentownerxp = d[0][0]
if len(currentownerxp) == 0:
if message.author.id not in guild_id_used:
ownerid = message.author.id
h = generateXP()
guild_id = message.guild.id
abc.execute(f"INSERT INTO xp VALUES(%s,%s,%s)",(ownerid,h,guild_id))
abc.commit()
print(d)
else:
ownerid = message.author.id
h = generateXP()
guild_id = message.guild.id
abc = userleveldb.cursor()
abc.execute(f"INSERT INTO xp VALUES(%s,%s,%s)",(ownerid,h,guild_id))
abc.commit()
print(d)
but i added if d is None then it insert it
BAD:
abc.execute(f"SELECT xp FROM exp WHERE client_id = {str(message.author.id)}")
Good (edit: switched ? to %s):
abc.execute("SELECT xp FROM exp WHERE client_id = %s", (message.author.id,))
You need do check d to know if the select returned any row or not.
Looks like you want if len(d) == 0: and not if len(currentownerxp) == 0:
and the inner if/else are looking the same?
and the select has xp as columnname and exp as tablename, but the insert is using tablename xp?
oh
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 153, in on_message
abc.execute("SELECT xp FROM exp WHERE client_id = %s, guild_id = %s",(message.author.id,message.guild.id,))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 568, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\connection.py", line 846, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\connection.py", line 656, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', guild_id = 872362022375915580' at line 1
where
If you have more than one where condition you need to and/or them:
abc.execute("SELECT xp FROM exp WHERE client_id = %s AND guild_id = %s", (message.author.id, message.guild.id))
maybe play at https://sqlbolt.com/ for some SQL learning.
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 82, in __call__
return bytes(self.params[index])
IndexError: tuple index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 157, in on_message
abc.execute("UPDATE xp SET exp = %s WHERE client_id = %s AND guild_id = %s",(message.author.id,message.guild.id))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 557, in execute
stmt = RE_PY_PARAM.sub(psub, stmt)
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 84, in __call__
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Not enough parameters for the SQL statement
huh
There are three %s but you give only two arguments
and you used the tablename and columnname the wrong way around.
wut
exp is the tablename and xp is the column
UPDATE tablename SET columnname = ...
is mongodb fixed yet oof
Nothing for help me?
does anyone have any experience with snowflake?
Can I generate a dictionary with a custom name to a file?
Whenever I save a dictionary as is j just get the contents
how are you saving a dictionary? you usually should not try to just write string-ified python things to a file. you should use json
and you definitely shouldn't try to enforce the name of the python variable in the file
I want to store rating 0-5 for users in my table, do I need to have another table to store all the previous ratings so I can calculate the average rating. If so, How can I make a value in one table be the result of a calculation of data from another?
not stringafied but yeah i guess i'll just use a json
its saving the output of the dictionary
how else are you saving it if not as a string? with pickle?
dumping it
with json
with open('rr.json', 'w') as convert_file:
convert_file.write(json.dumps(new_dict))```
this saves the content of the dictionary
but I want to be able to iterate over each dictionary generated
I want something like this
self.options = {
discord.PartialEmoji(name=emote_name, id=emote_id): role_id,
but instead of self.options =
i want to make the dictionary be dependent on a user input
so user supplies...
id, emote_name, emote_id, role_id
id = {
discord.PartialEmoji(name=emote_name, id=emote_id): role_id,```
than it saves that and writes to a file
or appends it if it already exists
the problem with json is that it's hard/impossible to append to it cleanly without overwriting it
can you be more specific about what data you want to store?
its just values
sec
discord.PartialEmoji(name=emote_name, id=emote_id): role_id,
}```
on my end i type like...
/rr 2 test 1 2 3
2 test 1 2 3 being the variables mentioned above
id, emote_name, emote_id, role_id
json.dumps doesn't throw an error about discord.PartialEmoji?
you probably assumed right. you'd need to serialize that thing to some other representation, e.g. emote_id
yeah it errors out
i may have multiple sets of values per message_id as well
so its not as simple as just tossing in some key values
and using that
i have asked a db and flask realated question in #web-development , can anyone help?
not on their end, not sure if there will be a fix on their end tbh, its probably as intended
gonna work out resolution in next couple of hours and will update with how i fix it
don't really like the idea of having to install certificates my end, but maybe that'll be the way to go
MongoDB Developer Community Forums
Hello, I keep getting this error with Python. This just started happening today, and I changed none of my code. I dont know whats happening. > Ignoring exception in on_message > Traceback (most recent call last): > File "C:\Users\trexx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event > ...
or potentially as someone linked previously:https://stackoverflow.com/questions/54484890/ssl-handshake-issue-with-pymongo-on-python3
unfortunately this is the nature of things. either you use pickle (bad idea, unsafe), or you have to actively think about how to serialize and deserialize information between your disk and your program
Root Certificates Our roots are kept safely offline. We issue end-entity certificates to subscribers from the intermediates in the next section. For additional compatibility as we submit our new Root X2 to various root programs, we have also cross-signed it from Root X1.
Active ISRG Root X1 (RSA 4096, O = Internet Security Research Group, CN =...
Install ISRG Root X1, ISRG Root X2, Let’s Encrypt R3 .der certificates and works
im in a complicated problem...
I have this function:
@staticmethod
def fetchOne(sql):
conn = sqlite3.connect(config.db)
cursor = conn.execute(sql)
data = cursor.fetchone()
conn.close()
return data
```but I am trying to utilize better programming practices by passing in the variables to the execute functions, such as `conn.execute(sql, (value1, value2)) `
but sometimes i have 1 value, 2 values, 3 values (3 max)... so is there a way to create one function to do all this?
edit - would it be a bad idea to do it like this?
```sql
@staticmethod
def fetchOne(sql, values: list):
conn = sqlite3.connect(config.db)
if len(lst) == 1:
cursor = conn.execute(sql, values[0])
if len(lst) == 2:
cursor = conn.execute(sql, values[0], values[1])
if len(lst) == 3:
cursor = conn.execute(sql, values[0], values[1], values[2])
data = cursor.fetchone()
conn.close()
conn.execute(sql, *values) 🙂
oh waittttttttttttttttttttttt.
The second value of execute takes in a list, right? so I can literally just used values?
hmm, *?
In most cases yes, actually. There is one library that takes them as separate arguments, so I thought that's what you were using at first
So just execute(sql, values) for sqlite
Explanation of the * syntax: https://stackoverflow.com/q/36901
lol appreciate that 😄
Sure ask your issue
c.execute(f"SELECT * FROM user_reactions WHERE reaction_message_id = '{reaction.message_id}'")
will this work?
is this aiosqlite?
it is sqllite
3
# setting up SQLLite3 connection
connection = sqlite3.connect('user_reactions.db')
c = connection.cursor() # create cursor
# c.execute('DELETE FROM user_reactions')
this is how I got my connection
yes, aiosqlite is an async version of sqlite3 which is better as it is not blocking
!blocking
Why do we need asynchronous programming?
Imagine that you're coding a Discord bot and every time somebody uses a command, you need to get some information from a database. But there's a catch: the database servers are acting up today and take a whole 10 seconds to respond. If you do not use asynchronous methods, your whole bot will stop running until it gets a response from the database. How do you fix this? Asynchronous programming.
What is asynchronous programming?
An asynchronous program utilises the async and await keywords. An asynchronous program pauses what it's doing and does something else whilst it waits for some third-party service to complete whatever it's supposed to do. Any code within an async context manager or function marked with the await keyword indicates to Python, that whilst this operation is being completed, it can do something else. For example:
import discord
# Bunch of bot code
async def ping(ctx):
await ctx.send("Pong!")
What does the term "blocking" mean?
A blocking operation is wherever you do something without awaiting it. This tells Python that this step must be completed before it can do anything else. Common examples of blocking operations, as simple as they may seem, include: outputting text, adding two numbers and appending an item onto a list. Most common Python libraries have an asynchronous version available to use in asynchronous contexts.
async libraries
The standard async library - asyncio
Asynchronous web requests - aiohttp
Talking to PostgreSQL asynchronously - asyncpg
MongoDB interactions asynchronously - motor
Check out this list for even more!
should I swap to aiosqlite
you would need to serialise it in some way
sorry
c.execute(f"DELETE FROM user_reactions WHERE reaction_message_id = '{int(reaction.user_id)}' AND WHERE user_id = '{int(reaction.user_id)}'")
why is this erroring
operational error near where
Replace the 2nd WHERE with~~ a another AND~~ nothing
so AND AND?
slimer
just AND?
Yes just 1 AND
i wanna get this emoji out of the db to add as a embed reaction
but its not pulling the data
await self.bot.db.execute('SELECT lastfm_emoji FROM user_data WHERE user_id = ?', (ctx.author.id,))
don't you need () around the ?
what
nevermind ig
??
if not upvote:
await message.add_reaction("👍")
await message.add_reaction("👎")
else:
vote = self.bot.db.execute('SELECT lastfm_emoji FROM user_data WHERE user_id', (ctx.author.id,))
await message.add_reaction(vote)
bruh
You need to use smth like fetchone/fetchall
so instead of
self.bot.db.execute
it would be
self.bot.db.fetchall
?
or
fetchone
since im getting 1 emoji for the reaction
No not like that

You need to execute it first
oword
I can try to find example from somewhere, it may take a few minutes on phone
cursor = await db.execute("whatever")
row = await cursor.fetchone()
oh really
vote = self.bot.db.execute('SELECT lastfm_emoji FROM user_data WHERE user_id', (ctx.author.id,))
row = vote.fetchone('lastfm_emoji')
?
Remove the thing inside brackets in last line.
Show the code?
Add if statement ```py
vote = ...
if vote is None:
print("nothing in db")
#other code
Does the database have anything?
And current code looks like?
Did the print(row) do anything?
nope
Then it can't find anything I guess. But I can't help any further on mobile, sorry.
for i,row in PatientData.iterrows():
sql= '(INSERT INTO PatientData(DIAGNOSIS_AGE,SEX,ETHNICITY_CATEGORY,HISTOLOGY,ADJUVANT_TREATMENT,ECOG_PERFORMANCE_STATUS,SMOKING_HISTORY,SMOKING_HISTORY_PACK_YEAR_VALUE,RELAPSE_FREE_STATUS,RELAPSE_FREE_STATUS_MONTHS,UBIQUITOUS_ASSAY_PANEL,PERCENT_NECROSIS,TUMOR_VOLUME_CM3,TUMOR_STAGE,POSITRON_EMISSION,cFDNA_INPUT_NG,LYMPH_NODE_INVOLVEMENT,KI67_PERCENTAGE,CT_SLICE_SPACING,PATIENT_ID) VALUES(%d,%s,%s,%s,%s,%d,%s,%d,%s,%f,%d,%d,%f,%s,%f,%d,%s,%d,%f,%s))'
cursor.execute(sql, tuple(row))
print("Record Inserted")
cursor.commit()
Error While Connecting to sql Not all parameters were used in the SQL statement
what error is there can anyone help #databases
have you tried to use the dataframe to_sql() function? It will be faster then iterating through all rows in a pandas dataframe.
If you have reference please share I'm new to this
can I use this concept for XAMPP SERVER
i don't know XAMPP
I have csv file and I try to insert a data from csv file using python
There is only one placeholder %s for all datatypes (mysql connector).
for float,int also we can use %s may I know its correct
Yes, only use %s
ok thank you
But I got Error While Connecting to sql 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO PatientData(DIAGNOSIS_AGE,SEX,ETHNICITY_CATEGORY,HISTOLOGY,ADJUVA...'
INSERT INTO PatientData(DIAGNOSIS_AGE,SEX,ETHNICITY_CATEGORY,HISTOLOGY,ADJUVANT_TREATMENT,ECOG_PERFORMANCE_STATUS,SMOKING_HISTORY,SMOKING_HISTORY_PACK_YEAR_VALUE,RELAPSE_FREE_STATUS,RELAPSE_FREE_STATUS_MONTHS,UBIQUITOUS_ASSAY_PANEL,PERCENT_NECROSIS,TUMOR_VOLUME_CM3,TUMOR_STAGE,POSITRON_EMISSION,cFDNA_INPUT_NG,LYMPH_NODE_INVOLVEMENT,KI67_PERCENTAGE,CT_SLICE_SPACING,PATIENT_ID) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
is this syntax is right
@grim vault let me know
Looks ok to me.
how do I select the bottom row in an sqlite3 table?
define "bottom"
rows are not inherently ordered
Ignoring exception in command topxp:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 164, in topxp_command
abc.execute("SELECT xp,client_id FROM exp WHERE guild_id = %s ORDER BY desc",(ctx.guild.id,))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 568, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\connection.py", line 846, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\connection.py", line 656, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc' at line 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc' at line 1
help
Why so many %s?
20% of a thing named s?
You have 20 columns which needs 20 values. Using 20 %s is correct.
You need soemthing to order (eg a columnname) ... ORDER BY xp DESC
oh
hey
top2 = allten[1][0]
top2id = allten[1][1]
top2name = await client.fetch_user(top2id)
if not top2:
b = None
else:
b = f"**#2 - {top2name} - {top2}***"
i set if top2 is None then b is None
but it said the top2 is None and didn't set the b is None
Ignoring exception in command topxp:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 170, in topxp_command
top2 = allten[1][0]
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Program Files\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range
``` the issue
This:
top2 = allten[1][0]
IndexError: list index out of range```
is the issue. either `allten[1]` or `allten[1][0]` does not exist. It has nothing to do with the if.
so how can i do like if the top2 varible is None then it will do nothing and if it exists then it will set b = "a"??
You'll need a top2 first because allten[1][0] doesn't exist.
can u make an example with my code??
I don't know what allten is, so no I can't.
oh
abc = userleveldb.cursor()
abc.execute("SELECT xp,client_id FROM exp WHERE guild_id = %s ORDER BY xp DESC",(ctx.guild.id,))
allten = abc.fetchall()
here
if len(allten) > 1:
# now index 1 does exist
top2 = allten[1][0]
top2id = allten[1][1]
top2name = await client.fetch_user(top2id)
b = f"**#2 - {top2name} - {top2}***"
else:
b = None
But maybe you want to loop over allten
ok
something like:
top_list = []
for idx, row in enumerate(allten, 1):
name = await client.fetch_user(row[1])
top_list.append(f"**#{idx} - {name} - {row[0]}**")
if idx == 3:
# I only want the first three
break
or so
oh ok thanks
instead of a is None but it print None , how can i set a so it will print nothing??
You still want to print with no output? If yes you need to set a to an empty string "" instead of None.
I'm just the one with time right now, but thanks.
can i use range instead of enumerate ??
If you want, of course.
i need help
Go ahead and ask
I am trying to specify my column name for my SELECT statement through a variable..
sql = "SELECT ? FROM Quests WHERE DiscordID = ? and ActiveQuest = ?;"
cursor = conn.execute(sql, (rest, ctx.author.id, value))
data = cursor.fetchone()
conn.close()
```Doing it this way will literally select the string `rest` and return that back, which makes sense. It's like doing " SELECT 1 ", it'll return back 1 if record found.
I realized I can do `sql = "SELECT " + rest + " FROM Quests WHERE DiscordID = ? and ActiveQuest = ?;"` and it works, but I was told it's bad programming practice using variables directly in the string..
Anyone know how I can do this?
You cannot use ? with columns no. Where do you get rest from?
rest is just a string set between a few if statements and passed into the function for the sql statements
So the thing is, it is okay if you know it can be trusted
If this is your string that you picked then it is okay, but you should never use a string you got from a user (like through input or a Discord command) without heavy validation
ah yea lol
none of my sql statements take in any actual user input
thanks!
Hmm, my code started randomly saying "parameters are of unsupported type" for my conn.execute statement?
sql = """INSERT INTO Economy(DiscordID)
VALUES (?);"""
conn.execute(sql, user.id)
```Edit - Oh... so I changed it to `conn.execute(sql, str(user.id))` and it says "Incorrect number of bindings supplied. The current statement uses 1, and there are 18 supplied."
conn.execute(sql, (user.id,))
hm, ill try that.
what's that extra comma for :p
The second argument must be a iterable, I guess your string is 18 chars long.
To get a tuple.
conn.execute(sql, [user.id]) will also work.
The get a tuple with an single entry you need the comma.
ahh.. i keep brainfarting.
yea, that's exactly how i do it for my other functions lmfao
ah ok, thanks for the help!
Can you pass expressions as parameterized queries with asyncpg?
oh my god it works thanks
Hi, I am currently doing a project in predicting Collective Variables for studying Molecular Dynamics using Deep Learning. If possible, I would like to check models using some datasets already available online. I need multiple trajectories of a single system(like a simple protein) with the same conditions. If anybody could provide me some resources, it would be really helpful.
maybe try channel data-science-and-ai
Sure! Thanks
Hey can someone help me writing a query ?
!paste
the portion i dont know to do is a subquery
(select sum(debit) from account_move where account_move.id =aml.id and aat.type 'income' ) as untaxted)```
i have never written one before.
Just change the last ) to a ; and it might just work?
Trying to get used to using sql. I have this problem where Im supposed to calculate retention rate for users that paid the previous month and current month. But Im having a hard time figuring out how to go about doing this
Any pointers?
How do you define retention rate? And how is the data structured?
So the columns I have right now are payment_id, account_id, account_created_at, receipt_created_at, receipt_expires_at, transaction_number and trial_period_flag
-trial_period_flag is a boolean column that indicates whether the user is in the trial period or not.
-a retained user is someone who paid both the previous month and current month
-so im assuming retention rate month over month would be users who paid previous month and current month divided by total users for that month
-have to calculate month over month retention rate for users not in the trial period
-also using postgres
select date_trunc('month', receipt_created_at)::date as month_year, count(*) as total
from scan_table sc_total
group by 1
This is what I have so far, but this just returns total user month over month that are no longer in the trial period
hello
am trying to get into government bootcamp , and i got stuck in two question about machine learning models , any one can offer a help pls
Hm. That's a lot to do all in sql, maybe you can get ideas from this (unanswered) question: https://stackoverflow.com/q/37521045
Yeah it would've been so much easier in python lol
Is this an assignment of some kind
Yeahhh, Im taking a bootcamp to be a data engineer and this is the sql portion of the assignment. Complex sql stufff doesn't click with me like python does so this part is hard to figure out
same same lol
Sooo I think the biggest thing Im having trouble with is figuring out is
-trying to figure out who paid current month and previous month to determine a retained user
Like should I just count if user paid 30 days after the receipt_expire_date?
Hey everyone - I recently started learning postgres recently and right now I'm trying the DELETE statement, only problem is it literally won't delete
My SQL is DELETE FROM tasks WHERE title='test'
when i run from any the postgres console it works
from anywhere else just a nope
My rls policy:
create policy "Tasks are deletable by task manager."
ON tasks
for delete using (
auth.role() = 'taskmanager'
);```
and I ran GRANT taskmanager DELETE on tasks
running the same query with select returns the expected value
a single row
i've tried writing it in pg-node for nodejs and psycopg2 for python
neither work
code
cursor = conn.cursor()
cursor.execute("DELETE FROM tasks WHERE \"title\"='test' RETURNING *")
conn.commit()
print(cursor.fetchall())
cursor.close()
conn.close()```
i left out the connection part for obvious reasons
when i turn off rls it works

is this on supabase?
Yup
I believe auth.role() returns either authenticated or anon in most cases then right? are you sure you've got the right field there?
It works for other stuff

I just removed the policy
And replaced it with granting permissions
Alright
But it still doens't want to work
what does the error say?
I asked in the supabase server, and that's not supposed to work apparently; where do you define this taskmanager role for users?
CREATE ROLE ___
seemed like it worked before but is was probably the lot of grants lol
ah yeah that's not the role that's returned by auth.role()
auth.role() is set by supabase itself, and is assigned for every user that has signed up through it's authentication system
and you've connected to the db using this role itself?
dbname = "postgres",
port = "5432",
user = "taskmanager",
host = "db.supabaseidthingy.supabase.co",
password = "password"```
@burnt turret
honestly, yeah. anything else is probably overthinking it
But then don't I need to somehow tell if next receipt created date is after the current receipt_expiration_date? Also the same user is listed multiple times
that looks right, can you show your GRANTs as well?
i don't want to reveal too much because this is an assignment, but you probably need to join the table to itself
GRANT SELECT, INSERT, UPDATE, DELETE ON tasks TO taskmanager;
that looks right to me 🤔 if it was a lack of permissions for the role I think it should've raised an error there (but don't quote me on that) i've got something else to do rn, but I'll try looking into it again in a bit if the issue isn't solved
Thanks!
Been at it since Friday and haven't made any progress. I think just figuring out how to think about going about this is difficult for me. Its due tomorrow.
-So right now I have one table that counts all the users, is grouped by receipt_created_at where trial_period is 'false'
-So should I create another table that counts the users that has the next created_receipt_date within 30 days after the current receipt_expired_date?
Hello its possible use MySQL server for create database in a server and connect with mobil app ?
ended up solving it by ditching rls for grant and revoke
lol alright 👌
I am using myphpadmin for MySql, Here's the code:
query = """
SELECT
EXISTS(
SELECT 1
FROM RequestItem
WHERE RequestItemId = %s AND DeliverAfter < %s
LIMIT 1
);
"""
time_now = datetime.datetime.now()
values = (request_item_id, time_now)
db_cursor.execute(query, values)
result = db_cursor.fetchall()[0][0]
if result == 1:
return True
elif result == 0:
return False```
My question is:
in `datetime.datetime.now()` I can do something like `datetime.datetime.now(pytz.timezone('US/Pacific'))` to get the datetime of a specific time zone. But say my server is not in the same timezone. How will the date time be compared? Based on the server datetime or the machine I'm on?
please mention me in your response, thanks 😄
It's probably not the best idea but it's easier so 😅
yeah lol
And what I would be doing with RLS can be more easily done with GRANT + REVOKE
you don't need to make 2 tables, but you will probably need a subquery
sqlite tables shouldn't be treated as "ordered". however you can select the row with the largest id value
how?
SELECT *
FROM mytable
ORDER BY id DESC
LIMIT 1
try:
while True:
cur.execute(f'SELECT User, Language FROM {tb_n} ORDER BY id DESC LIMIT 1')
row = cur.fetchone()
print(list(row))```
it spams on for infinity because of the while loop
but the limiter should limit it, correct?
no?
the limit just limits the number of rows in the query
if you are making the same query in an infinite loop then the database will just keep re-running the query
computers are less magical than you think
if you tell your program to loop, it will loop
this is what I have so far. I believe this is giving me how many purchases were made each month being grouped by account_id and payment_id. But you mentioned a subquery, so I shouldn't use a join right?
select sk_ret.account_id, sk_ret.payment_id, date_trunc('month', sk_ret.receipt_created_at)::date as month, count(*)
from skann_table sk_ret
inner join (select account_id, payment_id
from skann_table sk_2
group by 1, 2)
sk_2 on sk_2.account_id = sk_ret.account_id
where trial_period_flag = 'false'
group by 1,2
you are joining with a subquery here, that's fine. you are maybe thinking of "correlated subqueries". also why are you using column numbers for grouping here? i don't think it's good style unless it's necessary (i.e. because the column is computed and not just a name)
only groupipng by account_id, and payment_id so the relationship between the two joined tables are 1 to 1. Though Im pretty confused on this. I didn't think this would feel so complicated lol. So should the subquery be total users by month or users retention count by month? I think Im just confused on how to solve this step by step to get the right solution.
ultimately you need something like this, right?
user_id | month | was_member_last_month | is_member_this_month
i think you're overthinking it
So this is the prompt.
A retained user is someone who paid both previous month, and current month. Using SQL calculate month over month retention rate for users who are no longer in the trail period
-I was thinking the output would look more like
month_year | number_of_retention_users_per_month | total_users_per_month | retention_rate
so are there just 2 months here?
it's kind of a vague prompt
i was not suggesting a final output, i was suggesting an intermediate structure from which you can easily derive the final output
I think about 6 distinct months
6 distinct months i believe
ahh okay. But yeah I mean thats the prompt. I know how to do this in python but have no idea how to go about getting to this in sql. Soo I originally started with my first query as
select account_id, payment_id, receipt_created_at, count(*) as total_users
from skann_table skt
where no_trail_flag = 'false'
should I have started this another way?
hard to say how exactly you should have started... it's maybe better to work backwards from your goal
you rightly identified that receipt_created_at can be used as a proxy for the most recent month in which a user was subscribed
ok, so now you can build up into
account_id | receipt_month
and then you can self-join WHERE t_curr.receipt_month = t_prev.receipt_month + 1
which is more or less the crux of the stackoverflow post i sent
and from there you just have to group by "current month" and count the number of users who were a member in both months
you can do joins in where clauses?
FROM a
INNER JOIN b
ON a.x = b.y
is syntactic sugar for
FROM a, b
WHERE
a.x = b.y
but you can of course use JOIN syntax for this too
imo you don't really understand joins until you understand why those two queries are semantically equivalent
So you're basically just doing the join in the from clause for the second one using the where clause as the joins
yes
But if its possible to do this without joins, I'd like to try that way.
i don't think it is, nor do i see why you would want to avoid joins
thought it would be easier but if its not possible then okay
so is this giving me user retention by month?
select sk_curr.receipt_created_at, count(*) as total_users
from skann sk_curr
inner join (select receipt_created_at
from skann sk_prev
group by 1
) sk_prev on sk_curr.receipt_created_at = sk_prev.receipt_created_at + 1
group by 1
not unless receipt_created_at is a month?
Sooo thats where I'd be extracting month and year from.
But when I try using `date_trunc('month', receipt_created_at)::date as month. I get an error. But when i run it like this I get something back
what error? what did you try?
you might want to "pre-compute" that with yet another subquery or a CTE
you could probably also do this with lateral if you wanted to be really slick
nvm it ran and returned the number of users by month. So when I add these numbers up they equal the total number of users who aren't in the trial period. Sooo just to reiterate and be clear
sk_prev on sk_curr.receipt_created_at = sk_prev.receipt_created_at + 1
is self-joining the two tables based on current/previous users for that given month?
-when i first started looking at this I thought I would've had to do something like lead(receipt_created_date) - receipt_expired_date < 31 31 being the number of days in between.
really?
depends on how you define a "month". the important part is the self join
so how do I get total users for that month?
at this point i think you're asking questions that you should know the answer to, if you're applying to a data engineering role
not a role, a bootcamp assignment. but thanks! Ill try to figure out the rest
ah, i misunderstood. but yes, i think you have all the tools you need at this point
(hint: don't forget about count(*) ...)
Is PostgreSQL pretty much the industry standard when it comes to data bases out in the wild?
Not "the" but "one of"
I think it's common in small projects nowadays
Any big differences between MySQL and Postgres?
Not that big, they support different sets of extensions
Postgres has a nicer collection of data types and a lot more functions
(imo)
with pymongo.update_one(original_dict,new_value)
can i just call the dict object for the first param. ? jw cuz if i print the dict object it wont return a dict even tho it is one i theory
create database Man ;
Name varchar(20),
Height int ,
Weight int ,
Salary int
) ;
insert into Abilities (Name,Height,Weight,Salary)
values
('Aniket',5,72,10000),
('Karan',6,78,20000),
('Aakash',5,58,15000),
('Divesh',5,55,288000)
select * from Abilites;```
i'm getting error on this
Abilities != Abilites
Also missing the ; before the select (or after the insert).
Hello anyone know how SQL data convert json file using python
@grim vault please check if let me know
don't ping random people
You want to convert a JSON file to a SQL database?
No I want convert a SQL database to Json file
is there any reason for you to want to do that?..
you can read from it then convert each row to a dictionary in a json array, but usually converting structured data (sql, csv) to unstructured or semi-structured (nosql, json, xml) does not makes much sense
Ok
sqlalchemy question:
What is the way to store datetime.timedelta objects?
Hi guys
have you ever seen this error in DBeaver
SQL Error [16777232]: Query failed (#20211004_115307_00151_s2r9w): Error reading tail from s3://some-bucket/folder/folder/part-00010-0287d64b-292f-428e-9da5-10e61bd353c1-c000.snappy.parquet with length 16384
I have delta table in S3
Hi, I have these Object types and Object table. ```sql
CREATE OR REPLACE TYPE Student_T AS OBJECT
(Name VARCHAR2(30),
Phone INTEGER,
Course VARCHAR2(30))
NOT FINAL;
CREATE OR REPLACE TYPE PostGrad_T UNDER Student_T
(ResearchGrantAmount_T INTEGER,
ResearchArea VARCHAR2(30))
NOT FINAL;
CREATE OR REPLACE TYPE Undergrad UNDER Student_T
(Academicyear NUMBER,
status VARCHAR(5))
NOT FINAL;
CREATE TABLE COLLEGE_STUDENTS OF STUDENT_T; ```
I'm having issues understanding inheritance in terms of inserting rows.
I need to insert a row for both PostGrad_T and Undergrad but I'm not sure how, could someone help or show an example of how it should be done?
what database supports this?
i don't know the answer but i'm pretty good at finding things in documentation
I'm using oracle apex
it looks like you can insert instances of Undergrad_T into that COLLEGE_STUDENTS table
Oracle Help Center
Anyone have any experience with peewee?
I can't insert a string into my database, as it simply does nothing
looks like that was solved
Quick question
In postgres I'm trying to use RLS to check if something a user is submitting in a query matches something in my db.
Got the from db part done now just need to know how to get one of the insert values out
any1 know how to do this?
Are you asking how to make a SELECT statement
basically how do I check if an object IN an array which is IN a document exists?
for ex, this is my collection
now you see, inv here is an array
I want to check wether a specific item exists in the array.
For example, if lock exists, return True and how much exists.
you need to check the values that are going to be inserted?
you'll need to use WITH CHECK in the RLS policy then (instead of USING)
so im going to add a database to my discord bot, and because i didnt find any solution for accessing the db like mongo, i'll be transferring the db files between both my pc's when i want to work on them. my question is, how big does the file get? because if it gets as big as a few GB's, that'll be a problem for me
i dont think it will be that big(but depends a lot on the sample size)
oh ok
r u using django for accessing the db
no
u should use django tho it has some problems with windows
i'll look into that
django makes database managament a lot easier
im making my personal website using django
im not making a website actually
ik
im making a discord bot
but django is still great for databases
i'll check that out
Hello can someone help me with a sql query i'm trying to join two tables and one of the columns is a sum value.
Because the values are repeated from the second table the sum is wrong.
how do i correct this ?
what is the best way to convert a sqlite output from a single row to a vertical list, and also remove any symbols? I just want the straight text
I used to export the results of query as csv before but that was in postgres
ah ok, at this point I'm able to get the output of a column into a row, but i need it to be a vertical list for a discord bot I'm making
are you trying to do a find query? it looks like inv is not an array, but an object
@wary spire but if you do have an array, you can treat the array as if it were a single field, as in https://stackoverflow.com/a/18148872/2954547, or use $elemMatch https://docs.mongodb.com/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch
Show your code?
i tried these but aint working
i went simple
def check_for_item(user, item):
d = db.collection.find_one({"uid": int(user.id)})
try:
if d["inv"][item] >= 1:
return True
except:
return False```
i did this
def check_for_item(user, item):
result = collection.find_one({
"uid": int(user.id),
f"inv.{item}": {"$gte": 1},
})
return result is not None
like that maybe?
no i had to do try except
cos some errors were coming up
and the way i did is working perfectly
except: is almost always a bad idea
it catches too many things
what were the errors?
i assume you were trying to catch KeyError
def check_for_item(user, item):
d = db.collection.find_one({"uid": int(user.id)})
return d.get("inv", {}).get(item, 0) >= 1:
def check_for_item(user, item):
d = db.collection.find_one({"uid": int(user.id)})
try:
return d["inv"][item]
except KeyError:
return False
note that in your code, you return None if the item exists but is 0
Hi, I need to create a "List of Values", inside the dictionary key - "Phone". so that whatever the input the users give, I can append to the already created JSON file, instead of overwriting it. Any help?
Hi, I need to create a "List of Values", inside the dictionary key - "Phone". so that whatever the input the users give, I can append to the already created JSON file, instead of overwriting it. Any help?
Hi, I need to create a "List of Values", inside the dictionary key - "Phone". so that whatever the input the users give, I can append to the already created JSON file, instead of overwriting it. Any help?
def CreateJson(data):
with open("Databasemgmt/thanos.json", 'w') as f:
json.dump(data, f, indent=2)
data_var = {}
data_var['name'] = input("Enter your name: ").lower()
data_var['age'] = input("Enter your age: ").lower()
data_var['phone'] = []
data_var['phone'].append() = input("Enter your phone: ").lower()
data_var['address'] = input("Enter your address: ").lower()
data_var['id'] = {}
data_var['pass'] = {}
so that whatever the input the users give, I can append to the already created JSON file, instead of overwriting it.
you can't modify json data in place. you must modify it in memory and overwrite the file. this is inherent in the design of modern filesystems in general and json in particular
if you need to modify data in-place, consider using a database
as they say, "json is not a database"
Which is why, I'm creating a "list" object for phone number, so that later on, any new entries made can be appended to that list, thereby retaining the existing data and also adding the new one at the same time..
This could be a work-around right?
no, it doesn't work like that in json
you can make a list in python, sure
but you can't make a json array and just expect it to magically work
I'm working on a Goodreads-esque book tracking platform, but having some trouble wrapping my head around how to structure the PostgreSQL database I'm connecting to with Flask
What I'm hoping to achieve is something like the below image.
- many-to-many relationship between books and users; one book can have many readers; one reader can have many books
- many to one relationship between categories and users; one user can have many categories they shelve their books in
- many to many relationship between categories and books; one book can be in multiple categories; one category can have multiple books
However, this is made even more complicated by the fact that a category can be set to 'ordered', so the order of the books displayed can be set. With this constraint, I'm at a loss at how to structure the DB. Any suggestions?
So far I have user and book models, which are connected to each other through a many-to-many helper model (which also serves to keep track of the users library). I'm confident on connecting the users to the categories, but not sure about how to proceed afterwards. Make another helper table to connect categories and books? And how will the order be set, where a book can have multiple 'current_order' fields based off the category?
can someone help me connect my mongo database
what and the fuck
is that
i think another many-to-many table of books and categories makes sense like this:
create table m2m_book_category (
category_id integer,
book_id integer,
book_order_in_category integer default null,
primary key (category_id, book_id)
)
and a many-to-many table of users and books:
create table m2m_user_book (
user_id integer,
book_id integer,
primary key (user_id, book_id)
)
that's their diagram of their database system
what have you tried so far?
i need help with the connection
i'm willing to let you have the thing
if you can help
i'm not interested in "the thing"
the database connection url
i suggest reading the pymongo or motor documentation
i'm not interested in the database connection url, and nobody else here is either
probably, mistakes happen. that's why i asked what you already tried
!paste post your code, use this site 👇
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
you can/should remove any "real" information: your name, database credentials, passwords, etc.
Thanks for the suggestion, I'll take a stab at doing it this way. Was just a bit worried that it would be redundant to have both a category and categoryassociation.
meh! if you don't have any category "metadata" then you can just omit the category model entirely, although i imagine you'd at least have a name or something
yes, I do have a name, description, and then private/public boolean. So will probably just keep them both like this
hey am new to databases is sqlite3 a good place to start ?
am trying to do a password manager
I was using with check still didn’t work. Got help from a Supabase dev, idk why they helped me but they were very helpful lol
yes
this is my query
(
SELECT
raw_user_meta_data->>'provider_id'
from
auth.users
WHERE
id = auth.uid()
) = new."DiscordID";
rls query
new."DiscordID" is supposed to grab what the user is trying to insert
I get Error adding policy: syntax error at or near ">"
because it auto corrects to - > >
this just isn't working
solved part of the problem
SOLVED!
JSON accepts lists too... :/
it did work anyways.
you still have to overwrite the entire json file
once you load the data into python there's no such thing as "json" anymore
Yeah, that's the same in any case right.
it's all lists, dicts, numbers, strings
right. that's what i was trying to emphasize
Yep. Yep. got that.
Ah! Okay.
my bad. was out of my head last night, after all of those things and the code not working 😅
Many suggested me to use SQL, with python.... as DB instead of JSON, any suggestions on this?
I don't really have a big data structure, I just want to save personal informations of people, which would be their basic info and their digital IDs, etc....
If i use SQL, is it necessary for me to have mySQL installed in the PC? like I'm not sure, but JSON works anywhere without any pre-requirements right? how about SQL?
Any other DB suggestions?
sqlite is a sql library that doesn't require you to install any software
it's a single file that you can interact with by importing the sqlite3 module that is included with python
!d sqlite3
Source code: Lib/sqlite3/
SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.
The sqlite3 module was written by Gerhard Häring. It provides a SQL interface compliant with the DB-API 2.0 specification described by PEP 249, and requires SQLite 3.7.15 or newer.
however you can also use a graphical program to interact with it, e.g. https://sqlitebrowser.org/
and yes, if you need to frequently modify or query small sections of the data, a database is a good choice
json is good for when you need to save or load data at the start or end of an application, e.g. a config file, or for sending pieces of data between programs or machines
Oh.. okay
Thanks. I'll study about SQL first then... and understand it.
With SQLite3, is it better practice to have a single db/cursor variable and use that in all of my code, or to open a DB/cursor, do stuff, close it each time? It's for a Discord bot, and there's quite a lot of calls at this point.
CASE
WHEN ap.payment_type = 'inbound' THEN aml.credit
WHEN ap.payment_type = 'outbound' THEN aml.debit
END AS amount,
CASE
WHEN ap.payment_type = 'inbound' THEN aml.second_credit
WHEN ap.payment_type = 'outbound' THEN aml.second_debit
END AS second_amt,
CASE
WHEN ap.payment_type = 'inbound' THEN aml.third_credit
WHEN ap.payment_type = 'outbound' THEN aml.third_debit
END AS third_amt```
is there a better way to write this part without repetition
its part of a sql query
Two selects joined with an union all and the condition in the where?
Or if there are only two options use the else to get rid of one repetition.
sometimes sql is just really verbose
I was wondering if anyone could enlighten me as to what this command means, or does exactly: sqlite3 database.db < schema.sql. I am using a SQLite database in Python, in a Flask app. I followed a tutorial and had to use that command, but when I tried to alter the schema.sql code to fit my project, everything failed. So I want to understand more about this. The documentation is not helpful.
I understand that it's piping the schema.sql file into the sqlite3 command's input, but I don't know what that means really.
sqlite3 can read sql commands/queries from stdin. so schema.sql should be a text file containing various CREATE TABLE, INSERT, etc. commands, and sqlite will run them one at a a time. < is typical unix shell syntax for redirecting standard input from a file
Okay, thanks. I will come back at a later date because my next question is going to be able the structure of the schema.sql file, because obviously something's not working in the schema.sql file I wrote.
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
and show us what error(s) you get
Here is the code.. I will have to come back later for the error(s) because this is something I worked on a year ago.. so I will have to go back into the project and follow the 34 minute tutorial a second time.. to get the code running them make my modifications to reproduce the error.. https://paste.pythondiscord.com/xabopexuze.sql
that looks valid to me
I'm just trying to create a table called refcards that has an id and two text fields. Yeah well I will come back with the actual error. Maybe it wasn't because of the schema.sql file and something else in my models.py file..
I'll probably have to ask the question in web-development because now it's going to become a question about my app.py and models.py files in a Flask app. Thanks for the input anyway.
good luck
mysql> create table userprefix(client_id bigint not null primary key, username TEXT not null, prefix TEXT not null default !);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '!)' at line 1
what wrong
Thanks. 🙂
.
mysql apparently doesn't like the !
so how can i fix it? i mean in the type of column prefix
what's the ! supposed to mean?
str
who told you that? i haven't used mysql in years, but i don't remember that ever being valid syntax
is it in the docs?
i searched for it and it said the TEXT type is for str
yes, of course. i am asking about !
why is that there? the ! is the cause of the error
ok
oh ok thanks
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\luffy\Desktop\All Things\Code File\Python\Discord.py\MineHardcore.py", line 164, in on_message
abc.execute("INSERT INTO exp VALUES(%s,%s,%s)",(message.author.id,message.author,"!"))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 556, in execute
psub = _ParamSubstitutor(self._process_params(params))
File "C:\Users\luffy\AppData\Roaming\Python\Python39\site-packages\mysql\connector\cursor.py", line 435, in _process_params
raise errors.ProgrammingError(
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'member' cannot be converted to a MySQL type
what wrong
Python 'member' cannot be converted to a MySQL type
that's what
import mysql.connector
class databases(object):
def __init__(self,password,database):
self.database = database
self.password = password
self.con = mysql.connector.connect(host="localhost",user="test",password=password,database=database)
self.curse = self.con.cursor()```
tried to make this a module and import it into another file but it wont work
any idea why?
Import how? Won't work how? Check your file paths and __init__.py
this probably isn't a databases question. show your file layout
cluster = MongoClient("my mongo link")
database = cluster["Feature"]
``` is returning ```database = cluster["Feature"]
TypeError: string indices must be integers```
that isn't what's in your screenshot, cluster = ("...) looks like it's a string wrapped in parentheses
line 6
when trying to update a mongo value i get
pydiscord.ext.commands.errors.CommandInvokeError: Command raised an exception: WriteError: Cannot apply $addToSet to non-array field. Field named 'response' has non-array type string, full error: {'index': 0, 'code': 2, 'errmsg': "Cannot apply $addToSet to non-array field. Field named 'response' has non-array type string"}
on
newdict = {'$addToSet':{"response":response}}
col.update_one(find,newdict)
nothing in the docs stating about labelling it as a list when inserting, before updating so
already a value in response for there to add to
using mongodb, how do i find a document and then add on to it?
I'm having a hard time inserting a timestamp into my table, in a SQLite3 database in Python, in my schema.sql file. I've tried every possibility I could find on-line and it's not working. I got it to work for 5 seconds, but then it broke again. How do I write it in the create table expression, the way I write id integer primary key autoincrement??? I think I've got the rest of the code working. Or maybe it's some browser cache thing in Chrome, I don't know. I'm writing a Flask app. Thanks in advance.
there is no native datetime/timestamp column in sqlite. you have to either use text and pick a standard format, or use numbers and use epoch seconds
I was able to get it to work with this:
created_at DATETIME DEFAULT (STRFTIME('%d-%m-%Y %H:%M:%S', 'NOW','localtime'))
ah yeah. note that those are really going to be strings
you can register "converters" and "adapters" in the python sqlite3 library to automatically convert
That's what I want, though, strings.
I'm just using it to put a timestamp at the top of a note in a notepad...
I should have specified that.
yeah, should be fine then
I really had to work hard to get at this solution. I tried every possibility I could find. Nothing worked until poof it finally worked. I don't really know what I'm doing in SQLite.. Someone suggested I practice using it, so that's what I've been trying to do, but boy is the documentation lacking, in my view. I guess it's probably because I was looking for a nonexistent function... lol
yeah, sqlite has okay "reference" docs, but for getting started you will want to follow some more general sql things
however there is https://sqlbolt.com
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
sqlite also has some quirks compared to other databases, especially:
- column data types are "recommendations", not strict checks
- many fewer data types
Thanks. I will check this out. 🙂
Hello All, I am looging for a python 3 package to connect sql server. My script runs on a Redhat machine. So I am not sure which library should I use. It would be if I get advise
$ sqlite3
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .mode table
sqlite> drop table if exists test;
sqlite> create table test (
...> id integer primary key,
...> created_at_d default current_date,
...> created_at_t default current_time,
...> created_at_ts default current_timestamp
...> );
sqlite> insert into test(id) values (1), (2), (3);
sqlite> select * from test;
+----+--------------+--------------+---------------------+
| id | created_at_d | created_at_t | created_at_ts |
+----+--------------+--------------+---------------------+
| 1 | 2021-10-07 | 06:48:44 | 2021-10-07 06:48:44 |
| 2 | 2021-10-07 | 06:48:44 | 2021-10-07 06:48:44 |
| 3 | 2021-10-07 | 06:48:44 | 2021-10-07 06:48:44 |
+----+--------------+--------------+---------------------+
sqlite> ```
I would suggest using UTC as timezone not localtime. It should be easy to convert for display purpose. And if using '%Y-%m-%d %H:%M:%S' as format you can use the column for an chronologic order by.
i wanna db with a ui run on 32 bit os
I thought I tried created_at default current_timestamp and it didn't work. I'll try again. Thanks.
I tried
created_at default current_timestamp
but it gave me a time 4 hours off... for some reason, 4 hours later than the actual current time where I live.
Yes, that's because it's UTC.
Hello, i have some memory leak issue with mariadb
import mariadb
class Maria:
def first_mariadb_connect_and_basics(
self, host_=config.db_host
):
# Simple connect to mariadb server
self.conn = mariadb.connect(
user=config.db_user,
password=config.db_passwd,
host=host_,
port=config.db_port,
)
....
while True:
maria = Maria()
items = maria.first_mariadb_connect_and_basics(
"test", "items", config.db_host
)
....
maria.conn.close()
Anyone have a idea please ?
Same issue with only connect and close while, and tracemalloc detect memory issue on mariadb.connect
Here log from tracemalloc after 1min of load
i never have a issue with that before, but now my script need to be load permanently, i reach out of memory after some hour
Hello, I have some code that looks like this:
async def my_method(session: AsyncEngine) -> None:
async with session.connect() as conn:
query = select(class_a, class_b) \
.join(class_b)
result = await conn \
.stream(query)
result = await result.all()
This returns me a list of primitives instead of a list of (class_a, class_b), is there some way to change that?
what's AsyncEngine?
but in general, the answer is to use something like marshmallow, cattrs, or pydantic to do the "deserializing" from "raw data" to "objects"
im using the async version of sqlalchemy and the thing is that in queries where i have no joins (so i return one table) the conversion is done automatically
so I am assuming that there is a way to tell sqlalchemy hello the output is a tuple of these 2 classes and not a list of strings
async engine is from sqlalchemy.ext.asyncio, its the async version of the normal sync engine
ah, that i'm not sure




