#databases
1 messages · Page 149 of 1
show it
No problem
it is a way too though
class Commodity(models.Model):
""""Model for freelancer ingame regular commodities in the shop"""
pod_appearance = CharField(unique=True)
something like this
more complex contraints are required only for a more advanced conditions
yup
ok thanks, ill try that.
it will make error if you will try to insert duplicated data into database
which breaks this costraint
obviously, you will not be able to migrate your db to having this constraint, unless all your data is already unique btw
How do i use SQlite db for an application bot
eg
1-) Mod/Owner sets up the bot with the Guild Id and where he wants the applications sent.
2-) Owner/Mod creates application.
3-) A member of the guild applys for it (eg. ?apply Mod)
4-) The bot dm's him the questions the mod/owner made.
5-) He answers and submits them
6-) the answers are sent to a channel (step 1) with a new number (randomly generated but saved) for the Mods/Owners to review
7-) They can accept or deny the application
8-) Accepting will give them a role and send a message to the user, for denying, it just sends a message.
Try converting time to seconds from some epoch. Then you are comparing two large integers.
does anyone know what this error is on pymongo
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0, 'errmsg': 'Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
I have a question regarding switching from sqlite to postgreSQL. Currently I am using sqlite and open a connection to the database file everytime I get an API call
Is it okay to continue doing that, or is there a way of having a global database connection among all the threads running my flask api?
for user in users:
try:
cur.execute("INSERT INTO badges VALUE (%s, %s, %s)", (user.id, name, emote))
except:
users.remove(user)
failed.append(user)```
I have this code and `badges` is a table with a unique key for `uid` and `name` (first and second column in the table), but for some reason the except only run one time and the other time its working fine but the value just isnt added
Can someone help me with that?
its like I break the for loop for some reason
I think it should be "VALUES", but I could be wrong about htat
thats called a pool but idk if and how its working for sqlite, but for postgresql it should be available for the most libaries
that doesnt matter afaik
lemme try
btw, is user.id your primary key for the database
(1062, "Duplicate entry '431876970322591755-1. Geburtstag' for key 'badges.badges_UN'")
have no primary key
dont need it here
bist du deutsch btw? 🙂
hahahah
Hi all, I'm starting a new flask project and in the past I just used a postgres database, but I'm wondering if doing something nosql like mongodb or cassandra would be better?
One of the criticisms I've seen of SQL is the rigidity of the schema when you want to add new columns to a table for example, but doesn't something like alembic make that a non-issue?
For server based database like postgres it is better to use a connection pool. So you can avoid the connect/disconnect overhead. It should be supported by the library or framework you use.
Yeah thank you, I did indeed implement it with a pool in the end :)
Alembic would make it easier to make the migrations and change schema yes, but I wouldn't consider this as a criticism or disadvantage. Its like writing more code for new features and functionality in a software (i.e. changes will be needed.)
is it possible to store a list in sqlite?
Hello my friends, I have a problem with a SQL query, when I call the main table, I need to add and create a foreign key in the additional one, how can I write the query correctly?
cursor.execute("""INSERT INTO information_users.users_id VALUES ('last_insert_id()')
FROM information_users AS iu JOIN users ON iu.users_id = users.id_users join
users_imunitet AS ui ON iu.imunitet_id = ui.id_users_imunitet"""
)
"database is locked" error
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/Tests-Bot/Cogs/Moderation.py", line 239, in warn
await cur.execute('''INSERT INTO Warnings VALUES (1, ?, ?, ?, ?, ?)''', (ctx.guild.id, user.id, ctx.author.id, datetime.datetime.now(UTC), Reason))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/cursor.py", line 37, in execute
await self._execute(self._cursor.execute, sql, parameters)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/cursor.py", line 31, in _execute
return await self._conn._execute(fn, *args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
result = function()
sqlite3.IntegrityError: UNIQUE constraint failed: Warnings.ID
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/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: IntegrityError: UNIQUE constraint failed: Warnings.ID```
is aiosqlite just having a stroke or did i fuck something up
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "unique"
await conn.execute('''CREATE TABLE IF NOT EXISTS economy_system (member_id unique , wallet bigint , bank bigint)''')
Anyone knows why this would happen?
Don't you need to provide a type for member_id, like int?
Thank you it worked!
could anyone help me with this
@commands.command(help='Warns the user for the specified reason', aliases=['w'])
@commands.has_permissions(kick_members=True)
@commands.guild_only()
async def warn(self, ctx, user: discord.Member, *, Reason='No Reason Provided'):
UTC = datetime.timedelta(hours=-1)
UTC = datetime.timezone(offset=UTC)
con = await sql.connect('./warnings.db')
cur = await con.cursor()
Warnings = await cur.execute('''SELECT Id, User FROM Warnings WHERE User = ? ORDER BY Id DESC''', (user.id,))
WarningsCount = await Warnings.fetchall()
if len(WarningsCount) == 0:
await cur.execute('''INSERT INTO Warnings VALUES (1, ?, ?, ?, ?, ?)''', (ctx.guild.id, user.id, ctx.author.id, datetime.datetime.now(UTC), Reason))
try:
await user.send(f'You were Warned in {ctx.guild.name} by {ctx.author}. This is Your First Warning;\n**Reason/Message:**\n{Reason}')
await ctx.send(f':ok_hand: Warned {user}! This is Their First Warning.')
except discord.Forbidden:
await ctx.send(f':ok_hand: Warned {user}! This is Their First Warning - I couldn\'t DM Them.')
else:
await cur.execute('''INSERT INTO Warnings VALUES (?, ?, ?, ?, ?, ?)''', (None, ctx.guild.id, user.id, ctx.author.id, datetime.datetime.now(UTC), Reason))
try:
await user.send(f'You were Warned in {ctx.guild.name} by {ctx.author}. You now have {len(WarningsCount) + 1} Warnings;\n**Reason/Message:**\n{Reason}')
await ctx.send(f':ok_hand: Warned {user}! They now have {len(WarningsCount) + 1} Warnings!')
except discord.Forbidden:
await ctx.send(f':ok_hand: Warned {user}! They now have {len(WarningsCount) + 1} Warnings - I couldn\'t DM Them.')
await con.commit()
await con.close()
that's the code
@clever bough
What do you want?
Will social miss check our c.w today?
Not the place to ask, but idk.
Perhaps take this to DMs 
go to #discord-bots
its related to databases not discord.py
aiosqlite is having a problem where the database is "locked"
hi
i need someones help
is anybody here using whats app
hello
is anybody using whatsappp
please
tll me
i nneed help
asyncpg is just a driver, i don't think there are any specific learning resources for it as such
learning how to use SQL is a different thing though
you'd only end up using a few asyncpg functions to run SQL queries
sqlbolt is a good SQL tutorial
there's one similar to it specifically for postgres too
actually i think sqlbolt might be better 🤔
hello, just ask your question
asyncpg docs - https://magicstack.github.io/asyncpg/current/index.html
PostgreSQL tutorial (not for asyncpg directly, PostgreSQL SQL syntax tutorial at most) - https://www.postgresqltutorial.com/
SQL syntax tutorial - https://sqlbolt.com/
w3schools tutorial for SQL syntax(I used it and it is pretty good, includes exercises dataview, and examples, with a test at the end) - https://www.w3schools.com/sql/sql_distinct.asp
anand suggestion(pgexercises) - https://pgexercises.com/
Links in this channel that would help:
Using asyncpg with discord.py(I know you are using it) - #databases message
Understanding asyncpg return objects(asyncpg.Record) - #databases message
Explains why not to use f-string, quite important- #databases message
And official FAQ site - https://magicstack.github.io/asyncpg/current/faq.html
**MOST OF IT IS BY ANAND, THANK HIM ** I just organized it a little. For any question ask here or open a help channel (see #❓|how-to-get-help ), and the finest programmers will be there to help!
Learn PostgreSQL quickly through a practical PostgreSQL tutorial designed for database administrators and application developers.
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
is there a concept of "hierarchy" in sql? in terms of, if i have two tables that have the same columns, is there a way to abstract them?
say i got "Y" and "Z" tables that have the same columns, is there a way to declare a table "X" and make both Y and Z tables descend from it?
two tables with the same data is redundancy
Sure there is different types of inheritance.
Can you be more specific, maybe give an example
CREATE TABLE x (
x_id integer,
common_column varchar(255),
-- common columns for all sub tables
);
CREATE TABLE y (
x_id integer,
y_column varchar(255),
-- other columns specific to y
FOREIGN KEY (x_id) REFERENCES x (x_id)
);
CREATE TABLE z (
x_id integer,
z_column varchar(255),
-- other columns specific to z
FOREIGN KEY (x_id) REFERENCES x (x_id)
);
This would be class table inheritance. The primary keys of the sub tables also are the foreign key to the parent table.
no, but there you are establishing a relationship between x, y and z, right?
Only between parent and child
what i mean is table y is : pk id integer, name string, table z is pk id integer, name string
Be more specific
so if these were objects i would do x : pk id integer, name string
gimme a sec ill paste the actual sql code
CREATE TABLE lists (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME TEXT UNIQUE
NOT NULL
COLLATE NOCASE
);
CREATE TABLE categories (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME TEXT UNIQUE
NOT NULL
COLLATE NOCASE
);
What are you trying to achieve? What’s the end goal
they are two different tables, have different data in them
they work differently in terms of code too
and have different relationships
but im writing the daos now, and i realize there are a lot of shared functionality, so i will refactor
so i will make both category and list descend from a common object
or category from list, as category extends the basic functionality of list
so i was wondering if theres a similar way of refactoring tables that have the same functionality in sql
something like:
CREATE TABLE lists (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME TEXT UNIQUE
NOT NULL
COLLATE NOCASE
);
CREATE TABLE categories (
DESCEND FROM lists
);
- What I said and gave example for is exactly what this is doing.
- This is not really necessary. The table lists itself looks like bad design, as you don’t generally store lists but normalise them.
Your overcomplicating this and will just have more trouble writing queries or code for it.
- Isn't "FOREIGN KEY (x_id) REFERENCES x (x_id)" making x_id in Y and Z reference the x_id in X?
- What do you mean?
Which makes the subtables inherit all of X.
yeah but i want to inherit the structure of X, not the contents
or rather, not want, but wonder if there is such a thing
Yeah you can’t do that.
Alright, fair enough, thank you
What did you mean by "The table lists itself looks like bad design, as you don’t generally store lists but normalise them."?
It’s to do with Normal Form
Which states you would want atomic values. So if your storing lists which can be divided then it would break this.
mmm, i didn't quite catch that, my structure is, media objects have a category_id (foreign key) as field, but there's then a list_to_media junction table because a media can belong to many lists
lists are like a kind of "my favorites" grouping in that the user can create as many as they want, and relate any media object into it, and a single media object can be related to many lists, while categories are a hard value of each media, they just happen to have the same exact structure
if it were json it would be:
{
categories:
[
{"id": 1, "name": "Category 1", "members:"
[{"id": 1, "name": "Media 1"....}...],
}
]
lists :
[
{"id": 1, "name": "Favorites", "media_ids": [1, 2, 3, 4]}
{"id": 2, "name": "Favorites 2", "media_ids": [2, 3]},...
]
}
Yeah I see but your initial table didn’t show that so well. The name of the table lists is not super obvious as well as it what it’s doing
oh no problem man, im just asking, i realize i didn't post the entire thing. So there's no bad design with the "lists" tables, but i should change the name to make it less confusing?
maybe user_groupings or user_lists?
Sure. And for many to many you would need to have a composite primary key.
whats that? im using this right now:
CREATE TABLE lists_to_media (
LIST_ID INTEGER REFERENCES lists (ID) ON DELETE CASCADE
NOT NULL,
MEDIA_ID INTEGER REFERENCES media (ID) ON DELETE CASCADE
NOT NULL,
UNIQUE (
LIST_ID,
MEDIA_ID
)
);
Yeah that’s fine.
Maybe make them both primary composite keys
See that example
thx!
CONSTRAINT bill_product_pkey PRIMARY KEY (bill_id, product_id)
so basically im using the composite of the foreign keys as a primary key
instead of my UNIQUE( constraint?
if you are in ORM (Django), I have alternative how to do that
class CountryAndHub(models.Model):
country = models.ForeignKey(
Country, on_delete=models.CASCADE, db_index=True)
hub = models.ForeignKey(Hub, on_delete=models.CASCADE, db_index=True)
priority = models.FloatField(default=1.0)
visible = models.BooleanField(default=True)
class Meta:
verbose_name_plural = "countries_and_hubs"
constraints = [
models.UniqueConstraint(
fields=['country', 'hub'], name='unique_country_hub')
]
with meta field we could make compsite unique contraint too there
plan on implementing it on django in the future, im doing this project to try several new things, but im not at that point yet, right now im building the data structure and implementing a dao that can work on different dbs
what does your code do?
isn't it just a django implementation of what i posted?
essentially yes
it is exactly the same as you posted
if we would remove priority and visible attribute
and rename it to your thing
yep
we would receive your lists_to_media
its funny doe how its implementing the constraint with the Meta class
like i assume the class name could be anything? or is "Meta" a keyword?
does django extends python like it does html?
so its doing some kind of fancy inspecting/interpreting
it detects Meta is class within a Model class
yup, new level of abstraction!
as I read in previous book, you can solve any programming problem with additional levels of abstractions
except the problem of too many abstractions
sicp tier shit hahah
Can anyone help me connecting to elephantsql?
Isn't it DELETE
Was I correct?
Oh great
Had a doubt with django and postgresql
Could anyone suggest how they go up with this?
Can anyone please help me connecting to elephantsql? I am trying to connect to it, I have already made an instance, and went on his data, and in create_pool I entred:
user = username shows under "User & Default database", password = Password shown under "Password", database = database shown under "User & Default database", host = The link shown under "Server"
error:
https://paste.pythondiscord.com/todutuzonu.sql
hey guys, can any one help me to convert a couple of df from a pickle dictionary to jason / thanks
when i create a new folder, i added the folder to the path of where the data is being stored. when i press next the folder is deleted and gone
and i couldnt find the folder
postgresql
ping when response
Although you can store array elements, you will be violating the basic rules of relational databases. So you should try not to store it as an array, and instead create another table to store the data. So each column is atomic.
The rule you're violating is called first normal form and which is the first step in database normalisation.
Database normalization is the process of structuring a database, usually a relational database, in accordance with a series of so-called normal forms in order to reduce data redundancy and improve data integrity. It was first proposed by Edgar F. Codd as part of his relational model.
Normalization entails organizing the columns (attributes) and ...
Is it allowed to store "lists" like that:
guild_id | word
---------------
123 | hi
123 | hihi
And than iterate through all of the rows with guild id 123 and convert it into a list of my own?
Yes exactly, How do you think I should go about storing this?
How do I use sqlite for discord.py??
I think sqlite is already async, so check their docs mainly
👍🏻
I told you. You can create a new table.
Like what he has done here #databases message
Alright then that is
A new table with the message ID and user ID
Cool I guess this won't cause any issues for 3-4 years if it scales I gotta rethink later :p
At the moment your list is representing multiple entities of a type. This list can be divided further right?
Hello, I'm trying to fetch a large number of values using the same key from MongoDB and place them into a List, but i cant figure out how, I dont really have code or an error because I just need help figuring out how to do a thing, not resolve an errror
For example, if a Product has multiple colours and we want to store these colours we could do it as a list like [red,blue,yellow]. But we see we can divide the list into three separate colours. So you make a new table with columns product_id, colour. And then store each colour seperatwly on a new row. @autumn condor
This brings so much more benefits such as easier querying/aggregation, ensuring data integrity and making it easy to manage what colours a product has.
Yep
Ah okay I've worked with SQL, but majorly NoSQL and my work so far with SQL has been with less amounts of data. And currently what I'm building can easily go up to a lot, so had concerns
Thanks! Now I'm a bit clear
You might want to look at examples online of similar database schemas, or just to get the idea of how other people structured it. There is a good site for templates here, so you might want to check if it includes something you can use for ideas. https://drawsql.app/templates
Oh this looks nice, didn't know about it thanks!
I've got a daily data extraction process that pulls about 10 files, cleans them and dumps them into GBQ as a data lake. One of these files for example averages about 600k rows of delimited data, with 20 columns
This process runs inside of a container in google compute engine and runs daily
would it be more time & cost efficient to drop any unused columns with python during the cleaning phase before the df is uploaded from the container to GBQ or drop it via a sql command in GBQ
I'm wondering if dropping such a large column from a df would cause a major performance / time increase on the compute engine
!d sqlite3
How do I use aiosqlite for discord.py
It's pretty much the exact same you would normal sqlite but with async and await
so would this work?
:/
Any documentation?
https://sqlbolt.com/ (for SQL help)
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
ty
And just to check they still work with discord.py right just that i need async and await right?
yeah discord.py doesnt really change anything
its just the async await stuff that changes it
hey can someone help me with mySQL?
what's the issue
I wanna download mySQL
Windows (x86, 64-bit), ZIP Archive
Debug Binaries & Test Suite
Windows (x86, 64-bit), ZIP Archive
which of these two I should download, I just started database
zip
im using pymongo to save a channel id of a server:
x = col.insert_one(dic)
await ctx.send("done")```
but how would i get the channel id by the server id?
await col.find_one({"channel": guild_id})
this is what i tried ^
but it returned "None"
by default it does in ascending order
you need to do DESC for decending
at the end of the query
how could i add a value to an array(the array is loaded from a json file)
So I have a 2700000000000 of strings, all I need is just do simple queries of another strings to find matches, what db type would be the best for this?
Maybe some simple threaded cpp program to find matches from plaintext would be faster than any sql db for this?
HI, I have a scenario. I am using Django and I need to implement a function similar to this.
Suppose I have coordinates of a group of devices. I need to find devices located within a particular radius of a given coordinate. I was thinking of looping through all the coordinates and calculating distance and comparing it with the radius. And it returns the qualifying coordinates.
But there should be better way to do this right, I f there are a lot of coordinates, then this method is not efficient. Can anyone help me??
look into PostGIS
Hey Anyone there?
username = self.textEdit.toPlainText()
password = self.textEdit_2.toPlainText()
self.Database()
cursor.execute(
"SELECT * FROM customer;"
)
print(cursor.fetchall())
cursor.execute(
"SELECT * FROM customer WHERE username = ? AND password = ?;", (username, password)
)
print(cursor.fetchall())
conn.commit()
And this is the output
[(1, 'FirstUser', 'First', 'User', 'FirstUser', 'firstuser@user.com')]
[]
I'm searching for FirstUser but it's not getting found
im using pymongo to save a channel id of a server:
x = col.insert_one(dic)
await ctx.send("done")```
but how would i get the channel id by the server id?
```await col.find_one({"channel": guild_id}) ```
this is what i tried ^
it returned "None" tho
{guild_id : the guild id, channel: channel id}
You'll need to detect and get the ful dict
If you'll do:
data = await col.find_one({"guild_id": ctx.guild.id})
It'll return the full dict that contains this data
@jaunty galleon Any ideas about what I can do to fix this issue?
Hello there. Last times I used sqlalchemy. Now i figured out, that there is an flask-sqlalchemy library. But i don't figured out how I can set the create method in an extra Database.py file. I used to create a Method in an Database file so all my database settings are in one file. It seems flask_sqlalchemy needs the app statement wich i can't call from an other module?
OKay
It's working now for some reason @bitter yoke
I don't even know if I changed anything in the code
Did you change the data in the sqlite db? Or changed nothing?
Hi.. is there a way to store many to many hierarchy in RDBMS (not Graph Database) where a child can have n numbers of parents and some parents can be childless as well.
i sort of gave up on using flask-sqlalchemy for that reason -- i found it way too weird (or maybe impossible) to use it if I also wanted to use some of that db code from non-flask-related modules
Okay, thanks for that view. I think I'LL keep using sqlalchemy then, too.
are you using the ORM or just core in SQL Alchemy?
I'm using the ORM. Building relations and tables.
Then you might still consider the Flask-SQLAlchemy thing or not -- what it really does for you is manage the Session objects based on Flask's threads and requests, which is a handy thing compared to doing it yourself -- i just ran into this last week and it was pretty frustrating for me too
here's a pretty long article with way more info than you need about someone else who decided to skip Flask-SQLAlchemy:
https://towardsdatascience.com/use-flask-and-sqlalchemy-not-flask-sqlalchemy-5a64fafe22a4
you can make tables that'll store that kind of relationship, but it can get pretty tough to query them in a clean way
Have you explored how your can integrate session management with SQLAlchemy in flask without using Flask-SQLAlchemy. I like SQLAlchemy and it’s much easier to use than Flask-SQLAlchemy.
Yes but there won’t be any foreign key referencing to primary key in the same table..
if I recall, that's basically what the author of that article is exploring -- in my case, I was only using core and I didn't need to get fancy with sessions and ORM so I cheated, very badly
so am I understanding that also, in this case, the parents and children are the same "things" -- one table of "things", and they're "parents" if they happen to have children, and they're "children" if they happen to have parents
just the name of the clumn
Session handling is very nice by using normal sqlalchemy
Yep.. that’s how it is. Everyone is a parent. But if the parent doesn’t have a child than we have a single entry with null child, otherwise parent Id would get repeated to manage all the child’s of it in each row.
so if there's a 'thing' table with 'id' and 'name', you could have a 'thing_relationships' table with parent_thing_id and child_thing_id, I think --
Yes but then there would be relationship id as primary key in thing relationship table.. which I am okay with by the way.
But how would I define the relationship in SQLAlchemy so I can go to any depth of a parent’s tree. It’s relationship is like DAG. It’s acyclical. If a parent has a child, that child cannot be the parent of its own parent which I hope makes sense in a hierarchical model.
Right -- so
this sounds terribly familiar, although I can't remember where I ran into it
i think the tables we discussed there are one of the only ways (if not the only way) to really store these relationships in an RDBMS
and querying them is hell
and I have basically no idea how SQLAlchemy could be taught to understand them
Querying is exactly what I am trying to figure out here. I am not even doing any CRUD operation in this database. It’s for reporting and it’s a frequent requirement from business it get the descendents of a parents. I work in telecom and that’s how circuits are defined. You have a 100g pipe, which is broken down into smaller pipes. And we use 5 or 6 such pipes to connect point a to point z
it's (unfortunately) a genuinely interesting problem
there might be a known "clever" way that I'm not aware of, but forgetting about SQLAlchemy for a second --
if you were just doing this with SQL by hand, can you think of a way that wouldn't require you to run a query, check if there were children, run another query, check again for children, run another query, etc?
No problem.. I’ll figure something out. I know I am missing something here.
There is the concept of association table but I am not sure how I would use it I define relationship
That makes sense.. I am not sure how cost effective it is. Let me try that
i don't think it's going to be efficient at all, I just can't think of a way around it
it'd be a great use of a graph database, though
easy enough to get "all children of thing X" or "what is the parent of thing Y" in a single SQL query, but the arbitrary-depth thing stumps me without looping and doing multiple queries
if you only need the info one "level" at a time like that, though, it might be fine
It would break my ORM, all my objects are in RDBMS 🙁
yep, my only gut feeling there is maybe, maybe
if the ORM can be told "this is a many-to-many relationship"
and you can ensure you never tell it to "follow all relationships", but instead exert some control over which ones it follow at which times
it could be possible
What do you mean by which one it follows at which times?
so if you have an object for thing X, you'd like to able to call getChildren() on it
Yep
but also getParent()
and if i'm not mistaken, in SQLAlchemy you're likely to quickly find it following all parents and children of everything
until it runs out
But why would it work quickly, it’s a recursive query. Sorry I meant all decendents not just children.
Can you please quickly cover what you mean by this, I didn’t get it
i mean if you say getChildren, and SQLAlchemy gets the children -- won't it also get all of their children, and all of their children, and all of their children
and since each child has a getParent, if would get that parent, and its parent, and its parent, and all of their children
That’s where lazy and eager loading comes in
yep
so that's what I meant by making sure you have knowledge and control over when it does and doesn't traverse the relatonships
because it's potentially a big eager load
yep we're on the same page
there are people on pages I've googled that seem to be doing this in SQL Alchemy, but so far, they're not really quite doing the same thing
i'd say if you can convince SQL Alchemy that you've defined a many-to-many relationship that just happens to have the same type of object on each side, and you're careful with lazy/eager, you may just have a solution here 🙂
sounds like you've got a bit more SQL Alchemy experience than I have, too, so hopefully it's easier than it sounds to me
Yep. That’s where I am. Just need to figure out the relationship at the moment.
Also have you ever tried to connect 2 databases like RDBMS and Graph in one ORM
If it’s a possibility it will solve most of my problems
😩
Nope, and I hope to never have to try
I've had (for instance) an RDBMS with its ORM, and also (say) some NoSQL database (or more than one)
but the interactions between them were all "our code", not anything we could ask the ORM(s) to do declaratively
like, a vague memory of a "user" object from an ORM-with-MySQL from a central company-wide user DB, but for some specific app, a NoSQL record of "user preferences"
Yes.. that’s would require a lot of effort to to that. Not even sure if SQLALachemy even has the dialect fot Graph databases
i think it only supports RDBMS
yep.. alrighty back to the drawing board. Thanks mate!
in fairness, we always quickly realized that even if we could cram it all into one ORM-like thing, really you'd lose out on the differences between the SQL, NoSQL, Graph, etc models that made you choose them anyway
yep, good luck -- I hope it stays fun 🙂
I know ORM is basically NoSQL just more rigid.
Cheers!
Actually NOSql ain’t rigid at all. Bad anology. Lol
hm, actually -- just stepped away and thought of something -- this is arbitrary in depth but a child can't have two parents, right?
No it can. That’s the challenge.
oh, yep
i just took three steps and said "wait was this defffinitely many-to-many"
oh well, it was a nice thought for 30 seconds
Yeah..
I’ll keep you posted if I find something
Just in case you might need it later
i'll honestly be curious just for the sake of knowing 🙂
👍
yo
class User(AbstractUser):
money = models.IntegerField(default=1_000_000)
def __str__(self) -> str:
return self.email
class Transaction(models.Model):
class Types(models.Choices):
SELL = "Sell", _("Sell")
BUY = "Buy", _("Buy")
share_type = models.CharField(max_length=4, choices=TransactionTypes)
owner = models.ForeignKey(User, on_delete=models.DO_NOTHING)
currency = models.ForeignKey(Currency, on_delete=models.DO_NOTHING)
shares = models.IntegerField()
max_value = models.IntegerField(default=0)
date = models.DateTimeField(default=timezone.now())
class Currency(models.Model):
name = models.CharField(max_length=10)
value = models.IntegerField()
Any idea how i can design database to currency exchange www?
what should i add?
add a WHERE clause with the condition you just said
the WHERE will come before the ORDER BY
yep
WHERE invites >= 1
yeah
in sqlalchemy orm, if i delete all rows it resets pk to 0, is there a way to stop this? column is currently ```py
challenge_id = Column(Integer, primary_key=True, index=True, autoincrement=True)
thanks
im guessing it has something to do with index=true but im not sure
Yo I'm new to dbs.. so how do I check if a certain value exists in a column or not?
select exists (select * from table_name where column_name = value);
It returns value of 1 or 0
Ah i see
I was trying out the introductory SQL restore tutorial at https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=ssms and I ran into an issue, I hope the images below will help explain the issue.
More context
i was trying to read pickle in python as pandas but im getting the error as this. ive been reinstalling updating pandas, pickle module and even though i cannot find a solution for days now. help me please. thanks.
When ordering data would be more efficient to store it already ordered instead of ordering by order by statement?
Why do you want to take all this extra work in ordering yourself. Such a pointless thing to do.
Also the first rule of normalisation states, any ordering of the data must be defined by the data and not by the physical ordering of the rows.
And SQL is based on idea of sets, meaning that the only ordering you should rely on is the one you give in your query.
ok and then how would i make it extract the channel id saved in it tho?
x = col.insert_one(dic)
await ctx.send("done")```
i have this to save a channel id of a channel a user mentions, now i want to make a command that can fetch the channel id and send in it a message, this is what i have for that:
```data = col.find_one({"guild_id": ctx.guild.id})
print(data)```
it prints out the guild id + channel id + the object id, how can i make it extract just the channel id?
using pymongo btw, im very new to mongodb in general
it prints this:
{'_id': ObjectId('OBJECT_ID_HERE'), 'guild_id': ACTUAL_GUILD_ID, 'channel': ACTUAL_CHANNEL_ID}
how can i isolate "ACTUAL_CHANNEL_ID"?
@proven arrow what if i wanted to edit the value of the channel id
from the channel id to something like 0000
is there like a col.edit_one() or col.update_one()
For that there is update_one
ty
what are like the arguments that i need to place for that?
x = col.update_one(dic)```
this doesnt work for sure
First arg is the condition, ie, whatever you give for the corresponding collection.find
2nd arg is the new value
See here for an example. You need to use the $set as the key for the new values. https://www.w3schools.com/python/python_mongodb_update.asp
Hey! Does anyone here have experience with SQLAlchemy? Specifically experience with getting the data, submitting data and displaying data on the webpage
I need someone to guide me through setting it up and making it work with my app
in mongodb how do i sort by the size of a list?
I am a bit lost in the sauce. I am working on a pipeline that will ingest data ( XML files, EDI ). This data is shipment status data, and to specify these aren't shipments that are going to your door, but full out containers on ships. So the number of these shipments is drastically lower, than something like amazon to your door. The goal is to build an app that the client can go to and see the status of there shipment, currently done using PowerBI. What I am thinking is since this data is coming in XML format, I can easily convert it to JSON and use a no-sql database for example firestore. Where each document is the order-id, and as we get these updates the document would be updated ( Again not a lot of updates happening to the document at once time, maybe a decent amount of reads depending on how many people are checking up on the status). What do you guys think, would a no-sql database be good for this or would a sql database be better for this app. This data at some point will go to a datawarehouse, but it being sql/no-sql really makes no difference for me with this.
@late tinsel can you elaborate more on the use case? Is there any compelling reason not to just have a bunch of XML files on a filesystem somewhere?
Also PostgreSQL (a popular relational database) has an XML data type with functions for querying data from XML documents https://www.postgresql.org/docs/current/functions-xml.html
i recommend against trying to generically convert the XML to JSON just so you can put it in some document database, unless you're very confident that the format can be converted without messing things up
either way it will need to be converted into some format
Since it will go to a data warehouse
ideally you'll be storing the original XML somewhere anyway, since it's a data warehouse
https://www.ibm.com/docs/en/scbn?topic=standards-315-status-details-ocean it looks like there's some standard way to encode this EDI data in XML then?
<CarrierSCAC>CHSL</CarrierSCAC>
<CHRLoadNumber>102388305</CHRLoadNumber>
<Mode>OCEAN</Mode>
<ShipmentStatus>
<StatusName>VD</StatusName>
<StatusDate>20210429</StatusDate>
<StatusTime>0000</StatusTime>
<DateTimeQualifier>ACTUAL</DateTimeQualifier>
<StatusLocation/>
<StatusCountryCode/>
<EquipmentNumber>ABCD7723925</EquipmentNumber>
<EquipmentStatus>LOAD</EquipmentStatus>
<EquipmentType>40FT</EquipmentType>
</ShipmentStatus>
<ReferenceNumbers>
<ReferenceNumber>
<ReferenceQualifier>SHIPMENT NUMBER</ReferenceQualifier>
<ReferenceValue>102388305</ReferenceValue>
</ReferenceNumber>
</ReferenceNumbers>
<ShipmentStatusDetails>
<VesselName>NYK TRITON</VesselName>
<VesselCode>9356713</VesselCode>
<CountryCode/>
<Flight_VoyageNumber>086E</Flight_VoyageNumber>
<LadingQuantity>10</LadingQuantity>
<LadingUOM>CTN</LadingUOM>
<NumberOfPallets/>
<Weight>15522</Weight>
<WeightQualifier>GROSS</WeightQualifier>
<WeightUnitCode>KILOGRAMS</WeightUnitCode>
<Volume>17</Volume>
<VolumeQualifier>CUBIC METERS</VolumeQualifier>
<HazMatIndicator>N</HazMatIndicator>
<SpecialHandling/>
</ShipmentStatusDetails>
<PortOrTerminals>
<PortOrTerminal>
<PortFunction>PLACE OF RECEIPT</PortFunction>
<PortName>Port Ningbo</PortName>
<PortCountryCode>CN</PortCountryCode>
<PortStateOrProvinceCode/>
<EstimatedDate>20210326</EstimatedDate>
<ActualDate>20210326</ActualDate>
</PortOrTerminal>
<ActualDate/>
</PortOrTerminal>
</PortOrTerminals>
</ROOT_ShipmentStatus>```
Is what I will be getting ( example, sorry if I pasted wrong format )
But this can easily be converted to json format
you can use 3 ` characters to make it a "code block"
```xml
<ROOT_ShipmentStatus>
</ROOT_ShipmentStatus>
```
update hehe
and you can add xml after the ``` for syntax highlighting
The idea, is I will need to query for this data as it is coming.
yeah this can be converted to json without too much pain. and yes, you could then dump the json version into mongodb and do fairly arbitrary queries against the data without having to worry about flattening it or whether your relational database supports xml or json
Or as people want the status to be more exact
so what's an example of a query you would want to perform?
this could be flattened to relational tables if you wanted, which would be great for doing analytics queries in the data warehouse
Realistically it would be for 4 areas, Did the shipment leave the dock, did the shipment arrive at dock, did the shipment pass customs, and did the shipment arrive final destination
Then this data would be moved to a data warehouse
Which is a whole animal of its own, as they currently have it on the same MS SQL server as there SAP b1
Trying to move it somewhere else, but at the same time need cost effective, but not shooting ourselves in the foot. They want to use snowflake, but that is overkill as well <50 Gb
lol
so the flow would be something like:
- user requests a status check for shipment 12345
- your app fetches the status of shipment 12345 which is returned in this format
- your app saves the raw xml to a blob/file store, extracts the status of the shipment, then forwards the data to the data warehouse
- your app reports the status to the user
is that right?
So, the data doesn't come through the App, the Cargo companies send us this data through sftp. We would load this data somewhere
After data is loaded or placed where ever.
Then the user would:
- Request status check for shipment 12345
- App fetches data in whatever format it is
- Show information in pretty format and time line like chart
- Money
So the app is more so just for checking the shipment status, where we will be collecting the data from the Cargo Vendors
No other input, maybe an area to escalate to check for more info
Whats the best data base for storing information?
What kind of information.
Like variables and levels for discord.py
sqlite
@late tinsel will you want to flatten all this to a relational table for the data warehouse anyway? or are you intending to leave it as a structured "document" in the warehouse?
Any others?
not with the same desirable properties as sqlite:
- included with python
- the entire database is a single file
- doesn't require a separate server running
- uses sql for querying, which is mostly standardized and therefore has lots of learning resources online
i was not aware that they had a database
Me too, I found out like 2 days ago
however i would not use repl.it to host a discord bot or to store data
it's not what their service is for
oh kk
@harsh pulsar I will be most likely looking to flatten these files. However doing something of a data lakehouse has crossed my mind, since I have been debating using databricks to replace any ssis pipelines and future pipelines, allowing for easier repository of all pipelines in one place versus each server has it's own ssis packages to maintain and region. Kind of centeralize all of it.
databricks is cool but it's a very big can of fat slimy worms
i wouldn't recommend it here
haha, I come from big data
And these guys are looking to collect everything
So it make sense from a pay now, versus pain later
plus spark isn't too bad to learn.
They want to utilize SAP b1, but abstract out a lot of the workflow by creating apps/power apps
Also start doing things like forecasting etc
But none the less, I am used to handling consumer data
So different mindset
i haven't ever used ERP software so i can't comment on b1
Realistically I think for there needs a postgres based data warehouse would work, or even maybe something like singlestore ( memsql ), since it is similar enough to snowflake, and especially using something like databricks, changing out the database is easy
You just change the sink realistically or can even do the data lakehouse and just cram everything into blob storage
abstracting away from the tooling, this is what i personally would feel good about:
- sftp upload -> data lake, xml files
- data lake, xml -> data warehouse, normalized relational data
- data warehouse -> app database (optional, omit if the data warehouse can handle queries from the app)
My original Idea for the data warehouse/data lakehouse was utilize
- SQL to Blob storage via ADF in azure
- Blob Storage to data warehouse/data lakehosue via databricks
i assume you meant XML in 1?
Im talking overall, so it will be a mixture of SQL ( SAP B1 ), XML from Cargo vendors, and APIs as well from where ever else
ah, hm
The worst thing about the SQL is that each region has its own sap b1 setup
So all of these will need to transformed into similar format via some form of pipeline either way, then converted to a dimensional model
The apps are more so for workflows, status updates etc
So it is weird for me because it is a mixture of oltp type apps, and olap type apps
honestly you know more than i do 😛 so all i will say is that from the data scientist perspective, just keep the original XML files somewhere and don't be surprised if one day someone actually wants to access them
Oh yeah, im a data engineer
Always keep raw format data somewhere.
If a data warehouse ever needs to be rebuilt, boom
its all there, if something isn't looking right, boom original is there
history as well
etc
yep exactly. what i will say is that at my last DS job, the data engineers used azure data factory and databricks for all the ETL, and databricks/dbfs itself was the data lake
My last place, we convereted a lot of data to either parquet or avro, but they would have to claw the raw file archive from my teeth lol
saved my ass so many times
hah exactly
Thats also including all the times a pipeline wasn't designed to add new columns lol
so the data that's in b1 is already in b1 and you aren't looking to migrate. but you are looking to ingest data from a bunch of heterogeneous sources into this data lakehouse, and then hook some of it up to an app (among other things)
Yeah
while creating apps that can talk between sap b1
and themselves
a lot of mixture of olap and oltp work loads
Literally just finished making app for ceneralized product code generation
Since codes were getting reused and causing issues lol
is databricks suitable for oltp? i would imagine not
as for the data ingestion and warehousing, that does definitely sound like an adf/databricks use case. i haven't used snowflake but from what i hear it seems like a similar niche
Yeah ADF would be used to pull data out of sql
or sftp
Databricks would process it and either act as the warehouse, or push to snowflake
Pretty standard
i thought snowflake could do its own processing? having both databricks and snowflake sounds expensive
It can
Really depends what you are looking to do though
Databricks is pretty much just spark
So calling API's, enriching data etc is easier writing a python script
Albiet snowflake can call functions now anyhow, it's not the same.
Plus databricks integrates with damn near anything
So spark for the data proccessing, and then snowflake for the data warehouse
you dont need (or want) all the stupid notebook junk
Yeah, I can just use jupyter notebooks lol
Plus most people just write sql and then use something like tableau from my experience.
At least in the analytics we performed
so how does the data get stored in snowflake? it has a sql query engine?
My biggest goal with utilizing spark, is to get the fuck away from ssis
Yeah, you ever heard of redshift or bigquery?
yeah, used for very small things but never professionally
It is just a database designed for olap workloads
in essence
So bigquery, redshift, snowflake all in the same family
ah got it
so you'd probably have to dump that out to another database to hook the app up to
Yeah, for anything involving transactions or single record queries a sql/no-sql db should be used.
Snowflake is pretty strictly olap
So analytics workloads, big data etc
so your original question was whether to use nosql or sql? id personally always go sql if possible, postgres specifically just for the flexibility and huge feature set
Crazy expensive, as well as probably not as responsive to be quering something like Snowflake for user account data
I was thinking of using postgres, but at the same time I feel like maintnance would fall onto me
So I would probably see if azure has a managed service version of it, which they probably do
...is there an alternative that lets you push the maintenance off to someone else
anyone here good with pymango
yeah im pretty sure azure has a managed rdbms offering, maybe not postgres specifically
probably some mssql thing....
haha the other thing I can use is ms sql
since they already have people maintaining, but I want to get away from ssis
Which, if it is there, there will be someone using it lol
do you have to use ssis if youre using mssql?
oh, you want to get everyone away from it
Yeah, I am a firm believer of do it 1 way.
That way you don't end up with like a million different proccesses, different tooling, etc
You can move people around etc
Train once, and you are good
versus train the person everytime they move deparments lol
idk if this is any better, you might end up with vendor lock-in
yeah thats a big plus
They are 100% already going for vendor lockin
Looking to get rid of internal emails and use Teams
PowerApps
etc
ah the ole microsoft bought the vp dinner
I mean you can't beat ms when it comes to enterprise and integration.
It's like apple, shit just kinda works
yeah for sure. azure sql database seems like a good option then
oh thats way better
Yeah, I prefer postgres over ms sql
$0.10/GB/mo + $25/mo for a single core
Have to review, because these fuckers will get you with costs everywhere haha
Like network egress
what would you use to keep the app db in sync with the data warehouse?
nightly update from the latter to the former?
Depends on what is needed in the data warehouse
If a nightly is fine, adf can do it
Really depends on the data, we have had pipelines that push data from a queue to a SQL server as well to the data warehouse at the same time.
Queue -> 2 cloud functions ( GCP )
- Cloud function for ingestion into SQL
- cloud function for ingestion into bigquery
Others have been in the case of ms sql, is secondary replica
Secondary replica is updated within seconds, and is read only, there the data can be queried and moved to data warehouse without impacting main server performance
makes sense
Many solutions to the problem
good to know this stuff, i dont ever want to have to do it myself but its come in handy often to be able to at least sketch out a solution for someone
All depends on how much time and money you wanna throw at the problem haha
I feel like DS peeps should know some of DE
If not, thats how you get a million and one jupyter notebooks and not all the data you need.
Why the previous place I worked at went for a data warehouse, because they had like 50 different data sources, and no one knew what data existed and where. Made the DS guys less effective
Also, we were able to model the data into a format that made the DS guys very happy haha
They didn't need to wrangle anything, just do there magic haha
yeah i enjoy knowing enough to "be dangerous"
i can spin up my own postgres server, do my own web scraping, write my own api clients, etc. but when things get serious i really do want to hand it off to someone so i can focus on the actual ds work
then again im just a swe in my current job anyway so apparently i went the opposite direction...
asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "VARYING"
What this error mean?
@torn sphinx it means your query has incorrect syntax. post the code
How to import mySQL database driver to python?
Okay 👍
I fixed it tho, thanks :)
Hello, Any Python Libraries available for neo4j which supports optimistic locking of nodes like spring-data-neo4j?
How to handle concurrent transactions happening through python which might update same nodes simultaneously, which need to perform locking and avoid deadlocks and race conditions?
Was this suggestion for my question?
hi
i am learning python
anybody interested to learn it with me
today's topic function
if you are learning than you should first take a tutorial online or a class with others (remote of course)
Hello
!mute 829895458855059456
:incoming_envelope: :ok_hand: applied mute to @ripe moat until 2021-05-12 14:41 (59 minutes and 59 seconds).
async def func_bitcoin():
while True:
db = cluster["CapBot"]
collection = db["bitcoin"]
users = await get_bitcoin_data()
exchange_rate = users["exchange_rate"]
if exchange_rate < 60000:
if exchange_rate > 40000:
users["exchange_rate"]+=random.randint(0,500)
users["exchange_rate"]-=random.randint(0,500)
else:
users["exchange_rate"]+=random.randint(1500,2000)
else:
users["exchange_rate"]-=random.randint(1500,2000)
collection.replace_one({"id":1},users)
await asyncio.sleep(60)
this is pymongo
!paste
the collection.replace_one() is running but it doesn't work, it doesn't replace
there's no errors either
try to use _id instead of id
And be sure, that this document has _id == 1, not ObjectId or smth else
also, replace_one is awaitable method. You should use await collection.replace_one(...)
bru typo moment? lemme check
if you are using motor here, for sure
omfg i actually did a typo
pymongo.errors.ServerSelectionTimeoutError: dsbot1-shard-00-01.fl8o7.mongodb.net:27017: [WinError 10054] The remote host forcibly dropped an existing connection, connection closed, dsbot1-shard-00-02.fl8o7.mongodb.net: 27017: [WinError 10054] The remote host forced an existing connection, Timeout: 30s, Topology Description: <TopologyDescription id: 609bf8ffa44b31621c7a9bd4, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription.net ('dsbongbod8-s ', 27017) server_type: Unknown, rtt: None, error = AutoReconnect (' connection closed ')>, <ServerDescription (' dsbot1-shard-00-01.fl8o7.mongodb.net ', 27017) server_type: Unknown, rtt: None, error = AutoReconnect ('dsbot1-shard-00-01.fl8o7.mongodb.net:27017: [WinError 10054] The remote host forcefully dropped the existing connection')>, <ServerDescription ('dsbot1-shard-00-02.fl8o7 .mongodb.net ', 27017) server_type: Unknown, rtt: None, error = AutoReconnect (' dsbot1-shard-00-02.fl8o7.mongodb.net:27017: [WinError 10054] The remote host forcefully dropped the existing connection ')>]>
how do i fix this?
Helllo help me
IN sql
Send your question
I need to List the employees with the lowest salary per each department
FROM employees e, departments d
WHERE e.department_id=d.department_id and salary IN
( SELECT MIN(salary)
FROM employees
GROUP BY department_id);```
sql
SELECT first_name, last_name, salary, department_name
FROM employees e, departments d
WHERE e.department_id=d.department_id and salary IN
( SELECT MIN(salary)
FROM employees
GROUP BY department_id);```
Result is not okey because I am getting several different employees in same department
You want the lowest one?
List the employees with the lowest salary per each department
As I understand I should get employee who has lowest salary in that deparmtnet
switching to JOIN syntax because i think it looks better in this case:
SELECT
t.employee_id,
t.first_name,
t.last_name,
t.salary,
t.department_name
FROM (
SELECT
e.employee_id,
e.first_name,
e.last_name,
e.salary,
d.department_name,
ROW_NUMBER() OVER (
PARTITION BY d.department_id
ORDER BY e.salary
) salary_rank
FROM
employees e,
departments d
WHERE
e.department_id = d.department_id
) t
WHERE
t.salary_rank = 1
maybe something like this?
when asking sql questions like this, it helps a lot if you can provide example data via https://db-fiddle.com
and ideally also state what rdbms you're using
how
SELECT last_name AS "Last Name",
salary AS "Min. Salary",
department_id AS "Dpt#"
FROM employees
WHERE (department_id, salary) IN (
SELECT department_id,
MIN(salary)
FROM employees
GROUP BY department_id
)```
Here is another way
note that the tuple IN syntax doesn't work in sqlite and i think also ms sql server
but yeah that's pretty slick, i think it works in postgres
I am using this in sqllite
Can I inbox you?
Like salt said you should provider some sample data and example database in a fiddle. If you want help I’m sure you can at least put that much effort in to make someone’s life easier? 👍🏻
And makes it easy for you too to get help
An online SQL database playground for testing, debugging and sharing SQL snippets.
You can do something like:
SELECT * FROM employees where (salary) in (select min(salary) from employees group by department_id);
ok I solved it thanks
SELECT department_name AS 'Department Name',
COUNT(*) AS 'No of Employees'
FROM departments
INNER JOIN employees
ON employees.department_id = departments.department_id
GROUP BY departments.department_id, department_name
ORDER BY department_name;```
Is that ok for List all the departments and the number of employees per each department
Is that for a different question or the same as before?
Different
is this homework
No I am practicing
Yeah it’s fine. Have you tried yet to see the result?
I tried but having doubts
Well it’s fine. Do you understand what’s going on with it?
Because then those departments wont have any employees
How department can't have employees
SELECT city, COUNT(*) FROM employees
INNER JOIN departments ON departments.department_id = employees.department_id
INNER JOIN locations ON locations.location_id = departments.location_id
GROUP BY city ```
Getting number of employees in each city
My question why Kaunas not appeared
Looking at how you post the questions doesn't look like your trying to learn. 😆
Looks more like homework.
But if you want to get departments with 0 employee count then use left join
SELECT departments.name, COUNT(employees.department_id)
FROM departments
LEFT JOIN employees ON departments.id = employees.department_id
GROUP BY departments.id;
If your wondering why this works then its because, this type of join will return NULL for those departments that do not have a employee. And so the count function which aggregates will not count NULL values and so you get zero for it.
I thought Ligaya Turmelle's post on SQL joins was a great primer for novice developers. Since SQL joins appear to be set-based, the use of Venn diagrams to explain them seems, at first blush, to be a natural fit. However, like the commenters to her post, I found that the
So without left join I was got departments with number excepting null?
Read that article I linked, it explains it with nice diagrams.
And you can run the different joins locally on your pc to get a better understanding of how it joins.
why I am not getting all ciyies?
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 72, in _resolve_uri
results = resolver.query('_mongodb._tcp.' + self.__fqdn, 'SRV',
TypeError: query() got an unexpected keyword argument 'lifetime'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 20, in <module>
cluster = MongoClient('mongodb+srv://##########@clustercapitalism.gtqj1.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/mongo_client.py", line 639, in __init__
res = uri_parser.parse_uri(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/uri_parser.py", line 500, in parse_uri
nodes = dns_resolver.get_hosts()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 102, in get_hosts
_, nodes = self._get_srv_response_and_hosts(True)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 83, in _get_srv_response_and_hosts
results = self._resolve_uri(encapsulate_errors)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 79, in _resolve_uri
raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: query() got an unexpected keyword argument 'lifetime'
guys what's this error?
Hi, try to install dnspython, should help
What would be an SQL trigger to check if a ticket is closed, and then raise an exception if it is?
What do you mean if ticket is closed?
I basically have a table of tickets, and I need to make it so if the ticket status is closed, then no update can happen to it
Well you have 2 options. One is to have a trigger like you say, the other is to handle it application side.
I need it through a trigger, but just have no idea what to do
EG, here is a short version of what I'm doing:
INSERT INTO Ticket(TicketID, Status) VALUES (1, 'Open');
INSERT INTO Ticket(TicketID, Status) VALUES (2, 'Closed');
And then for the closed ticket, it wouldn't let you update:
INSERT INTO TicketUpdate (TicketUpdateID, TicketID) VALUES (1000, 1);
INSERT INTO TicketUpdate (TicketUpdateID, TicketID) VALUES (1001, 2);
the second one should raise an exception as it's closed
ok
Is it something like this?
"CREATE TRIGGER name BEFORE INSERT ON TICKETUPDATE EXECUTE PROCEDURE procedurename()"
i did
There are examples given here, on triggers. https://www.postgresql.org/docs/current/sql-createtrigger.html
And with this you can use BEFORE UPDATE
I'll take a look and see if I can find anything, have been stuck on this for hours lol
Not really, haven't been sure where to start. I need to read up on it more, have just had this sitting in the editor: CREATE TRIGGER CHECKCLOSED BEFORE INSERT ON TicketUpdate CHECK Status = 'Closed'
I am new to databases so I am just playing around atm, but I got an error.
@commands.command()
@commands.has_role(823787908678942721)
async def database(self,ctx, user: discord.Member = None, *,reason = None):
post = {"_id":{user.id}, "username": {user.name}, "reason":{reason}}
await ctx.send("Updated")
collection.insert_one(post)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\leogr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\leogr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\leogr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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: module 'pymongo.collection' has no attribute 'insert_one'
dnspython or dnspython3?
can someone send a vid on how to setup pymongo
@torn sphinx
MongoDB is a simple and easy to use database. This tutorial will show you how to use MongoDB with python and the python module pymongo. Pymongo is the offical MongoDB API that allows for you to easily perfor mdatabse operations.
Please Note: This is simply the basics of MongoDB in python, it is meant to get you started and give you an introduct...
without 3. dnspython. It is already for py3 now
Hi, i need help regarding PCA implementation in python, can anyone guide me?
ohhh that's why it didnt work
Hi help me
Your on the correct lines. You might want to make a function which checks your conditions for each row.
So the trigger would be:
CREATE TRIGGER check_update
BEFORE INSERT ON TicketUpdate
FOR EACH ROW
EXECUTE FUNCTION check_ticket_status();
And you would make a function for it,
CREATE OR REPLACE FUNCTION check_ticket_status()
RETURNS trigger AS
$$
-- declare current ticket status here;
begin
-- get ticket status of ticket with a query
if condition then
RAISE EXCEPTION 'Failed to update ticket';
end if;
return NEW;
end;
$$
LANGUAGE plpgsql;
You just need to add the conditions you like to check, and a query to get the current ticket status
@welcome.command()
@commands.guild_only()
@commands.has_permissions(manage_channels=True)
async def channel(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute(f"SELECT channel_id FROM welcome WHERE guild_id = ?",(ctx.guild.id))
result = cursor.fetchone()
if result is None:
sql = ("INSERT INTO welcome(guild_id, channel_id) VALUES(?,?)")
val = (ctx.guild.id,ctx.channel.id)
await ctx.send(f"Welcome channel has been set to {ctx.channel.mention}")
cursor.execute(sql,val)
db.commit()
cursor.close()
db.close()
``` idk why this does not store the guild id and channel id? it works but it just does not insert it into the db
i'd suggest doing all the sql together.. and not having that await ctx.send in the middle of the process.
also, don't know how that works.. but i typically do
sql = (f"INSERT INTO welcome(guild_id, channel_id) VALUES({ctx.guild.id}, {ctx.channel.id})")
cursor.execute(sql)
db.commit()
cursor.close()
db.close()
then how do i notify them that it has set the channel?
personally I'd go further and use context managers instead of closing stuff manually
Uh, just send the message after u close the database 😛
Yea, idek what that is haha
Please, if u could, show how you’d do it here ^-^
roughly like that:
con = sqlite3.connect(db_path)
with con:
# equivalent to creating a cursor and executing it:
result = con.execute("SELECT channel_id FROM welcome WHERE guild_id = ?",(ctx.guild.id)).fetchone()
if result is None:
con.execute("INSERT INTO welcome(guild_id, channel_id) VALUES(?,?)",(ctx.guild.id,ctx.channel.id))
await ctx.send(f"Welcome channel has been set to {ctx.channel.mention}")
con.close()
If I didn't miss anything, that's equivalent to the entire thing
notice how I don't need to commit because the with-block automatically wraps the thing in a transaction.
It's described here, at the end of the docs:
https://docs.python.org/3/library/sqlite3.html#using-the-connection-as-a-context-manager
And in fact, right above it is the con.execute thing mentioned:
https://docs.python.org/3/library/sqlite3.html#using-shortcut-methods
Using the nonstandard execute(), executemany() and executescript() methods of the Connection object, your code can be written more concisely because you don’t have to create the (often superfluous) Cursor objects explicitly. Instead, the Cursor objects are created implicitly and these shortcut methods return the cursor objects.
Wait @hexed estuary is there a way to send things from a DB (sqlite3) when a user says $applications?
Hmmm....
Is there a way to specify the global settings for a mysql connection with pymysql?
Like when I run my program, it'll do something like pymysql.connect(pymysql.details, autocommit=True)
Basically, (I think) I need to run my program, give it the login details via a file, but then delete the file right after.
use environment variables
poo poo
i use mysql as my database, it has come to my knowledge that its table can only have 100 rows
not more than that
any way to change this?
100 rows sound awfully small, i don't think a limit like that exists?
ahh mb its around 65000 bytes
if like every row is 10 bytes
we get 6500 rows
which should be fine
for the time being
even that sounds extremely small
that 65000 bytes number you're seeing looks like it's the maximum row size
not the maximum table size
hmm okay ty
the currency is real of fake one
what is expected amount of users?
Infinite IG
as I don't limit users to use my bot
I use sqlite3 now
but as sometimes bot restarts it looses some data
any gud suggestions?
you did not answer questions
losing data is unlikely to be the fault of sqlite
what ques?
oh... you have commit system
?
alternatively you can use with construction
to ensure commit always happens
a moment, I'll try to find code
ok
!e
from contextlib import contextmanager
@contextmanager
def autocommit():
try:
yield
finally:
print("insert commit command here")
with autocommit():
print("inserting data to db")
@wise goblet :white_check_mark: Your eval job has completed with return code 0.
001 | inserting data to db
002 | insert commit command here
this can make sure that commit always happens during your operations
or alterantively you can seek how to enable auto commit for all sqlite commands
ok
db = SQLAlchemy(session_options={'autocommit': True})
how to open connection to sqlite with auto commit
but
it will not allow you to make transaction manipulations
rollback and etc
this is useful only if you aren't using them
but DML commands would work?
what is DML
Data Manipulation Language
ORM?
like update
yeah, sure it will work
auto commit makes every your command being a short auto session
BTW what is SQLAlchemy
automatically update
becomes short hidden version of
session.open
do update
session. commit
hmm
there are two ways to work with databases, raw SQL
SELECT * FROM TABLE WHERE BLA BLA BLA
and ORM (SQLAlchemy provides it for example, and usually integrated into flask)
commodity.objects.all().filter(name='123').first()
well this ORM kinda looks hard 😅
actually it is pretty nice and easy
it allows making... auto migrating system
everytime when you need to choose tables, you can change them based on your code project
without lose of your data
hmm
or any difficult operations
most companies add to requirements: you must learn raw SQL, and not just ORM for dummies 😉
but raw SQL is way more easy 🙂
like
it makes your SQL operations auto optimized
and as I said it has wonderful migrating system to auto create and auto alter your tables, you aren't needing to worry about it ever
Hi, is there a way to reflect the database limited to some tables. I know automap reflect is the way here with only parameter but my tables don’t have primary key defined so it only get picked up as a class when I do full scan. I can’t define primary key because those tables are materialised views created by someone else.
all I do... just insert makemigrations and then write migrate
it creates tables and their alterations
based on my classes in code)
hello help me
In database sqllite
?
List the lowest and highest salary per city, the total number of employees per city, the number of employees earning the lowest salary, the number of employees earning the highest salary, the percentage of employees earning the highest salary per city and the percentage of employees earning the lowest salary per city. This information should be shown as 1 row per city containing all the information requested.
SELECT a.city
, a.Employees_Number
, a.Employees_Min_Number
, (a.Employees_Min_Number / a.Employees_Number * 100) AS Min_Rate
, a.Employees_Max_Number
, (a.Employees_Max_Number / a.Employees_Number * 100) AS Max_Rate
FROM (
SELECT x.city, x.Employees_Number
, (
select count(*)
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
where locations.city = x.city and employees.salary = x.Min_Salary
) AS 'Employees_Min_Number'
, (
select count(*)
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
where locations.city = x.city and employees.salary = x.Max_Salary
) AS 'Employees_Max_Number'
FROM (
SELECT locations.city,
COUNT(employees.employee_id) as 'Employees_Number',
min(employees.salary) as 'Min_Salary',
max(employees.salary) as 'Max_Salary'
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
GROUP by locations.city
) x
) a;```
How to add to select lowest, highest salary per city?
I tried add in select Min_Salary, Max_Salary but not works
How would I perform aiosqlite.connect() inside __init__ of a class?
I have a discord bot and I use postgresql to store data , Right now I am trying to use tortoise orm , I have a lot of tables made under different schemas (i made different schemas because I have a lot tables and everything under public schema looked ugly.)
my question is how do I specify schemas in tortoise-orm, like I have a schema called guild and i have two tables under it , then I have a schema called user with two tables under it .
now how do I use all these 4 tables?
Hi helpm e
Hey guys i am stuck i hope someone can help
Database is sqlite
Database:
# CREATE TICKET IN DATABASE async def create_ticket_db(userid, issue): sql.execute("INSERT INTO SupportTickets (UserId, Issue) VALUES (" + str(userid) + "," + issue +")") conn.commit()
Command:
# OPEN TICKET @bot.command() async def ticket(ctx, *, issue = None): userid = ctx.message.author.id if ctx.author != bot.user: # CHECK IF TICKET IS EMPTY if issue == None: # ERROR - NO TICKET IS EMPTY await ctx.send("Der Inhalt deines Tickets sollte nicht leer sein: ticket <grund>") return # Create Support-Ticket await create_ticket_db(userid, issue) # CREATE SUPPORT-TICKET-CHANNEL channelname = "ticket-" + str(await get_support_ticket_id(userid)) await ctx.guild.create_text_channel(channelname) # set channel permission # send embed ticket message else: return
Error: no such column: test
TicketId is Ai and Unique
Hi help me in sqllite
?
SELECT a.city
, a.Employees_Number
, a.Employees_Min_Number
, (a.Employees_Min_Number / a.Employees_Number * 100) AS Min_Rate
, a.Employees_Max_Number
, (a.Employees_Max_Number / a.Employees_Number * 100) AS Max_Rate
FROM (
SELECT x.city, x.Employees_Number
, (
select count(*)
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
where locations.city = x.city and employees.salary = x.Min_Salary
) AS 'Employees_Min_Number'
, (
select count(*)
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
where locations.city = x.city and employees.salary = x.Max_Salary
) AS 'Employees_Max_Number'
FROM (
SELECT locations.city,
COUNT(employees.employee_id) as 'Employees_Number',
min(employees.salary) as 'Min_Salary',
max(employees.salary) as 'Max_Salary'
FROM locations INNER JOIN departments
ON locations.location_id=departments.location_id INNER JOIN employees
ON departments.department_id=employees.DEPARTMENT_ID INNER JOIN jobs
ON employees.job_id=jobs.JOB_ID
GROUP by locations.city
) x
) a;```
List the lowest and highest salary per city, the total number of employees per city, the number of employees earning the lowest salary, the number of employees earning the highest salary, the percentage of employees earning the highest salary per city and the percentage of employees earning the lowest salary per city. This information should be shown as 1 row per city containing all the information requested.
How to add in select finding lowest, highest salary per city?
@welcome.command()
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def channel(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute("SELECT channel_id FROM welcome WHERE guild_id = ?",(ctx.guild.id, ))
result = cursor.fetchone()
print (result)
if result is None:
sql = ("INSERT INTO welcome(guild_id, channel_id) VALUES(?,?)")
val = (ctx.guild.id, ctx.channel.id)
await ctx.send(f"Welcome channel has been set to {ctx.channel.mention}")
elif result is not None:
sql = ("UPDATE welcome SET channel_id = ? WHERE guild_id = ?")
val = (ctx.channel.id, ctx.guild.id)
await ctx.send(f"Welcome channel has been updated to {ctx.channel.mention}")
cursor.execute(sql, val)
db.commit()
``` any idea whats wrong with this? The whole thing works it also sends the message but it wont insert it into the db.
@dense barn
One good habbit to get into for any database management is to use a context manager to ensure the db gets closed.
with sqlite3.connect(db_path) as db:
This ensures that even on an error, you still do a db.close() which I do not see in the code you posted. After the db.commit() there should be a cursor.close().
ahh
Not sure if the closes are what is causing the problem but it's a good place to start
ok tq
If you use the with statement, you don't need to do the db.close()
ye i tried that but didnt quit works so i just came back to that
If you do any other database stuff in your code and don't have close() statements, it's likely that the db is being held open by whatever is first accessing it
Traceback (most recent call last):
File "c:/Users/user/Desktop/Python Capitalism/webserver.py", line 1, in <module>
from quart import Quart, render_template, request, session, redirect, url_for
File "C:\Users\user\Desktop\Python Capitalism\venv\lib\site-packages\quart\__init__.py", line 3, in <module>
from jinja2 import escape, Markup
File "C:\Users\user\Desktop\Python Capitalism\venv\lib\site-packages\jinja2\__init__.py", line 9, in <module>
from .bccache import BytecodeCache
File "C:\Users\user\Desktop\Python Capitalism\venv\lib\site-packages\jinja2\bccache.py", line 24, in <module>
from .utils import open_if_exists
ImportError: cannot import name 'open_if_exists' from 'jinja2.utils' (C:\Users\user\Desktop\Python Capitalism\venv\lib\site-packages\jinja2\utils.py)
PS C:\Users\user\Desktop\Python Capitalism>
guys i can't import quart?
or flask either..
Maybe you removed a dependancy that it needs? Have you tried removing quart and reinstalling it to your virtual environment?
It looks like it's not finding something from jinja2
Hi, someone knows how to change different schema PostgreSQL in SQLAlchemy orm ? i tried all stackoverflow answer but no one work, maybe someone here sucess ?
Guys, is there a book and or a better documentation to understand SQLAlchemy (both core and ORM). I really want to go down the rabbit hole but the documentation is so confusing for some reason.
Hi
SQLAlchemy Tutorial - SQLAlchemy is a popular SQL toolkit and Object Relational Mapper. It is written in Python and gives full power and flexibility of SQL to an application develope
Hi help me
I need help in data modeling
Each hotel (of which you want to store your name, address, telephone, year of construction, etc.) is classified in a category (for example, three stars) being able to lower or increase of category.
Hotels have different kinds of rooms (suites, doubles, singles, etc.), which are numbered so that you can easily identify the floor you are in. So, for each room you want to save the code and type of room.
Individuals can make reservations for hotel rooms. The name, address and telephone number will appear in the reservation.
Travel agencies can also make reservations for the rooms. In the event that the reservation is made by a travel agency, the same data as for individuals was needed, in addition to the name of the person for whom the travel agency is making the reservation.
In the previous cases you should also store the price of the reservation, the date of start and the end date of the reservation.
what could be primary key in hotel table?
how can i get sliqte3 latency?
Primary keys are typically just ints or bigints
Use a bigint
As long as your primary keys are unique
Which I think they are by default
You might want make the hotel table's primary key act as a foreign key in the room table, and room table primary key a foreign key in the reservation table
Idk, does your modeling tool have a way to depict foreign key relationships?
Do you plan to write SQL for this, or use an ORM?
No
I just wanted to create data model according to description
I am not sure is it ok
Your diagram looks correct from what I can see
I'd recommend using PonyORM diagramming tool: https://editor.ponyorm.com/
It's more comprehensive, and will actually generate SQL for you in several dialects in case you'd want to test it out.
How does it work? What’s a custom reward role?
"retiredJerseyNumbers": ["number" : "99" ,"seasonRetired" : 2000 , "seasonTeamInfo" : 1999 , "pid" : 9 , "text" : "Wayne Gretzky's number has been retired league wide, in honour of the great one."],```
What's wrong with this?
How complex of a system do you want?
For a proper system I would expect many more tables, than what you have.
Ok what tables more?
any idea how i can get sqlite3 latency?
Can someone explain why this doesn't work?
Priority INTEGER CHECK (Priority <0 AND Priority <4),
Table row called Priority. Is this not a correct check to have the value be between 1 - 3?
I also did Priority INTEGER CHECK (Priority <=1 AND Priority <=3), but that didn't work either
what's wrong?
no idea what DB that is but at face value
don't you mean >0?
yw 👋
@slender roost is that using sqlalchemy?
Yes sir
Hello, How can I make the models such that the admin role sets the values (ex: upper bound, lower bound) and all the staff roles gets these values when they create a record (admin.upper_bound, etc)?
@welcome.command()
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def channel(ctx):
db = sqlite3.connect(db_path)
cursor = db.cursor()
cursor.execute("SELECT channel_id FROM welcome WHERE guild_id = ?",(ctx.guild.id, ))
result = cursor.fetchone()
print (result)
if result is None:
sql = ("INSERT INTO welcome(guild_id, channel_id) VALUES(?,?)",(ctx.guild.id, ctx.channel.id))
await ctx.send(f"Welcome channel has been set to {ctx.channel.mention}")
elif result is not None:
sql = ("UPDATE welcome SET channel_id = ? WHERE guild_id = ?",(ctx.channel.id, ctx.guild.id))
await ctx.send(f"Welcome channel has been updated to {ctx.channel.mention}")
cursor.execute(sql)
db.commit()
cursor.close()
db.close()
``` any idea why this wont store the guild id and channel id?
Postgres question: I have this code to get the first 10 sorted rows from the database, what's the correct way to get the second 10 rows?
data = await con.fetch("SELECT * FROM levels ORDER BY xp DESC LIMIT 10")
i am not known with sqlite3 so i won't be able to assist with that, I do have some other tips for your code. For the if statement you can change the elif to else. Also see if you can switch to aiosqlite, sqlite3 is synchronous and is massively blocking your entire bot whenever you do any database operation. aiosqlite is async and won't have this issue
ok
don't use LIMIT in the query, instead fetch 10 rows at a time from the cursor. this is the only time when it is acceptable to reuse a cursor. is this aiosqlite?
asyncpg
so postgres
i have a connection pool
that's the wrong query whoops
async with self.bot.pool.acquire() as con:
data = await con.fetch("SELECT * FROM levels ORDER BY xp DESC LIMIT 10")
oh wait, in postgress you can use OFFSET
async def fetch_page(self, skip=0, limit=10):
query = "SELECT * FROM levels ORDER BY xp DESC " \
f"LIMIT {limit} OFFSET {skip}"
async with self.bot.pool.acquire() as con:
data = await con.fetch(query)
i'm not sure if you can use query parameters in LIMIT and OFFSET clauses, so i used an f-string. but try it with parameters, that would be preferable and safer
afaik you can use params anywhere with $n ($1, $2, $3, etc.)
i'll test it out
thanks
and i'll keep limit as is
usually you can't use it with tables or column names
oh also i see a lot of people make the query first and store it in a variable, then execute it purely with the variable
are there any benefits for this method? or just personal preference?
you have more freedom when formatting it
line breaks, triple-quoting, etc
sql is ugly enough already
okay fair point
hello everyone can i ask a question here?
i mean this is a channel for on topic help and questions and other discussions
oh ok so i can :)
i have more than 1 , multi dimensional numpy array and i need to transfer this to .xlsx file to make a dataset for using my ml project. As a first step i converted it to pandas dataframe and transfferred the data to xlsx file, but when i send to my 2. data its getting complicated therefore there is no index number to sign my multi dimensional arrays. Is there any solution for that
how can i specify this into code, for now computer doesnt know the difference between first and second index?
Hmm this doesn't seem exactly database related. I recommend going to another help channel so the correct people will see your question
@smoky lodge
Can I use the django ORM in non django projects?
@harsh pulsar this worked
@commands.command(help="shows the top 10 for chat xp", aliases=["lb"])
async def leaderboard(self, ctx, page=1):
page = 1 if page<1 else page
offset = (page-1)*10
async with self.bot.pool.acquire() as con:
data = await con.fetch("SELECT * FROM levels ORDER BY xp DESC LIMIT 10 OFFSET $1", offset)
Great
It's possible, but you still have to do all the top level django initialization. It's not really worth it. Use Sqlalchemy instead for a similar experience.
i wonder what happens if the page number is too high
probably index out of range when indexing the data from the fetch as that would return an empty result
apparently it just works
and it remains empty
Oh thanks, but I have seen the SQLAlchemy orm but the django orm just looks cleaner for me (my opinion)
ok thanks
you can mess with database queries on ~~https://db-fiddle.net~~ (wrong url see below)
its a great tool
Doesn’t resolve name, I think the url is incorrect
oh sorry its http://db-fiddle.com
An online SQL database playground for testing, debugging and sharing SQL snippets.
@wintry stream ^
.
ok @ivory igloo
yes

Ok so
shoo
I use sqlite3, so go to this and I recommend downloading this https://sqlitebrowser.org.
you can continue lel
lol yes i know
i learned sql in https://sololearn.com @ivory igloo use it if u want
I learned through youtube
xD
no bad
i am teach sqlite3
it very easy
oke bye battery low ;-;
i learned a bit of sql in school
also where on that page do i download that
lol go here https://sqlitebrowser.org
download that
and tell me when you have finished
are you there @ivory igloo ?
i think im done now
Ok so now you are using vsc right or some ide other than replit?
What ide are you using?
if its one on the web... then never mind
if you have on one your machine, then lets continue
Go into your ide and create a new file called main.sqlite
Now open up the DB Brower for SQLite and click Open Database
Find main.sqlite and open it
tell me when you have reached here @ivory igloo
i still dont get what an ide is
Ok so
Where do you code on.
ahhh so vsc is visual studio code
wait lemme open that up
watch this video, if any errors come to me https://www.youtube.com/watch?v=Y9DzfPJsP2s
ok?
collection.update_one({"id":0},{"$set":{str(user.id):{"inventory":{n_:new_amt}}}})
collection.update_one({"id":0},{"$set":{str(other.id):{"inventory":{n_:new_amt_2}}}})
guys, this doesn't do ANYTHING. But it runs through it and no errors appear. what's wrong?
collection.replace_one({"id":0}, users)
won't work either...
it just won't update the data..?
What is the response of it? It should return UpdateResult object with some info
So like result = collection.update.... and then print result
Yes. Check 'matched_count' firstly there. Doc for the UpdateResult: https://pymongo.readthedocs.io/en/stable/api/pymongo/results.html#pymongo.results.UpdateResult
i did
result = collection.update_one(whatever I had in here)
and it said
<pymongo.results.UpdateResult object at 0x000001DAB3FA9800>
what next?
Hello Guys!
I am trying connect to a .dir file via the dbm module more specifically "dbm.ndbm"
import dbm.ndbm
with dbm.ndbm.open("C:\Users\Public\__DEFAULT",'r') as state_variables:
print (state_variables)
for key in state_variables:
print(key)
its outputting an error stating that "ModuleNotFoundError: No module named '_dbm'" and its orginating from the "with" statement
Am I not importing it using the "import dbm.ndbm"
Any help would be greatly appreciated?
sounds like either:
- ndbm isnt supported on your system
- somehow the ndbm C backend module is missing or not compiled correctly
Yeah I guess your right
its not supported on windows
if anybody wants more info: https://stackoverflow.com/questions/3408272/python-dbm-module-for-windows
let me know if any1 uses any other modules to connect to a DB file (.dir extension) in python
I would like to use the dbm module on my Windows machine, but it is currently only supported on Unix. http://docs.python.org/library/dbm.html
Does anyone know of a similar module with similar synt...
@harsh pulsar thanks!
How do i get int from database?
i tried this:
sql.execute("SELECT TicketId FROM SupportTickets WHERE UserId = " + userid)
conn.commit()
result = fetch[0][0]
return result```
but not working
` ret = await coro(*args, **kwargs)
File "W:\SupportBot\bot.py", line 107, in ticket
channelname = "ticket-" + str(await get_support_ticket_id(userid))
File "W:\SupportBot\bot.py", line 54, in get_support_ticket_id
sql.execute("SELECT TicketId FROM SupportTickets WHERE UserId = " + userid)
TypeError: can only concatenate str (not "int") to str
The above exception was the direct cause of the following exception: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: can only concatenate str (not "int") to str`
!d g dbm
Source code: Lib/dbm/__init__.py
dbm is a generic interface to variants of the DBM database — dbm.gnu or dbm.ndbm. If none of these modules is installed, the slow-but-simple implementation in module dbm.dumb will be used. There is a third party interface to the Oracle Berkeley DB.
There are other backends
ill look ino this one
ive tried dbm.dumb, dbm.gnu
It looks like you have a typo. Try '_id' instead of 'id'
i just realized
sighs..
:-)
how do I stop making typos like "id"
