#databases
1 messages · Page 194 of 1
async def prefix(bot, message):
return prefix
I'd actually make a cache tbh to store prefixes
yeah.. good luck teaching him how to use redis
I actually want to ask what's use of bot argument in it?
sheesh
¯_(ツ)_/¯
prefix()()()()()()()()()()()()()()()()()()()()()()()()
..?
since it returns itself
Can you tell what's use of bot in it?
Hey can you tell whats use of bot argument in it?
async def prefix(bot, message):
I don't know, Ash did that 😄
Who will help me now
bot is an instance of a Bot object fyi
just looked at the source code
you don't use the bot param though, is what he's asking afaik
async def get_prefix(bot, message):
id = message.guild.id
Is it correct?
And i can select the prefix thing
And return prefix
Easy
Sqlite is very easy pesy
ahem you'll be still doing bad practices
Whats wrong now?
Is my strategy wrong?
yes
you should create a custom cache, in the sense, a simple dict
which you should load with prefixes on startup
Whats use of dictionary in it?
I am using database
you'll make a sql query every time a message is sent, instead selecting prefixes from a dictionary is better and if the prefix is not found in the dictionary, simply make a request ton your database
But i never did the dictionary thing before
this is more of a #discord-bots question idk
then do it now?
Idk how to
use brain
But there would be so many prefix to load
My brain said idk
Things in SQL are stored in json format?
no?
😐
how would that work on a list of tuples?
pliz elaborate
Me confused
Json.dumps?
do you even know what they do?
It converts dictionary to json format
.....
Json.loads to load data(don't ask me difference between load and loads)
no?
Anyway come to sql
...
Json not related to #databases
wut when did I ever talk about json
😭
I saying me
pffttt
what is the question?
Me confused
and I just said to make a custom cache, in the sense a simple dictionary that loads all the prefixes on startup to avoid making requests to the database every time
😔
import discord
from discord.ext import commands
import aiosqlite
bot = commands.Bot()
async def my_hook():
bot.conn = await aiosqlite.connect("name.db")
bot.cur = await bot.conn.cursor(){}
await bot.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT,guild_id INTEGER)')
await bot.conn.commit()
bot.setup_hook = my_hook
Is it correct yet?
Idk how to make
Let me google with my small keyboard
it'll raise errors
class Bot(commands.Bot):
def __init__(...):
prefixes = self.get_prefixes()
...
super().__init__(..., command_prefix=prefixes)
def get_prefixes(self):
query to get prefix
😵
with sqlite
Headache
move to #discord-bots I'll write a mere example
it isn't tho
what's the other option?
it's still cleaner tbh
https://mystb.in/InvolvementMinimizeAlternatively.python
this is a simple example of how I would implement custom prefixes
it is indeed cleaner
simple one for beginners
Can I use it if you have no problem
dudie, we were talking about aiosqlite
yes. but dont ask here if you get errors
Hmmm
i see no reason why u cannot do that with aiosqlite too
What would I do if i got error huh
still
eh nvm
solve it yourself
whatever you say u are helping anyway
we could switch 👀
Then what's this server for.....
I could solve if possible
lmao
it's for u to display ur problem and wait
Ye not for circus
till someone in a good mood comes and helps you
no me
Why everything red here.
imagine
that's a really dumb question 😐 pass in self to the hook
You mean bot setup hook?
yes?
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook() -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
def get_prefix(self, bot, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot
bot.set_hook = setup_hook
@bot.event
async def on_ready():
print("hello")
Like this?
rip
...
I'm really gonna cry, I'm out for now
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook(self) -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
def get_prefix(self, bot, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot()
@bot.event
async def on_ready():
print("hello")
i just added the self over there no way i am reading all that
Still red
Which line
set_hook
bot = MyBot()
bot.setup_hook =
i dont think u need setup_hook
Oh u understand
yeah
I understood
Yes I understand
just MyBot() is enough
I'm on the verge to cry
remove that
^
Hey @fringe sundial! I noticed you posted a seemingly valid Discord API token in your message and have removed your message. This means that your token has been compromised. Please change your token immediately at: https://discordapp.com/developers/applications/me
Feel free to re-post it with the token removed. If you believe this was a mistake, please let us know!
bro scroll up and see
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook(self) -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
def get_prefix(self, bot, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot
@bot.event
async def on_ready():
print("hello")
Now?
call the MyBot class
Ok
f bro guy didnt even scroll and see
Done
no comments, I'm out, I gotta do some stuff
fr
¯_(ツ)_/¯
finally scrolled up
Ye
🥲
why?
for a sec i thought the bug was real
async def
still 13% left sigh
I'll charge when it would be 2%
How to fix this?
dunno worked for me
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook(self) -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
async def get_prefix(self, bot, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot()
@bot.event
async def on_ready():
print("hello")
@bot.command()
async def test(ctx):
await ctx.send("eat poop")
Here is code
self.get_prefix(message) <-- message object from the guild here
no
Sad song ig
u need the guild id there somehow
#discord-bots again
Imma listen the last ride song
And do coding
SQL confusing
Ig pymongo more easy?
mongo ew
sql is basically english
Mongo?
mongo sucks
its as simple as it gets
But very less tutorials on SQL in Hindi
english-
(self, bot, message) instead try with (self, message)
should i make one👀
Asher go to sleep
Do you even know Hindi language 😂
u are right
bro i am indian
Really?
yes
I want codewithharry to make tutorial on sql
literally half the server is
I am
i wish
And become a doctor
ok bye, have a safe trip
And make my own hospital website
ok good luck
are u still getting error?
Let me grow till 18
13...?
Ye
😭
?
idk
@west hill have you listen the news that sidhu moose wala died before 1 month
Me from his state
guy got something like 20+ bullets pumped in him
ik
Off-topic channel: #ot2-the-original-pubsta
Please read our off-topic etiquette before participating in conversations.
You from which?
Ik 2 mins :(
quite far away from u
absolutely not
for safety karnataka
yes ma'am
SQL
9(
you guys arent even on topic, this is a databases channel not discord bots
Ok
i was helping u help him👀
Tf ma
no
I did wrong indentation in get_orefix 😂
but that will give u indentation error not missing argument
Still error
show code
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook(self) -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
async def get_prefix(self, bot, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot()
@bot.event
async def on_ready():
print("hello")
@bot.command()
async def test(ctx):
await ctx.send("eat poop")
Imagine mods come here and mute us
why not huh?
self, bot here self will act as bot and bot as message and message will an extra argument
async def get_prefix(self, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
he is not doing bot.guild.id
nvm, I'm out
wont work
let him try atleast ¯_(ツ)_/¯
ok sire
whats cur?
^
.
What's wrong
Bye me listen music
import discord
from discord.ext import commands
import aiosqlite
intents = discord.Intents.default()
class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix=self.get_prefix, intents=intents)
self.prefixes = {}
async def setup_hook(self) -> None:
self.conn = await aiosqlite.connect("name.db")
self.cur = await bot.conn.cursor()
await self.cur.execute('CREATE TABLE IF NOT EXISTS pretable(prefix TEXT, guild_id INTEGER)')
await self.conn.commit()
all_prefixes = await (await self.cur.execute("SELECT * FROM pretable")).fetchall()
[self.prefixes.update({record[1]: record[0]}) for record in all_prefixes]
async def on_ready(self) -> None:
print("Bot is online!")
await self.setup_hook()
async def get_prefix(self, message) -> None:
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?"), (message.guild.id)).fetchone() or ">"
bot = MyBot()
@bot.command()
async def test(ctx):
await ctx.send("eat poop")
this should work i forgot to run the setup hook
@fringe sundial
thats a sqlite error
return self.prefixes.get(message.guild.id) or await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?", (message.guild.id))).fetchone() or ">"
now try
i havent used aiosqlit b4 so idk
await (await self.cur.execute("SELECT prefix FROM pretable WHERE guild_id = ?", (message.guild.id))).fetchone()
just remove this line and try
I am sorry but it's giving errors again and again
no i meant remove that line
return self.prefixes.get(message.guild.id) or ">"
just try with this
i am not too sure with the aiosqlite part u would have to wait for others to help
But that will not return prefix?
what error same?
Codewithharry should start a discord.py series :)
^
This error
cant be
Ye
then u didnt remove the sql line?
Oh we forgot that fethone() return tupple
not a problem with that the sql line was giving an error
idk how u got same error after removing the line
can u send the repl link?
Can we do it lator?
when u are free
Or we make our own custom prefix thing? Together pls @west hill
dm drop the repl link when u are free i will see what the error is then👀
Ok
yu add a , (comma) for the parameters to make it a tuple
@fringe sundial ^
welp rip i am gonna stick with postgres
forgot just remembered my SQL needs that too
Hello guys,
I have two tables.
Picker and owner, and they inherit from User.
They have fields in common (the same as user) and at the same time, they have they own fields.
Like in the image:
As long as I know, this is an Is-A relationship
My question is, can I implement this with table inheritance in sqlalchemy? (https://docs.sqlalchemy.org/en/14/orm/inheritance.html))
If i put will it work?
is this common practice in databases? found this in the lab examples for a Google Cloud course I'm taking.
"""
Takes an email address and reverses it (to be used as primary key)
"""
def reverse_email(email):
return '_'.join(list(reversed(email.replace('@','_').
replace('.','_').
split('_'))))
there's a lot of fairly cursed Python in here so I wouldn't be surprised if it's unusual
I think that reversing URIs is not extremely uncommon, but I wouldn't call it particularly common either
that said, my only reference I can remember for that is that Java has imports like ```java
import com.google.gson.JsonObject;
import net.minecraft.data.HashCache;
Yep, sqlalchemy supports inheritance: https://docs.sqlalchemy.org/en/14/orm/inheritance.html
Thanks doctor.
I was doing this API with Sequelize in JavaScript but It does not support It among other stuff that does not support It.
I see that with SQLAlchemy you can do the same as with SQL.
One of the best ORM
Guys, does anybody know how I can do this with sqlalchemy? For me to query a table in sqldeveloper, I need to prefix its owner from the all_tables table. But in python with sqlalchemy either with the owner or without it, it returns the table or view doesn't exist. Any tips ?
I was able to fix it by setting the schema name
can anyone see my normalsd table tell if anything wrong i am not sure what key shouldbe pk or fk
hey guys - really need help with SQLAlchemy events, so I have this:
@event.listens_for(Emails, 'after_update')
def delete_retrieved_email(mapper, connection, target):
# If email row has been retrieved, it has been saved in the client's local storage. We now delete it off the server.
if target.retrieved:
connection.execute(delete(Emails).where(Emails.id == target.id))
When I test this in the python console (update an Emails instance) - it works. When I do the same in a pytest test, it doesn't work! Why could this be? I have been stuck on this all day it's so frustrating!
<@&831776746206265384> scam alert

Quick question I’m not sure where to ask this. But is it possible to import prices from Best Buy into a excel sheet based on the SKU or model number? Without manually doing it
Hello! I'm quite new at using SQLAlchemy and the orm, and I'm trying to query for entries in my class model's "title" column, but the query is going to be trying to match for a user's input on the song title. So I'm concerned that just filtering where title equals the user's input isn't going to be enough
I found the like and ilike methods but I can't seem to get these working with filter(), and i'm not even 100% sure if they accomplish what I want. How can I query data that is most similar to a given string?
typing this out, i figure i can use the spotify api to search for the song and then use its official title if i need to. it'd be best if i can try to find matches in the local database though =]
Our Organization has ERP, We do collect all the data from the ERP database SQL. Since ERP Scope is small we not capturing all the data in the ERP system. There is a requirement for me to capture the kilometers where drivers are going for delivery purposes. based on the kilometer we need to analyze whether the Petrol allowance is reasonable or not. So I planning to create a simple APK so I can install it on the deriver's phone so whenever they go for a delivery, they need to give the kilometers.
Kindly Suggest to me how I can make a Simple form APK. Is it possible to do it Python ?
im guessing im getting this error because my message_id column is of VARCHAR datatype and im trying to update int values to it, so ermm is there a way i can tell postgress the 991670121632374894 is supposed to be a string value and not an int? 😓
i tried wrapping it with (")'s but then for some odd reason i get this error column "991670121632374894" does not exist even tho 991670121632374894 is supposed to be a value/row...not a column
You need to use single quotes ' for string literals. Double quotes are for SQL identifier names, so postgres thinks you mean a column name.
ahh i see i see, thanks a lot!
Hello guys, can I make multiple request to different tables in the same database and the same endpoint?
E.g: first I make a GET request to a table.
If this data fits my condition, then I make a POST request to another table and if not, POST request to another table.
And so on
All in the same endpoint
GET and POST are HTTP verbs, which is most likely not a protocol you use to communicate with your database
are you asking if it's ok to send multiple queries to your database while responding to a single GET/POST request in your app?
if so then yes, that is normal - generally you try to reduce the amount of db queries needed to respond to the request, but it is normal to make more than 1
error coming from line 157 and 165... how could i possibly do this? what im trying to do is to get the usermodel for 2 different lists
like i need 2 separated lists
Hey can someone please help me in #help-bagel, it has to do with Flask and a Chat Apps formatting issues.
Thanks.
It sounds a bit weird for me that Im noob and I used to make in one endpoint, only one database operation.
But I can make multiple in the same endpoint with FastAPI async await for example
I'm receiving this error and very confused.. ever so simple. I thought this SQL would be correct? Working with MySQL.
Reference:
row is a list holding values of each row in the table being iterated via a for loop. (row is displayed on image below)
row[2] is the mutetype (value in this instance is text and type is TEXT)
row[1] is the discordid (value in this instance is 935665250030719028 and type is BIGINT)
cursor.execute(f"DELETE FROM muted WHERE discordid ={row[1]} AND temp = {True} AND mutetype = {row[2]}")
cursor.execute(f"DELETE FROM muted WHERE discordid ={row[1]} AND temp = {True} AND mutetype = {row[2]}")
_mysql_connector.MySQLInterfaceError: Unknown column 'text' in 'where clause'
'text' is not the column? 'text' is the value which belongs in the column of 'mutetype'
[Attachment of row in the table below]
Any idea how I can efficiently store up to 300k entries over multiple weeks and update about 1mil times (every entry around 3 times if not more)?
currently I'm using simple text files to store it
right now it will be doing about 1-20 database updates a minute but once i rewrite it in rust (at least thats the plan) I want to increase it to possibly hundreds
the entries contain all the same data and I've been thinking about using mongodb for it since its free/online and till now is the most stable online database i've used
I have a database of 500k+ strings of usernames in a CSV and I would like to search for any one of them as fast as possible.
What is the fastest way to search for a value in a large database? Should I use Python, C, excel, gsheets, ctrl-f in the CSV immediately? Would sorting the list make the search any faster?
can you give more context around the search?
how can i insert a python list of strings into a text[] column in postgres (i use asyncpg)?
Yep, the question is "how do I search for a name here faster"
An example of the data in my csv
H4NAJ7C8W, Sterling Fortune 27, 7800000
HRNAJUCIW, General eligun 60, 650462
Before I was using a vlookup or an index match in gsheets and the time to find a name is approx 10 seconds depending on the connection.
There are more than 500k entries, the data is sorted by the third column from top to bottom and one more time, I am only going to search for a row through the name (second row)
I'm looking for anything that could do this search in 1-2 seconds.
I guess this might not be the right place to ask this question as everyone here is specialized in python
yeah, most people would assume your question would be solved with python in some way.
There are also differences in terms of searches, whether you just want a look up, prefix or other fancy ways to search. That said, I can't help much with google sheet.
No google sheets is not the way, it is way to slow, I guess my question for you is would there be a way to do what I am Asking in python in 2 seconds?
I'm thinking something along the lines of if I were to sort the data by the second row
a 500k rows should be able to fit on most computers in memory. If you want a simple look up, then you can use a dictionary and the look up would be very fast
Don't use f-strings.
cursor.execute("DELETE FROM muted WHERE discordid = %s AND temp = %s AND mutetype = %s", (row[1], True, row[2]))
You problem is that {row[2]} is a text (and in this case also with the value text) which must be in single quotes in the SQL but your use of f-string doesn't have them. If you use placeholders (like above) the database module uses the correct form for the values depending on their datatype.
You tried to execute the statement:
DELETE FROM muted WHERE discordid = 9356... AND temp = True AND mutetype = text
but you need:
DELETE FROM muted WHERE discordid = 9356... AND temp = True AND mutetype = 'text'
Hello everyone , so um I have 3 .sql files .... and I'm supposed to retrieve data from them using Python
Now, I know python , and I have been learning SQL too but have never worked on .sql files before
Can anyone guide me about where am I supposed to do this work
I've done python programming in jupyter notebook , Kaggle Notebooks , Google Collab before
and have done SQL coding in Microsoft SQL Server Management Studio
I'm confused about which tool I am supposed to use for the task mentioned above
Tysm
If you run the files manually does it just run a 1 or more queries and return a 1 or more datasets?
.sql files are just text files. My guess is that you will be able to read the files as text in python and then put the contents in the execute of the required db driver. Is it a SQL Server db driver?
Traceback (most recent call last):
...
dbr = await interaction.client.database.execute(""DO
File "C:\Users\eboss\Documents\GitHub\dpy-dispy\venv\lib\site-packages\asyncpg\connection.py", line 320, in execute
_, status, _ = await self._execute(
File "C:\Users\eboss\Documents\GitHub\dpy-dispy\venv\lib\site-packages\asyncpg\connection.py", line 1659, in _execute
result, _ = await self.__execute(
File "C:\Users\eboss\Documents\GitHub\dpy-dispy\venv\lib\site-packages\asyncpg\connection.py", line 1684, in __execute
return await self._do_execute(
File "C:\Users\eboss\Documents\GitHub\dpy-dispy\venv\lib\site-packages\asyncpg\connection.py", line 1731, in _do_execute
result = await executor(stmt, None)
File "asyncpg\protocol\protocol.pyx", line 183, in bind_execute
File "asyncpg\protocol\prepared_stmt.pyx", line 142, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions._base.InterfaceError: the server expects 0 arguments for this query, 2 were passed
HINT: Check the query against the passed list of arguments. Note that parameters are supported only in SELECT, INSERT, UPDATE, DELETE, and VALUES statements, and will *not* work in statements like CREATE VIEW or DECLARE CURSOR.
await interaction.client.database.execute("""DO
$do$
BEGIN
IF NOT EXISTS (SELECT * FROM fnine_lib WHERE user_id=$1 AND url=$2) THEN
INSERT INTO fnine_lib (user_id, url) VALUES ($1, $2);
END IF;
END;
$do$;""", interaction.user.id, r.url)
It's saying it expects 0 args 
postgresql + asyncpg
I just started learning and want to play around with Flask, I want to store some scapped data in a db before I make any further steps. I was thinking of using MongoDB, are there any other recommendations?
i got this error
ERROR 1524 (HY000): Plugin 'root' is not loaded
while running
sudo mysql -u root -p```
command plz help me solving this
Depends on the data, any db would be fine, but i personally prefer postgres
MongoDB is good if you just want to dump a dictionary or something and you don't care how your data is organized. SQLite or Postgres is better if it makes sense to normalize your data and have tables with foreign keys and stuff. If you've never used a SQL DB it's worth taking the time to understand how they work, it's pretty different from a NOSQL db like Mongo
Technically you can just use jsonb for arbitrary data
Hello, I have a JSON file of a 2500 English words, and I wanted to learn how I can insert them into a database (I'm using Django, very new to this)
hi
I am using access with python
this is my code
Traceback (most recent call last):
File "C:\Users\user123\PycharmProjects\review-reader\use_db.py", line 8, in <module>
cursor.execute("""
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in DROP TABLE or DROP INDEX. (-3556) (SQLExecDirectW)')```
and incase if u guys ask me to comment out drop table
heres the new error
what is the best database engine for me if i have:
An ubuntu vps,
and I'm storing discord bot data, economy/items/so on.
rn i have sqlite and it works nicely, but I'm planning on scaling up soon, so i will need something that can also scale up, and i want it to have good python asyncio support,
does anyone know which dbsystem is going to be best fit for this?
hello all
FROM python:3.9.5
RUN apt-get update && apt-get install -y postgresql-client-11
for above dockerfile, docker build works
But for
FROM python:3.9.6
RUN apt-get update && apt-get install -y postgresql-client-11
docker build throws the following error.
#5 2.088 Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2592 B]
#5 3.086 Fetched 8545 kB in 3s (3341 kB/s)
#5 3.086 Reading package lists...
#5 3.605 Reading package lists...
#5 4.113 Building dependency tree...
#5 4.251 Reading state information...
#5 4.356 E: Unable to locate package postgresql-client-11
Unable to locate pkg. Any idea?
the details may depend on your models and stuff but maybe this will help: https://www.laurencegellert.com/2018/09/django-tricks-for-processing-and-storing-json/
In this post I'll show a few tricks I use to make JSON fit into Django more seamlessly. The first is a lesson on coding that everybody should know. Parsing external JSON: Whenever you take in JSON from "strange computers" (which is basically any computer) it works most of the time. As C3p0 said: R2D2,
Postgres
you can dump them to json and store them, you can pickle them, etc. but you can't edit individual records the way you can with a real db
class userData(db.Model):
DiscordID = db.Column(db.Integer, primary_key=True, nullable=False, unique=True)
Web_ID = db.Column(db.String, nullable=False, unique=True)
WebRank = db.Column(db.String(255), nullable=False)
Points = db.Column(db.Integer, nullable=False)
userPost = db.relationship("userPosts", backref="author", lazy=True)
class userPosts(db.Model):
postid = db.Column(db.Integer, primary_key =True)
postedWhen = db.Column(db.DateTime, nullable=False, default=datetime.datetime)
postTitle = db.Column(db.String, nullable=False)
postContent = db.Column(db.String, nullable=False)
dID = db.Column(db.Integer, db.ForeignKey('userData.DiscordID'), nullable=False)
db.create_all()
Trying to create these tables gives me an error
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'user_posts.dID' could not find table 'userData' with which to generate a foreign key to target column 'DiscordID'
hey, when im executing a command in python, how can i include the column names in the shell
thanks i was considering it
...
else:
username = input("Enter your username: ")
password = input("Enter your password: ")
c.execute("SELECT 2 FROM fork WHERE username = ? AND password = ? LIMIT 2;", (username, password,))
if c.fetchone():
play(username, ':-')
else:
print("Incorrect password or username")
New to sql. This is just a simple test with sqlite but how would I go about setting a variable in python with the prefix attribute in the database for that specific username without explicitly doing it the way shown above.
Where prefix in play() is explicitly put in as :-.
How is the prefix stored in the database? What's the schema for the table?
def c_table(name):
c.execute(f"""CREATE TABLE {tableName} (
server_id INT,
username VARCHAR(20),
password VARCHAR(20),
cmds INT,
prefix VARCHAR(3),
language VARCHAR(15),
PRIMARY KEY(username)
);
""")
I updated the prefix by calling this function
def update_prefix(usr_name, prefix):
with conn:
c.execute(f"UPDATE fork SET prefix = ? WHERE username = ?;", (prefix, usr_name,))
in
def play(username, prefix):
but prefix is set to the prefix in here (replied msg) and not the one in that specific user's db
c.execute("select prefix from fork where username = ? and password = ?", (username, password))
prefix = c.fetchone()
if prefix is not None:
play(username, prefix[0])
Does this work for you?
You're welcome
I am undergoing a class assessment which includes converting a relational database to dimensional model. As you know, dimensional model contains many tables. So, I need to find some public database with multiple tables. So far, I couldn't find one online. Help needed. Thanks
This doesn't answer your question, but it's generally recommended to use Python's getpass module to get passwords as input. Just a best practice, but it's a good thing to know.
hm I'll keep that in mind then
can someone please explain what is wrong with this psql query
select 'some prefix'|| round(cast (float8(
select SUM(transaction.amount) from transaction where type='deposit' and content_type_id='9'
) - (
select SUM(transaction.amount) from transaction where type='withdraw'
)as numeric), 2)
Thanks!
I been trying to sketch out why designing a curriculum for databases is hard and why it’s hard to learn it
So just by using select queries as an example, and listing out a couple of posible options in each clause we can see already we can form at least 96 possible types of select queries, unlike normal programming where I can devise a clean curriculum, I can not do that easily with sql
sounds like a non sequitur.
Teaching databases has nothing to do about teaching all the combinations of SQL. That's like saying how one cannot teach programming due to all the many combinations of the various keywords and operators in a programming language and how many programs you can express with them.
Can you expand on the problem you are trying to solve?
Hello everybody. I'm trying to create a table "Genre" to which the objects of the table "Movie" belong, and I wanted one movie to have several genres, and those several genres to be contained in one column (like a list of genres), but this type of column does not exist in SQL, maybe I don't know something
is there any way to install mongodb on mac without brew?
The SQL way would be to make a third table with movie and genre as foreign keys to link them together.
Some databases do support an array like column type but that's non standard.
Table Movie
movie_id PK
...
Table Genre
genre_id PK
...
Table Movie_Genre
movie_id FK
genre_id FK
PK(movie_id, genre_id)
how to do i get multiple output out of my sql enquiry
SELECT supervisor_name ,
supervisor_id FROM branch_info WHERE branch_code =(SELECT branch_code FROM linker_table WHERE car_plate_nr =(SELECT car_plate_nr FROM car_detail WHERE car_type ="SUV"))
getting only one row of output
but there are more output
in mongodb how would i add another name in the characters object?
also how would i update the value if said name by +1
i am learning SQLAlchemy ORM to use with my flask application and was reading the documentation, but i did not find anything in the docs that teaches about Migrating the Models i have written into database tables. Is Migration something Flask is responsible for or SQLAlchemy ?
what would be the most optimal way to import a JSON file to a MongoDB database?
I've seen people doing it with MongoDB Compass, Atlas and a few more ways that I can't remember now, so is there any "best/fastest" option really? If so, which one?
is is matter if a column in a table gets a NULL or NOT NULL if we changed the default value in SQL?
Hey there!
I don't know if that's the right place to ask for that but are files without any extension used as database files?
for example all the Login Data from Chrome is stored in "Login Data" (no extension)
They can be, but not necessarily.
Extensions are just part of the name. They don't affect the data. Like, I could take a text file and rename it to a .png extension and it will still contain the same data as it did when it was a .txt file.
Alembic is a extension on top of SQL Alchemy that is focused on migrations.
I’m a tutor bro, I’m saying there is no probably no efficient way of teaching it
I already learned it
But the way I learned it I had to keep going back and re reading
With programming you can roughly describe the knowledge obtained like a pyramid
But sql is different, it’s more like a network of facts
You have to put together
So somebody can’t learn the stuff 100% in a lecture
I’m giving an illustration, not an argument
One needs to learn relational algebra to help mental process what’s going on first
Which is what I did
That's great to be a tutor! But we can have a more interesting discussion if we don't rely on argument of authority. Let them stand on their own.
Learning the deeper side of SQL is tricky and probably not the most important topic because it varies from dialect to dialect and may miss on some more important topics like how to model the data, the purpose of ACID, the different types of DB, etc.
And the one learns SQL
By breaking down tables and the possible quieres
But teaching somebody how to use those queries is not formulaic at all
An argument is when given a set of facts I claim something is true
I’m not making an arguments other than the one right now
Everything I’ve said said so far we’re explánations and illustrations
Your free to think what you wish, but it’s not helpful to the people who are learning here
they were wrong though.
You can teach databases and you can teach SQL
I said you can’t teach it EFFiCiENTlY
The fact that you can combine the various parts of a SQL dialect in many possibilities does not render learning SQL impossible
You can sometimes treat knowledge like math
can you describe why it wouldn't be efficient?
And form curriculums easily
There is a formulaic sets of steps to learn a given topic
Sql isn’t like that
And I illustrated that by sketching the number of possible select queries
At best I’m making an inductive argument
So your free to judge it as weak
if you try to learn SQL by all the possible combinations of queries, that would still be the wrong way to go about it.
With programming you can teach it chapter by chapter
And can break down all the stuff step by step
I know because I have a curriculum on replit.com
I know exactly what problems to give etc
It doesn’t matter I probably know sql better than you 
Let's take an example like https://www.amazon.com/Learning-SQL-Generate-Manipulate-Retrieve/dp/1492057614/ Why shouldn't it exist?
Giving an example of a book doesn’t prove that it efficient teaches it
I know because I’m literally reading a book right now
And even with all the facts provided there is many different ways to organize the facts
But it doesn’t make sql easier to understand for other people
Like the prerequisite to learn sql is literall “be good at math”
That’s how I can describe it
And why I can do it
Because I’ve reasoned about many different things
It’s easy for me to know what to do next
I am using it as an example so I can understand what makes something inefficient in this example. The table of content does seem pretty logical
I’m not saying sql is easy for me, I’m just saying I know how to learn it
But I can’t teach that learning process
You sound like one of those bad professors my dude
Your free to think what you wish
Insulting people doesn't make you right
I know it doesn’t
If you can't have a normal discussion, I am not interested
It’s my opinion;of you
Good day! I have little question about database structure.
For now, i have sqlite3 database to store 25 different storage sites and items on this sites. Current database designed in one table, using columns like: serial, name, quantity, site1, site2 .. site25. Site columns are integers with just a number of item on them.
Now i want to remake all this and make structure like:
table1: serial FK, name, quantity
table2: site_name FK
table3: serial FK, site_name FK, quantity_on_site
I have around 2k items(rows) and 25 sites. Will this be the right structure for database?
ok i created a way to make it optimized
an optimized way to learn fundamentals of sql
Is there a way to shift sqlite3 data to postgressql using Python easily?
hi
Hey, I'm trying to domarket_hash_name = "AK-47 | Phantom Disruptor (Factory New)" cursor.execute(f"""Update Set where market_hash_name = 'market_hash_name'""")
It just say near "Disruptor": syntax error
what can I do
guys should I run con.commit() every time after the every process, or should I run after all process done?
solved
waiting
after all proccesses are done
Also the query is meant to be:
UPDATE <tablename> SET <column> = "whatever" WHERE <where stuff>
Example:
cursor.execute("UPDATE test SET market_hash_name = :market_hash where market_hash_name = 'something'", {"market_hash_name": market_hash)
anyone?
the code when i have the error :
Hey i have an error with my discord bot command to check an column in table.
The error when i use the command :
Ignoring exception in command get:
Traceback (most recent call last):
File "C:\Users\nstyb\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "D:\WORK\py\discordbot\main.py", line 27, in get
rows = cursor.fetchAll()
AttributeError: 'MySQLCursorDict' object has no attribute 'fetchAll'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\nstyb\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\nstyb\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\nstyb\AppData\Local\Programs\Python\Python310\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: AttributeError: 'MySQLCursorDict' object has no attribute 'fetchAll'
Code :
@bot.command()
async def get(ctx):
cursor.execute(f"SELECT hour from players_laders where discord = {ctx.author.id}")
rows = cursor.fetchAll()
error in line : rows = cursor.fetchAll()
thanks for your help
method-names are case sensitive, .fetchall() is all lower case.
And please don't use f-strings.
@bot.command()
async def get(ctx):
cursor.execute("SELECT hour from players_laders where discord = %s", (ctx.author.id,))
rows = cursor.fetchall()
anyone good at sql query
thanks !
I have this little project I’m working on, dealing with multiple nested dictionaries. As a beginner, It struck me that in a way nested dictionaries are similar to tables and the relationships I develop between them, and the resulting dataframes are like queries. It got me to wondering if maybe what I’m doing would be more properly set up as an actual database rather than multiple dictionaries that are created on the fly.
My next thought was, and I haven’t researched this yet, but what kind of database capabilities does python have? Can it create its own tables, stored externally to the script? Or would I only be able to use some kind of 3rd party software to hold the data?
all of the above
One of the foundations of Computer Science is the ability to process data, and that include being able to store and retrieve it. There are many many many many ways to go about it as there are many many many many different use cases, each one with a different set of trade offs
So in my particular case, my thought process is overkill. I'm dealing with relatively small datasets, probably no more than 1000 records. The most time consuming part is the "foundational data" is obtained from a 3rd party software. Once that's done, the processing can start. The results of processing would then be imported back into the software, or perhaps an intermediate visualization step to see the results of the processing.
I just like trying to do things "the right way" for personal reasons. That and I love databases.
but it just kind of struck me how similar nested dictionaries are to tables, or the results of queries.
I am not sure if it would hold up as the relationships increase, but yeah, it's one way to retrieve the data 🙂
It seems overkill for your case, but it's common in these cases to have a pipeline with the different steps and merging the output into a final file for the app. This way if a step fails, you can re-start it and you still have the previous file available. Plus, it can be scheduled across a set of machine for reliability/throughput benefits
At the moment that's what I've done with the one "expensive" dictionary. I saved that as a text file and then included a boolean to indicate whether the script should go talk to the software, or go use a local file.
Come to think of it, at the moment, if the local file just had the same name as the model (3rd party) file, that could help a bit with the determination of whether or not to process.
But, at the moment I'm more skilled with SQL than I am with pandas so querying and linking dictionaries to produce new dictionaries is a bit cumbersome for me. But I digress.
I need to go google what's out there for python. I think wherever this script is used will have MS Access available so there's that, but I think things would be faster if I didn't have to go through another piece of software and just used local plain old text files, somehow.
you may be interested in duckdb
I appreciate the suggestion! I was just looking and saw that sqlite is included with python so I was thinking of that first. I'll definitely check out duckdb.
They are pretty close. Duckdb is more oriented towards analytics
initially i went the alembic route but did not succeed in the configuration part.
is there an efficient way of selecting every column but excluding a specific one in postgresql?
Well my best bet would be to make a temp table and then drop that column from the temp table
I have a postgresql table that i'm trying to open in pandas with 23m rows, but, when I try to do so, it ends up running out of memory. However, I tried saving the table as a CSV file and opening the file in pandas and it worked perfectly, but what I'm noticing is that the CSV file is losing "metadata" of sorts in the table. In the table, I have a few JSON and array columns, but those get turned into strings and other undefined behavior when I import it into pandas from the CSV. What could I do to mitigate this? Is there another file format I could use?
The best solution may depend on what you're trying to accomplish. Can you load direct from Postgres to pandas by leaving those columns out (the JSON and arrays)? Is the memory issue with your hardware or are you going over the limit of Pandas (I think it's 100gb / frame?)
so my goal is to be able to load all of these columns in, and I'm able to do so when i limit the number of rows to something much lower (i.e. 10m vs 23m), but I'm just wondering if there's anyway to either:
- load the entire thing in memory
- save it locally in a format that preserves these columns that csv doesn't play nicely with
How about JSON? Seems messy to load that in to Pandas, but it's the obvious alternative to CSV. Otherwise maybe a pickle file
I could definitely try, how would I go about saving the postgres table to JSON?
I haven't done it but this is the idea ... https://www.peterbe.com/plog/from-postgres-to-json-strings
errr slight problem, I just said that i couldn't load the entire table into memory due to memory restrictions 🙃
And you can do it in offset batches?
oh wait really?
i never thought about that
i must need some sleep
Just want to say i agree with this 100%....Why would you ever want to learn through every possible combination when the efficient way is to go through the parts of a query, what they do, and what to expect in the underlying tables. Also a teacher for SQL bootcamps and the number one thing people become confused on is when you throw 100 detail specific examples at them at once. Give them the basic foundation and a way to advance in knowledge and it takes care of itself.
In keeping with efficiency, does anyone know an efficient way to load 100k-800k rows in xlsx/csv workbooks into Teradata via python. Just curious on the most efficient module/method as there are a lot of options and idk whether to run a chunking process or insert rows in a loop
@minor plover Again I haven't tried it so I could be wrong, but name guessing it should be fairly trivial to dump a few million records at a time
erm, how can i check if an element {"ABC"} belongs to an array column (text[]) of a table named XYZ? i am using postgresql
i found another method, in psql:
\t
\a
\o file.json
SELECT row_to_json(r) FROM TABLE_NAME AS r;
works most of the way, only thing is that each line is json formatted, but the file as a whole isn't
you need to add commas and [] to make it a valid json
but that's easy to automate
Thats seems quite ideal as its streamable and don't need to load all into memory
and it behaves just like json-lines does here: https://docs.python.org/3/library/json.html#cmdoption-json.tool-json-lines
please help
So I made a discord bot, it works with sqlite3, uploaded it to heroku. When I download the repository, the database file remains unchanged, although I made changes in the bot. I made the bot output the database values - and they were changed, but when I downloaded them , there were no changes. How do I download the sqlite3 database file from heroku?
First, you don't want to keep your DB in your repo, that should be ignored
But I've never used sqlite3 on Heroku so I'm not sure if or where the file would be accessible for download.
if choose == "2":
username1 = input("Username: ")
password1 = input("Password: ")
with open(username1, 'w') as f:
f.write(password1)
time.sleep(2)
folder = mega.find('DATA')
mega.upload(username1, folder[0])```
im using mega as a database and everytime the files uploads there's no text in the file while there's the text in the file in my pc
hi! is there a way to check if a postgres array 'x' has an element 'y'?
hello. Is there an API that lets define tables like SQLModel? I'm asking this since SQLModel has many features that I don't want to use in my project. The only purpose that I consider useful is the creation of a db using table models which is more user friendly. Regarding data manipulation, I pretend to use asyncpg.
postgres returns [0, 2, 133, 133, 51, 210, 141, 199] for a TIMESTAMP field, how would I decode it?
(ping on response)
Hey guys, how do i alter a field in transact sql to be auto increment?
use TO_TIMESTAMP function to convert it to suitable format
ohh wait u want the other way around
but it should still work imo
and can u show your select statement ? why is timestamp a list ?
in mongodb can i make characters something like
characters:
"Michael":
6
4
3
7
"Seraph":
7
2
6
7```
what i have right now
but i still want to retain the ability to index characters
Heya, I'm looking for some help with a Postgres query. I have a table that looks something like
id | title | alias_of
1 | 'foo' | 'foo'
1 | 'bar' | 'foo'
1 | 'bat' | 'foo'
2 | 'x' | 'x'
2 | 'y' | 'x'
...
```I'm trying to get, for a given input, the title with the minimum distance from that input (as calculated by pg_trgm's `<->` operator), for each group of 'alias_of'. The closest I've gotten myself is with
```postgres
SELECT DISTINCT ON (alias_of, min_dist)
*,
MIN(title <-> 'input here') OVER (PARTITION BY alias_of) AS min_dist
FROM tablename
ORDER BY min_dist, alias_of ASC;
```but it feels intuitively wrong to have both `alias_of` and `min_dist` as distinct parameters. I am quite unsure as to how I can make this work, so any help would be much appreciated ^^
I seem to have found a working solution with
WITH ranking AS
(
SELECT *,
title <-> 'input here' as dist,
RANK() OVER (PARTITION BY alias_of ORDER BY title <-> 'input here' ASC) AS r
FROM tablename
)
SELECT *
FROM ranking
WHERE r=1
ORDER BY dist ASC;
```though it seems rather roundabout...
hi I was wondering if someone could help me with my Peewee ORM's models and functions - I am writing a search application and I'm just having trouble to write it correctly. I keep getting mysterious error messages. I can share a whole "test file" with the relevant classes and functions or some excerpts where I think the problem might be but don't know how to fix it
Hey @maiden solar!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
yup
So this is the code. Currently when I try to run it it gives me the error apsw.SQLError: SQLError: sub-select returns 5 columns - expected 1
and I'm honestly confused about which part the code this even is, because it only gets thrown when I iterate over the results since everything is returned as iterable. Even debugging this whole thing seems a little hard to me.
welp maybe I'll go over to one of the help channels
Hello everyone, how do I make múltiple database queries in the same endpoint with FastAPI?
Async/await? Middleware? Normal way?
For example this is a POST endpoint:
- Query to DB if whatever id is correct.
- If its correct get xyz data from DB.
- If everything is OK and we have all the necesary parameters, finally add registry to DB.
Note that everything is in the same endpoint.
In this example we have 3 DB operations.
Thanks, I used to put only one query per endpoint.
I cannot test my multiple queries in one endpoint because I need the especifications of my project.
But I think in the normal way it may work :
obj = db.query().filter()
if obj != None:
xyz_data = db.query().filter().all()
if everything is OK:
db.create()
Hi everyone, i need a help with cursor, in python
how to make a cursor remember for every select query, lets take first time we have selected 100 rows
0-100
secondtime if i run query it should fetch from
101-200 rows
can it be possible?
I don't know what db you're using etc. but in general that's what OFFSET is for
So like I said: https://www.postgresql.org/docs/current/queries-limit.html
hey guys. I need help. I'm using sqlite3 and I want to delete a table... can anyone me out with this ?
I want to delete a table from the database file
how can I do that ?
no no not table
I want to delete a row
really sorry
I want to delete a row from a table
I tried -> 'DELETE FROME <table_name> WHERE UID=<uid>'
yes I know
this didn't work
@fading patrol @slow cove there is no equivalent function in python like offset or limit
okay the columns are UID, Email, Passwords
just some general columns
a basic table
Anyone ??
please help me
I have to Google everything for you? 🤣 Here are two different ways https://dellsystem.me/posts/psycopg2-offset-performance
If that doesn't solve your problem, show some code
no no i didnt mean that i tried searching i am sorry @fading patrol
hey, is it possible to split the models of sqlmodels in multiple files? rn im getting circular imports when trying it
Guys can anyone help me making a custom prefix for my discord bot pls
@winged moth
async def setup_hook():
connect = await aiosqlite.connect('prefixes.db')
cursor = await connect.cursor()
I wrote this
Is it fine?
ya?
make sure to close the connection before shutting the bot
No this is what the database sends to my driver
It’s a [u8] array
unsigned 8 byte integer array
How do I decode it to a time stamp I can understand
postges or something else?
Ok 👌
#100DaysOfCode #MySQL #Database #PostgreSQL
🎯 Learning Part 1: What is Structured Query Language (#SQL) and How I learn #SQL
Learning SQL has always had an advantage in the programming world.
It is not surprising that you have an advantage in employment once you know SQL.
postgres
it's a [u8, 8] kind of array
8 members, all are type of unsigned integer 8 bits
how is the table initlized
it's TIMESTAMP
DEFAULT current_timestamp
I'm trying to decode the byte array it's sending me
it looks like this: [0, 2, 133, 133, 51, 210, 141, 199]
and it's supposed to be this: 2022-06-28T18:45:00.002759
currently I'm trying to get it to unix timestamp
hey so i want to store user media information right, is it wise to provide a user one folder with a related parent folder for thier data storage?
root
|- user 1
|- user 2
|- user 3
etc
I wanted to user buckets but i suppose thats a bit out of my reach but i wanted to replicate somthing of that case. the folders and thier relationship with the user will be stored in a "indexing" database entirely and querying will be available through an api interface. Any thoughts?
there are nothing in postgres's documentation saying how the bytes work
hanng on let me spin up a test db real quick
thanks man
ok how are u inserting data into table and accessing it
and this good ?
postgres=# create table garbage (
col1 timestamp );
I figured it out
If I convert this [0, 2, 133, 133, 51, 210, 141, 199] to u64 with big endian
it will result in a timestamp
giving me how many microseconds it has passed since 2000 Jan 1st
Any idea how to do this properly? (Excuse me if wrong channel, just saw this related to DBs)
do what ?
Oh sorry, forgot to delete that aswell. Already found an answer so I removed my wall of text
would anyone be able to help me out in trying to write parts of my notebook into a docx file, i need to somehow save dataframes and plots into one file
im trying to follow this
and it seems to process just a regular table from a df fine but doesnt work when I try to input dataframes that i've made with .agg()
I'm using pymongo but how exactly would you get the admin and local variable to not print when using list_database_names()?
I did that
I used a for loop and then a if loop inside saying if databases names in [admin, local] continue and then print
no
for categories in database.list_database_names():
if database.name ["admin", "local"]:
continue
print(categories)
still printed admin and local
'str' object has no attribute 'name' thats what it returns when using categories.names
That worked, tysm!!
hay guys. what is the best database for a python bot (discord.py)
SQLite is easier, Postgres is more robust
how do I start using it in python? any video/tuts recommendations?
There's plenty if you search, I haven't followed any
okay. thx for your time
Is there an async database library?
or package?
(doesnt know what the imports are called)
For what DB? Here's one for SQLite: https://pypi.org/project/asqlite3/
@winged moth
Can you help at sqlite
I am not able understand how can write the get prefix function
import aiosqlite
import discord
from discord.ext import commands
import asyncio
def get_prefix():
pass
bot = commands.Bot(command_prefix='<', intents=discord.Intents.all())
async def connect():
connect = await aiosqlite.connect('prefixes.db')
cursor = await connect.cursor()
await cursor.execute('CREATE TABLE IF NOT EXISTS prefixes(guild_id INTEGER,prefix TEXT)')
await connect.commit()
await connect.close()
@bot.event
async def on_ready():
print("ready")
await connect()
Here is my code
I use a Dockerised Postgres db for my bot, and it often just raises asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "postgres" randomly, after working normally for 3 days. I often end up needing to run docker volume prune -f and restart the container, and it'd go back to normal.
What could the cause of this be?
characters:
"Michael":
6
4
3
7
"light"
"Seraph":
7
2
6
7
"dark"
in mongo db can i do something like this?
i want to be able to search for a name in characters and also be able to get some data from that character
Hi. I have a simple cx_oracle question over in #🤡help-banana if anyone has a sec to help me out.
yo guys
how to fix that in java program sir
what's the best solution when you want to select sum for total and for 30 first days in one select?
hi, i dont know very well how to explain what i want to do, i'll give you an example and you tell me what is the correct way of asking help for this sql query
i have some table like this
id cod value
1 2 1.0
1 3 2.0
2 1 1.0
2 2 1.0
and i want an output like this, with the columns of the cod values above
id 1 2 3
1 0 1.0 2.0
2 1.0 1.0 0
how can i do this?
Hello,
that operation is converting data from long to wide format, but I'm not sure if SQL supports it exactly all that well
(long = label as a column ; wide = each label is one column)
https://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query
https://stackoverflow.com/questions/37450474/long-to-wide-sql
Is there a way to merge rows so the output is like this? I use event sourcing and have 3 different events and i want to push them into the create ones
id name event reference_id object_reference_id object_id
1 test create 1 U00001 U00001
2 test2 correct 1 U00001 U00002
output
1 test2 create 1 U00001 U000001
so it merges updates into the create entry in database
thank you very much!
Can someone give me an idea to keep records of files with date.... I mean when I load file into memory, I want to put that file name and the loaded date and time
Not an online database.... A local one
hello, when defining declarative tables with SQLAlchemy ORM, is there a built-in way of mapping each class attribute to a string?
I want to set up my tables in the modern declarative way, but also have a mapping of strings to the class attributes (column variables), so that I can programmatically refer to each attribute/column
I imagine I would have some kind of "imperative mapper" set up like this:
mapper_registry.map_imperatively(User, user_table, properties={
'id': user_table.c.user_id,
'name': user_table.c.user_name,
})
but I can't tell from the docs -- is it possible to have tables defined in the declarative way, and also have this mapping? also how would I even use this mapping?
I want the user to be able to use a string 'name' instead of a variable user_table.c.user_name when they add/insert data into that column
anyone know what the fastest database file type is that is able to be opened with a basic text editor?
text editors cannot open any database type, fast or slow, unless you stretch database to include json, yaml, and the like, and you really shouldn't do that
i was thinking of just going with csv because i would only be writing to the file rather than getting data from it, do you know of any alternatives?
csv files can be thought of as 2-dimensional lists (or lists of dicts) in function in that you can access data by row and then column. If this is okay, sure, you can use csv. If you want more advanced data mappings - like how different data are related to each other, than proper databases are a better fit.
I suppose i will stick with a csv file in this case, thank you!
!d csv in that case you want this
Source code: Lib/csv.py
The so-called CSV (Comma Separated Values) format is the most common import and export format for spreadsheets and databases. CSV format was used for many years prior to attempts to describe the format in a standardized way in RFC 4180. The lack of a well-defined standard means that subtle differences often exist in the data produced and consumed by different applications. These differences can make it annoying to process CSV files from multiple sources. Still, while the delimiters and quoting characters vary, the overall format is similar enough that it is possible to write a single module which can efficiently manipulate such data, hiding the details of reading and writing the data from the programmer.
Is it expected behavior in SQLAlchemy when I use a raw_connection on an engine that temp tables are still there when I con.close() and then open up a new connection? 🤔 I thought closing would already be enough to get rid of everything. It appears not? Do I need to also close and recreate the engine or did I go wrong somewhere? Thanks!
Engine holds a pool of connections, it uses FIFO implementation by default which may use more connections that LIFO:
https://docs.sqlalchemy.org/en/14/core/pooling.html#using-fifo-vs-lifo
I'm not sure about your problems with temporary tables though, but i'd also recommend using context managers instead of closing connections with .close() method:
with engine.begin() as connection:
...
hello in mongo db can i have something like
characters:
"Earth Elemental": 7
"Fire Elemental": 4
and then sort by the number for each character
yes you can
how would i do that if characters is an array?
that would be an array of something like a struct
sorry, would you mind explaining what you mean?
Something like: characters: [{"Earth elemental": 7}, {"Fire Elemental": 4}]
i tried this but it returns a assigned number: name instead? is it because im using $push
collection.update_one({"_id": userid}, {"$push": {"characters": [{name: rarity}]}})
https://www.mongodb.com/docs/manual/core/databases-and-collections/ You can create collections of anything
Why not
characters: [
{
"name": "Fire Elemental",
"count": 4
},
...
]
I don't use mongo but in this case it should be easy to sort by count/number
hello, i am working with mysql 5.7 and i would like to insert data into my db. but i have an error probably cuz i dont write with the good syntax.could u please give an example of an "insert into values where" from Python please
because i found nothing on internet
this is my code :
command_best_time = ("INSERT INTO best_score "
"(Best_time) "
"VALUES (%(speedrun_total_time)s)"
"WHERE user_id = (%(id_user)s)")
data_best_time = {'speedrun_total_time': total_time, 'id_user':file}
and it returns me that : SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (user_id = ('67967437944310345335035921252057299374076208405004'))' at line 1
I just started backend developer, i learn database design but i only use ORM not native SQL. Do you think it is the suitable choice ?
It depends what kind of work you want to do. You probably need to know a little bit about native SQL but maybe not a lot
hey there, im currently building a timeseries database for pandas / dask dataframe data which can handle multiple billions of lines of dataframes. if anyone has a usecase for this and would like a specific feature hit me up! https://github.com/mercator-labs/oakstore
highspeed timeseries pandas dataframe database. Contribute to mercator-labs/oakstore development by creating an account on GitHub.
I need to fetch few docs from s3 bucket whenever user id logged into their account. All user id are in dynamodb table. How to tag both ?
anyone got recommendations for a database for distributed computing/3d rendering?
debating which one to choose
redis seems to tick a lot of boxes but seems more cumbersome to deploy on nodes than something like sqlite or sqlalchemy
CREATE TABLE `article_votes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`article` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `article_uid` (`article`,`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Can anyone tell me what this code means:
UNIQUE KEY `article_uid` (`article`,`uid`)
Thanks
And what's the equivalent of that in Django?
I don't know the equivalent in django, but I can tell you that it means it's a constraint on the uniqueness of the pair article and uid
It's hard to say without more information.
That will depend a lot on your workflow, the users, the type of data, how it comes in, how it gets queried...
In Django it can be modelled using a UniqueConstraint
So if I'm understanding it correctly, every article can have only 1 article_votes from 1 uid(user id)?
it would appear so
Ok
This is the full code just fyi https://github.com/tetreum/erep/blob/master/db.sql
on a side note, I would expect the IDs (user and article) to be foreign keys and the charset to be utf8mb4 (default since mysql 8) [although not really necessary in this table since it's not at risk of emojis]
Right, in Django I could just set them as foreign keys
hey guys, im a sorta beginner to SQLite and would like some help with the syntax
is there a way to get this value?
under shieldQuantity and row 1?
`SELECT shieldQuantity WHERE id = 1' might work https://www.sqlitetutorial.net/sqlite-where/
OKOK
is anyone there?
i just wanted to see that what happens if i delete the partition i use for linux ?
cuz i need space for my windows
that data will be lost and most likely prevent linux from booting
Also that question would be more appropriate for #unix since it's unrelated to databases
sorry i dont know much about computers and stuff i thought it was related.
and thank you very much!
Hi there, I'm solving a delicate problem and gotta try to ask if someone has experience with this. I'm working in a company and previous developers messed up Django migrations and also everything is one single django app... I would love to refactor into multiple apps and to rework migrations from scratch, but I cannot lose data in production database. Anyone has any idea how to rework migrations and do not affect data in database?
Its my understanding you can squash the migrations to make them easier to work with though apart from squashing you shouldn't be changing existing migrations. You will need to create migrations to go on the top.
and previous developers messed up Django migrations and also everything is one single django app.
I see this would just be a fresh migration after you've done the refactor that you want. Takes a bit of testing though with environments mirroring production though to make sure you've covered your bases. For something like this I'd take a backup of prod and restore it to another server so I can test and be sure.
Thank you for the answer, well there is over 100models in a single app, that's why I want to split it... If you split it you divide migrations. It would Remove fields and recreate them in other migration tree. Also number of migrations should be 0192 but there is over 300migrations(Due to those duplicates. Dependencies don't add up. Few migrations deleted along the road because if you try to create new project, fields are missing if you fix all the issues in migration tree.) I'm kinda upset at the former devs due to this unsustainable code lol.
I've landed a question with a thought how to work this out on Stackoverflow, maybe someone who dealt with this will notice it. --> /questions/72920584/how-could-i-rework-django-migrations-without-affecting-database
The idea was to --fake zero --> delete migrations in project folder + in DB --> split models into separate apps --> makemigrations --> add flag: managed = False --> migrate
Already done a copy of DB and I'm preparing for an awful afternoon. 😀
hello. I'm using asyncpg. I pretend to create a database remotely, so first I connect to a db template (template1). Then, I send a create database (testdb) command. However, I need to connect to it in order to, for example, create tables, triggers... Do I need to close the first connection and then open a new one with the created database or is it possible to send (with the previous connection) a connect testdb and automatically connects to it?
I don’t think this is possible. Is this the same project? https://github.com/MagicStack/asyncpg/issues/368
yes it is
wow I didn't know that it doesn't allow to do that. thank you tourdownunder
https://stackoverflow.com/a/56277002 I need to do something like that unfortunately. It's a little tedious
That looks a very neat solution.
my initial idea was just opening a connection to do the whole "creation". but seems I can't ahahahaha. I'll adopt that solution and that's it
I am trying to make a moderation log for my bot and I am wondering on how I would auto_increment the case id per guild. For Example:
Guild 1 could have 39 Mod Cases and when a new mod log is entered I want the case id to be 40, not the amount of mod log entries there are for all the guilds in the database.
Hi, do you know how many select where are possible per second with consumer hardware and postgresql database?
I would guess it varies widely on the exact hardware and data so you should just test... but tens to hundreds may be?
This person got 200 on a Pi https://blog.rustprooflabs.com/2019/04/postgresql-pgbench-raspberry-pi
pw = "my_pw"
username = "admin"
mongoClient = pymongo.MongoClient(f"mongodb://{username}:{pw}@ip:port/")
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}
Mongo-Shell (docker):
mongodb | 2022-07-09T22:01:27.305+0000 I NETWORK [listener] connection accepted from ipipip:1437 #7 (3 connections now open)
mongodb | 2022-07-09T22:01:27.310+0000 I NETWORK [conn7] received client metadata from ipipip:1437 conn7: { driver: { name: "PyMongo", version: "3.12.1" }, os: { type: "Windows", name: "Windows 10", architecture: "AMD64", version: "10.0.19041-SP0" }, platform: "CPython 3.8.5.final.0" }
mongodb | 2022-07-09T22:01:27.384+0000 I ACCESS [conn7] SASL SCRAM-SHA-256 authentication failed for admin on admin from client ipipip:1437 ; AuthenticationFailed: SCRAM authentication failed, storedKey mismatch
mongodb | 2022-07-09T22:01:27.419+0000 I NETWORK [conn7] end connection ipipip:1437 (2 connections now open)
mongodb | 2022-07-09T22:01:28.778+0000 I NETWORK [conn5] end connection ipipip:1409 (1 connection now open)
But when I login via a mongobrowser it's working fine
Anyone have any idea?
Please @ on response
ive got
await cur.execute("INSERT INTO tickets (member_id, guild_id, opened, ticket_category, ticket_status) VALUES (%s, %s, %s, %s, 'online')", ctx.author.id, ctx.guild.id, get_now_time(), ticket_category.value)
await cur.execute()
and its raising TypeError: Cursor.execute() takes from 2 to 3 positional arguments but 6 were given but im not sure why, as the statement looks the same as my other ones that are fine.
that was a few hours ago so probably solved by now, but either way:
you have to put the query parameters on a list or a tuple instead of just passing them as function parameters, so ```py
await cur.execute("INSERT INTO tickets (member_id, guild_id, opened, ticket_category, ticket_status) VALUES (%s, %s, %s, %s, 'online')", [ctx.author.id, ctx.guild.id, get_now_time(), ticket_category.value])
or
await cur.execute("INSERT INTO tickets (member_id, guild_id, opened, ticket_category, ticket_status) VALUES (%s, %s, %s, %s, 'online')", (ctx.author.id, ctx.guild.id, get_now_time(), ticket_category.value))
my friend needs help building a website with node js does anyone mind helping
Can someone tell me which website to learn for SQL interviews
Practicing some Google and AWS questions can help me
Any ideas?
Do I need any python libraries for handling a database on my laptop? If there are can someone tell me some of them (thanks anyway)
So i want to make a discord bot with items that a server can create, And i use for i in blabla, so would it be more practical if i create a table for every guild or store every item in one table but with guild id so i can identify it?
what is the smart way of getting the max days between each customer's purchases from a single table that has date and customer_id?
not max-min, but the longest between a purchase and the next
Thanks will try out
Hello everyone, i'm new on the channel and i need help for something
!! I would like install InfluxDB client on python. And i have no clue how to do it simply. Can someone please show me the way ? (I'm french sorry for the accent and syntax, lol) 🤠
I found the github link to get the documentation... but I'm still a bit of a novice. (https://github.com/influxdata/influxdb-client-python)
hey guys! im trying to search a database with criterial of two columns, having a tough time finding the right code. For example I need to show column A and how many times Colum B = the word successful
any help would be appreciated 😄
what do you mean by 'how many times column B'?
so if column B only shows Successful or Unsuccesful.. I want to only show successfull but filter it by Column A say Column A is a department
you can use groupby clause
ok i ran this and it worked, but i have 23 to find out if they are success or un, wondering if there a better way then runing 23 seperate codes
len(july_df[(july_df['Referral Source Type Name']=='PCP') & (july_df['successful']=='successful')])
for group by, would i just individually type all 23 'Referral Source Type Name'?
How to write your text to the 2nd line of the file?
the two columns are Referral Source Type Name and successful, there are 23 referral types and "successful" and "unsuccessful" under the second column
only need to find successful total for each referral type (118k rows)
Is there a way to use a database as file?
Do you mean a saved file on drive?
That's with a lot of databases
yes, .db, .sql, etc
import sqlite3
and just use it
You could have a csv or JSON as a database if youd like as well but things like sqlite can store it in a .db file on drive
!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 an SQL interface compliant with the DB-API 2.0 specification described by PEP 249, and requires SQLite 3.7.15 or newer.
Np
I made a database manager too if you want to try it out helps me create my databases etc
Say I have tables T1 and T2. I want to join them so that I can only get the records from T1 which are unique and not found in T2. How can I do this?
@versed inlet In Sql theres several ways.
If T2 cant have null values, id do something like
left join T1 on T1.id = T2.id
where T2.id is null
If T2 can have null values, id do
where T1.id not in (select distinct T2.id from T2)
Alternatively, you can outer join, but somehow I could never get that to work properly
the id in T1 and T2 cannot be null, but the row itself may not exist in T2. I'm guessing this works in that case as well
correct, a left join will leave a null value, left/right joins are essentially xlookups if youre familiar with excel
Outer join is meant for the exact case you specified, but Im not quite sure on the correct syntax
alright, thank you very much! I'll look into left and outer joins
With SQLite is there a way to format my table to take any negative numbers and set them to zero on insert / update
Heroku Postgres + SQLAlchemy
I have psycopg2.OperationalError: connection to server at "qwertyuiop0" (0.0.0.0), port 5432 failed: FATAL: password authentication failed for user "qwertyuiop1"
when invoking
def add_devlog(self, channel_id, user_id):
devlog = Devlog(channel_id=channel_id, user_id=user_id, archived=False)
self.session.add(devlog)
self.session.commit()
return devlog
code for making session
def __init__(self):
raw_db_url = subprocess.run(
["heroku", "config:get", "DATABASE_URL", "--app", 'pgd-bot'],
shell=True, capture_output=True).stdout
# Convert binary string to a regular string & remove the newline character
db_url = raw_db_url.decode("ascii").strip()
# Convert "postgres://<db_address>" --> "postgresql+psycopg2://<db_address>" needed for SQLAlchemy
final_db_url = "postgresql+psycopg2://" + db_url.lstrip("postgres://")
# Create SQLAlchemy engine
self.engine = create_engine(final_db_url, connect_args={'sslmode': 'require'})
session = sessionmaker(self.engine)
self.session = session()
It's external device so I can't use simple os.environ['DATABASE_URL'] for getting database url for engine
final_db_url looks like postgresql+psycopg2://XXXXXXXXXXX:x6545x54x564x87645xx465x@xx1-23-456-789-012.eu-west-1.compute.amazonaws.com:5432/xxxxxxxxxxxxx
@brazen flower ?
Fixed this error by replacing
db_url = raw_db_url.decode("ascii").strip()
final_db_url = "postgresql+psycopg2://" + db_url.lstrip("postgres://")
db_url = raw_db_url.decode("ascii")[11:]
final_db_url = "postgresql+psycopg2://" + db_url
But got this
FATAL: database "dd9nm8qjb3a3t8" does not exist
But
Are you setting up Postgres for the first time?
yes
its hardly 1hr m started with sql
my sql
m using pop sql
Err, is it postgres or mysql? 🤔
mysql
.
You need to create your database I think
but i have created
ha-ha we have same errors xD
now what should i do ?
Wait for more skilled developers or try to solve this problem by yourself
🥲
i have tried to solve using google but as i am new to database its hard for me to understand thinks
me too 😅
🥲
my values in pandas are type series,
even after I force them to be integers
means I cannot do logs with them even when using np.log which should work on series/arrays
sql question that I feel like I should know but I'm struggling. I'm using a mysql 5.7 and I've an employee id and when the query is displayed I need to put dashes every three numbers. ie 123456789 needs to print as 123-456-789. I know I can truncate and divide by etc and concat it back together but I was wondering if theirs an int parse to string function.
Oracle and MS-sql might have some formatting built in functions for MySQL I guess it’s substring and concat
lmao, I just like having clean code. Thanks
I want to make it so that when a channel is created, 0 (the default value in my column), rises by 1, im not sure how to increase the default value
Is it possible to make an internal database with a python file? (.py) like if I wanted to create a data sheet for companys contact info
How do I get the current prefix of a guild from a database (postgresql)
async def get_prefix(bot, message):
prefix = bot.db.field('SELECT prefix FROM guilds WHERE "guild_id" = ?', message.guild.id)
if len(prefix) == 0:
await bot.db.execute('INSERT INTO guilds("guild_id",prefix) VALUES ($1, $2)', message.guild.id, DEFAULT_PREFIX)
prefix = DEFAULT_PREFIX
else:
prefix = prefix[0].get("prefix")
return commands.when_mentioned_or(prefix)(bot, message)```
That's what I have, but when I do `bot.db.field`, the error message I get is `'Pool' object has no attribute 'field'` . I'm not sure what that means. When I do `await bot.db.fetch` instead of `bot.db.field`, I get a LOT of red lines
Well you can hard code data as constants into a python file, but that's not a "database". If you're going to modify the data, you don't want to hard code it
You might want to consider a config file (ini, toml, whatever) but if literally all your doing is putting an address in a constant in a .py file, there is nothing wrong with that.
If you have a lots of addresses, maybe put them in a CSV for a JSON file if they're not going to change. If you're tracking lots of addresses programaticaly, you probably want SQlite
Amazing that is what I was wondering thank you so much man!! 😁🔥🔥
I'm testing cockroachdb, I installed it and I'm copying data into it... I'm using executemany() and it seems to be going at 250 rows/s. Apparently each inserted row is treated as a separate statement
is there a fast way to import data?
building a CSV file is very inconvenient
Hello, someone who uses Panda to generate csv, do you know how I can do this? , split the value of a column into several rows with the same value of the remainder
what would be the ideal way to access a database from multiple files? I don't want to create a new connection for each request to the API
EDIT: figured it out, same way as JS, one file
hello guys
i dont know python but have to do assessment
Download a Comma Separated Values (csv) file titled shoppingtransactions.csv. This file contains over 7,000 transactions with each row representing a comma separated list of items purchased together in one transaction. Here are some samples rows:
• soup,light cream,shallot
• frozen vegetables,spaghetti,green tea
• french fries
• eggs,pet food
• cookies
• turkey,burgers,mineral water,eggs,cooking oil
• spaghetti,champagne,cookies
• mineral water,salmon
• mineral water
Implement an application in Python that reads in shoppingtransactions.csv and allows users to interact with the application with the following three commands:
- sup item[,item]
- con item[,item] --> item[,item]
- exit
Users will be prompted the menu above until the user selects Option 3. Command 1 calculates and prints the support of an item or a set of two items. For example, users may select Commend 1, then type:
sup Burger
Or
sup parmesan cheese,spaghetti
Command 2 calculates and prints the confidence of an item or two items provided that another item or the other two items were bought. For example, users may select Commend 2, then type:
con cookies --> chocolate
Or
con frozen vegetables --> sparkling water, ham
The only libraries that you can import are numpy and csv. Save your Python code in a file called shopping.py.
can u guys help me with this
its due date is near
For avoiding SQL injection, it is safe by just removing the special characters from the user's input?
Website with the collection of all the cheat sheets of the project.
hey, can someone help me with this sqlmodel/sqlalchemy error i have in #help-carrot ?
Too complicated for me 🙂
Because I am using Google Cloud's BigQuery, I have implemented parameterized queries + removed ; from user's input 🙂
https://cloud.google.com/bigquery/docs/parameterized-queries
A postgres question
I have a table of users and a table of their answers to some questions. I need to join those like that:
first_name | last_name | email | ... | answer_text_1 | answer_timestamp_1 | ... | answer_text_10 | answer_timestamp_10 |```
So I have their info and their answers to each question in one view. There is an arbitrary amount of questions, could be from 0 to like 100.
How should I go about that? Right now I build the SQL query with a cycle in my code, iterating over all questions, but there sure should be a way to do that with just SQL, right?
So I would need to dynamically add columns to the main SELECT clause and join the answers table for each question. Seems pretty tough for me to solve on my own
anyone know a good tutorial of some sorts for a leveling database for discord bots?
do you guys know some discord servers that have discussions/help about SQLAlchemy?
cursor.rowcount and cursor.lastrowid , can someone explain guys
is it bad practice to re-alias a sum with an existing alias in sql?
e.g. I have a chain of left joins, in the first one I get sum(a.revenue) as total, can I do in the next one sum(sum(b.revenue) + ISNULL(a.revenue,0)) as total instead of adding them in the end?
One is the row count, the other is the last row id.
In some cases they may happen to be the same number but try deleting a row and see what happens...
i dont understand in theory how it works
If you have three rows and their IDs are 2, 4 and 6 then the row count is 3 and the last I'd is 6. If that still isn't clear, read up on the basics of SQL
can anyone help me with some database to JSON code ?
OK, using python to talk to a Microsoft SQL database. I installed pyodbc and the ODBC driver. I've made the connection, pulled data, it's working. But I got this warning and I'm not sure what to do about it:
UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
So I found this answer to what to do about the warning and, as a beginner in python, I'm a bit confused on how to proceed.
I'm confused about the relationship between SQLAlchemy and Microsoft's SQL Server. For the moment, the only thing I'll be doing is SELECT queries to pull data into Excel. The most I'll ever be dealing with is < 1000 rows and maybe 300 columns. Is this a warning I can safely ignore, or do I need to start using SQLAlchemy? And is that instead of or in addition to pyodbc?
I'm just confused... 🙂
Hi I am trying to connect to Microsoft SQL, however I am getting the following error. Can't connect to MySQL server on '10.0.99.208:3306' (111)
how fast are SQL queries compared to some containers we normally use
Do you have a firewall from the machine you are trying from.
" <div class=\"thumbnail\"></div>\n" }```
is there a way to store a doc in this format? i am trying to store this in couchbase
why is sql so garbage
how am I supposed to understand what's wrong if the issue just says that An error occurred while executing batch. Error message is: Value to add was out of range. Parameter name: value
Reposting it here cuz I didn't get any response in python general
Hi, I'm using tortoise-orm (pgsql) to connect to database. I'm using it with quart. Whenever I make a query I get this weird error message. But after making the query 7-10 times pgsql successfully executes my query.
OperationalError prepared statement "__asyncpg_stmt_a__" already exists HINT: NOTE: pgbouncer with pool_mode set to "transaction" or "statement" does not support prepared statements properly. You have two options: * if you are using pgbouncer for connection pooling to a single server, switch to the connection pool functionality provided by asyncpg, it is a much better option for this purpose; * if you have no option of avoiding the use of pgbouncer, then you can set statement_cache_size to 0 when creating the asyncpg connection object
I've not used tortoise but this message seems pretty clear, what's the question?
im tryna make a basic login system which uses json data to check if the user is there or not.
import json
def jsonlogin():
usernameinput = input("Enter a username: ")
passwordinput = input("Enter a password: ")
with open("userdata.json","r") as f:
users = json.load(f)
users[str(username)] = password
if password and username in users:
print("Succesfully logged in \n")
else:
print("Invalid Username / password \n")
jsonlogin()```
Right now its always saying login success unless there is nothing inputted.
How can I fix that?
Here is a sample of what the data looks like in userdata.json
```json
{"id":"9","username":"cogborne8","password":"VStasVgDd","email":"nswalteridge8@dmoz.org","access_level":"3"},
Hey y'all, can a table's PK be referenced as a FK in two different tables?
Here I have the zoo_id being used as a FK in both the enclosure and individual_animal tables
How do you validate the passwords are the same?
(it looks wrong)
thats what im tryna do
and im not sure how
how would you describe the check in plain english?
if passwordinput is the same as password in json file then print success
Oh something that may be relevant: users[str(username)] = password means "take the value of password and put it in users[str(username)]"
which does not match your intent
But it does mean you need to find the user where the username matches and then compare their password
@bot.command()
@commands.has_permissions(administrator = True)
async def newcategory(ctx, acctype):
c.execute("""CREATE TABLE ? (
email text,
password text,
)""", (acctype,))
await ctx.send("Successfully created new account type!")
c.execute("""insert into ? values("anything", 'rawr', 10)""", (acctype,))```
c.execute("""CREATE TABLE ? (
sqlite3.OperationalError: near "?": syntax error
Look at the content of users and think about a way to find a specific users. That would be a good start
ok so far I got something a bit like this... though it's giving me an error
import json
with open("userdata.json", "r") as f:
users = json.loads(f.read())
def finduser(user):
user = next(
(item for item in users if item["username"] == user), None
)
if user:
return user["email"]
return None
usertofind = input("User you want to find: ")
print(finduser(usertofind))```
write your line as multiple statements. Keep It Simple and Stupid
also you are using user as different variables, which will mess up things
ok
ok... i came up with this```py
import json
with open("userdata.json", "r") as f:
data = json.loads(f.read())
usertofind = input("User you want to find: ")
if usertofind in data:
print("User found!")
print(data[usertofind])
else:
print("User is not in the json data")
does it work?
(I would expect not to work)
Print the first few lines of data
of the json file?
of the variable data
cool
so
it's a map that has an entry "userInfo" which itself contains an array of user data
thus obviously, data[usertofind] wouldn't find anything
so data[username]?
why?
because we're tryna search in the usernames
Does anyone know how I do it so when I run the ban command (or kick, whatever), the user can't ban the bot from the server?
How does that map to your data?
i mean.. im not sure
#discord-bots i think
In these cases, try to explore data
Look at the keys, the values so they make sense to you and you can understand how to get what you want out of it
i'm confused with what you mean by map and explore data
I mean to think about the structure of the information in data
i mean data is just a variable...
which shows call of userdata.json
wrong chat
Right and you would look for users very differently depending how it store values:
data = [
{name: user1, password: user2},
...
]
is very different from
data = {
users = [user1, user2, etc.],
passwords = [password1, password2, etc.]
}
from other ways to organize it
and the way you currently have it in data is different from the two ways I wrote above
so if you just type data[username], it will means different things
and you would get different results
wait but in that case if i did data[name] would it output user1?
ok but in that case
?
nvm
you can use the function keys() on dictionaries to get the list of keys
That can give you some clues
for firebase security rules, is it possible to only allow a read if the user knows the id?
so for example, it only allows it to read the specific reference for the key that the user has?
anyone know how can i put python code in php i want to calculate with python but i want to fetch data from phpmyadmin
There's no statement_cache_size parameter in tortoise orm
I tried using only asyncpg and statement_cache_size is only accepted by asyncpg and not tortoise orm