#databases

1 messages · Page 10 of 1

stark gust
#

people who don't have a database usually pick one that exists and use that...

#

like SQL or Mongo or something

agile flame
#

maybe I'm using the wrong term. I'm not going to make up my own datbase language

stark gust
#

so what are you trying to do?

mint wharf
#

Using psycopg2 for interacting with a postgresql database to replace my SQLite database in my app. Is there a way to get the values returned to return in a form similar to SQLite? Where I can specifically refer to columns like a dictionary?

agile flame
stark gust
#

you want to make an inventory database
otherwise known as a plain simple database
and you don't want to make up your own database language
but you aren't using anything that exists either

#

no, it is not clear what you mean

agile flame
stark gust
#

I can't get "620 BC" to turn into a valid timestamp, please help me out if you can

stark gust
agile flame
stark gust
# agile flame Great question! No I have not

but you already have a ton of assumptions about how you should do things, without knowing what a database's own requirements might be... sounds like you're trying to feed this cat through its ass

#

take a peek at Mongo for example. you are basically wasting your time with what you do now if you'd end up using Mongo
and your modeling of the schema could be easily done through Python and SQLAlchemy while you're thinking about it, and then if you chose to do SQL you already have a finished model you can use

#

I mean that's my opinion

grim vault
stark gust
agile flame
#

Well I value your opinion! I don't think I've made any assumptions yet. I can get my algo to work on a fake pandas table, but now I want to move that into a database. I was asking for help on this.
I will

  1. Look at Mongo (overhwlemed with all the choices though. there are like a dozen options)
  2. Look into "model schema"
stark gust
#
psycopg2.errors.InvalidDatetimeFormat: invalid input syntax for type date: "620"
LINE 1: ...INTO birth (date, approximate, id) VALUES ('620', tru...
grim vault
#

select to_timestamp('0620 BC', 'YYYY BC') -> -000619-01-01T00:00:00.000Z

agile flame
#

What do you mean by "if you choose to do SQL you already have a finished model you can use"?

#

an inventory database seems so common that I thought there might be some guides or boilerplate stuff out there. Anyway, I think I have enough to move forward.

stark gust
agile flame
stark gust
#

I don't know anything about Azure

stark gust
#

oh no

#

I'm so stupid

#

var1 = string value
var2 = func.to_timestamp(var1)
which do I try to add to the database? var1 of course

#

well, this was a fun hour or so completely wasted

#

I didn't realize from the error messages that it was writing out a string, not a timestamp...

torn sphinx
#

I have a question

#

Is it possible to have the user of a program enter something in the output and have that text inputted change a variable of a list

#

So like I have a list and one item in it is A and then the user inputs B and it changes A to B

#

Is that possible and if so how do I do it

stark gust
#

by "enter something in the output" you mean provide an input?

#

the user input is like any other string value, you can do with it whatever you can with any other string
including adding it to a list
you can replace a list's element by value or by index
not sure why you're asking this in #databases though

#

pgAdmin 4 appears to be an especially terrible software. or does it work fine and fast for others?

#

it reminds me of the iTunes Windows app user experience

#

what's the quickest way to get the autogenerated id of the latest inserted row from an SQL table?

fading patrol
fading patrol
#

RETURNING is the way to go

stark gust
#

thanks. I too like when the values just magically return 🙂

novel hinge
#

Does indexing a column help in query optimization? also how to know which column to index on

stark gust
#

you index the column that you want to search in, and yes, the point of the indexing is to make querying faster

#

like MUCH faster

sturdy wyvern
#

Hey guys....super noob question. Is there an advantage to breaking up a simple Python script in an orchestration tool like LUIGI vs. just scheduling the Python script to run?

torn sphinx
#
        await ctx.send("Updated DB")
        await cursor.execute('UPDATE users SET id = ? WHERE ad = ?, AND guild = ?, AND welcomechannel = ?, AND announcechannel = ?, AND welcomemessage = ?, AND leavemessage = ?, AND adchannel = ?', (member.id, '', ctx.guild.id, 0, 0, '', '', 0))
#
Traceback (most recent call last):
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 140, in setup
    await cursor.execute('UPDATE users SET id = ? WHERE ad = ?, AND guild = ?, AND welcomechannel = ?, AND announcechannel = ?, AND welcomemessage = ?, AND leavemessage = ?, AND adchannel = ?', (member.id, '', ctx.guild.id, 0, 0, '', '', 0))
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/cursor.py", line 37, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/cursor.py", line 31, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
    return await future
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
sqlite3.OperationalError: near ",": syntax error
#

anyone know why I keep getting this error?

#

I have no idea whats wrong

#

code is above

storm magnet
#

Hello, new coder here

#

Would it be able to get some help with exporting data scraped to a text or csv file?

#

Its just showing up in powershell but I cant get it to go anywhere else

#

I know im close but dont know what im missing

torn sphinx
#
          await cursor.execute("SELECT adchannel FROM users WHERE guild = ?", (ctx.guild.id,))
          result = await cursor.fetchone()
          if result is None:
            sql = ("INSERT INTO users(guild, adchannel), values(?, ?)")
            val = (ctx.guild.id, channel2)
            await ctx.send(f"Ad Channel has been set to {channel}")
          elif result is not None:
            sql = ("UPDATE users SET adchannel = ? WHERE guild = ?")
            val = (channel2, ctx.guild.id)
            await ctx.send(f"Ad Channel has been updated to {channel}")
          await cursor.execute(sql, val)
          await db.commit()    
torn sphinx
# torn sphinx ```py await cursor.execute("SELECT adchannel FROM users WHERE guild = ...
Traceback (most recent call last):
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 223, in adchannel
    await cursor.execute(sql, val)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/cursor.py", line 37, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/cursor.py", line 31, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/core.py", line 129, in _execute
    return await future
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
sqlite3.OperationalError: near ",": syntax error
#

@hollow oar 🫡

#

still stuck on these errors

real berry
stark gust
#

btw I just realized that the lack of month and day data is compensated with inserting 01-01... so january 1 will have way more birthdays than it should... this method sucks

torn sphinx
#
      await cursor.execute("SELECT adchannel, welcomemessage, welcomechannel, announcechannel, leavemessage FROM users WHERE guild = ?", (ctx.guild.id,))
      configs = await cursor.fetchone()
      adchannel, welcomemessage, welcomechannel, announcechannel = configs[0], configs[1], configs[2], configs[3]
      leavemessage = configs[4]
#
Traceback (most recent call last):
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 365, in configs
    adchannel, welcomemessage, welcomechannel, announcechannel = configs[0], configs[1], configs[2], configs[3]
TypeError: 'NoneType' object is not subscriptable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 1349, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/home/runner/cross-ad-bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'NoneType' object is not subscriptable
wintry scaffold
#

hey could i get some help so using mongodb to get data and display on a web page but it pull everything in that object id and not just the field i need

stark gust
# wintry scaffold hey could i get some help so using mongodb to get data and display on a web page...

on one hand you can choose what fields to return from the database (called projecting) by setting a second dictionary in find()

values = mongodb.collection.find({}, {"_id": 1, "username": 1}})

here's the documentation for it: https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/
on the other hand, adding projection to the query slows it down dramatically. you might be better off picking the values after the entire document is returned

values = list(mongodb.collection.find({}))
values = [x["_id"] for x in values]   # list-comprehension replaces the documents with their _id values only
#

there is of course also the option to only place the information you need into the field where you need it, not the whole thing. this is probably achievable whatever you use by concatenating the dictionary keys in your code. for example in Flask's Jinja2 templates you'd do something like this

{{ myvariable.dict_key }}

and this would place the key's value only, not the whole myvariable document

peak lion
#
            case "delete":
                dict_one = {"_id": inter.guild.id}
                exists_check = await inter.client.settings.find(dict_one)
                
                if exists_check is not None:
                    if "global_id" in exists_check:
                        c =  inter.client.get_channel(int(exists_check["global_id"]))
                        if c:
                            question = nextcord.Embed(description=f"{config.DiscordSupport} Are you sure to deactivate the global Chat ({c.mention})?")
                            
                            view = Yes_OR_No() sorry aber

                            await inter.response.send_message(embed=question, ephemeral=True, view=view)
            
                            view.message = await inter.original_message()
            
                            await view.wait()
                            if view.value is None:
                                return
        
                            elif view.value:
                                unset_field = {"global_id": c.id}
                                unset_date = {"_id": inter.guild.id}
                                await inter.client.settings.unset(unset_date, unset_field)
                            
                        else:
                            return
                    else:
                        reply = nextcord.Embed(description=f"{config.DiscordError} You don't have an active global chat!", colour=config.red)client.py
                        await inter.response.send_message(embed=reply, ephemeral=True)
                else:
                    reply = nextcord.Embed(description=f"{config.DiscordError} You don't have an active global chat!", colour=config.red)
                    await inter.response.send_message(embed=reply, ephemeral=True)```
#
Traceback (most recent call last):
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\client.py", line 512, in _run_event
    await coro(*args, **kwargs)
  File "c:\Discord\Maja Projekt\MajaSystem_Test\bot.py", line 191, in on_application_command_error
    raise error
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 910, in invoke_callback_with_hooks
    await self(interaction, *args, **kwargs)
  File "c:\Discord\Maja Projekt\MajaSystem_Test\modules\setup\cog.py", line 549, in global_chat
    await inter.client.settings.unset(unset_date, unset_field)
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\alaric\document.py", line 377, in unset
    await self._document.update_one(filter_dict, {"$unset": {field: True}})
TypeError: unhashable type: 'dict'```
stark gust
#

how can I update a field of many rows in a table with a random value using SQLAlchemy?
I mean I want a different random integer for each row's field
I assume it can be done somehow without looping through the table and doing a session for each row

fading patrol
stark gust
wintry scaffold
#

@stark gust thanks so much

stark gust
#

I found a solution in the meantime btw, I just can't make it work, but the error seems to be something else... whenever I reference this column of random numbers I end up with an error, but even if I do SELECT

fading patrol
stark gust
#

I didn't say anything because I don't think that this shows what the solution might be, but have a look

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "order"
LINE 1: SELECT * FROM Documents WHERE order = 1000

if I use any other column, it runs, it doesn't run with the order column.

#

the column exists. even if it wouldn't, I think it'd normally give a different error, not SyntaxError...

waxen finch
stark gust
#

yep, that was the problem 😄

#

is type a reserved keyword too by any chance? because I have columns named type in some tables too

#

okay, so I'm trying to add different random numbers to every element in a column, and I found that people do abs(checksum(newid())) % someinteger to do it. but if I try to pass this in SQLAlchemy like so:

query = session.execute('UPDATE Documents SET "order" = abs(checksum(newid())) % 200000')

then I end up with this error:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function newid() does not exist
LINE 1: UPDATE Documents SET "order" = abs(checksum(newid())) % 200000
                                                ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

how can I resolve this?

stoic pewter
#

how to raise an exception if the user id is not in the database? (in @namee.error)

pure sleet
stoic pewter
#

can i have an example please?

stark gust
stoic pewter
#

thanks

stark gust
#

I joined "the" SQL discord server... I have to provide my phone number to discord in order to be allowed to write there... I don't get it

brazen hornet
#

Hey guys I come from java language I have some general questions about sqlalchemy can anyone help me?

hot stag
#

So this is my code:

c.execute("DELETE from backlog WHERE oid=" + update_box.get())

And it works, the issues is that the oid stays and the rows don't shift to reflect the changes. Any idea on how to accomplish this?

#

maybe I should do "rowid" or "foreign_key" instead

stark gust
hot stag
#

I do, I just didn't include that in the code snipit. It deletes the entry just fine, but all future entries get a new oid based off what the latest oid is....

so say I have

OID 1 | data | data | data
OID 2 | data | data | data
OID 3 | data | data | data

After I delete oid 1, when I add a new entry to next entry is oid 4

stark gust
#

isn't your OID column autoincremented by any chance?

#

because that is how autoincrement works

light ice
#

guys I have problem when try deleting (using python and cs50 module same as sqlite3) a record from a table that has a foreign key.
ValueError: FOREIGN KEY constraint failed

@app.route("/deregister_7")
def deregister_7():
    id = request.form.get("id")
    if id:
        #db.execute("PRAGMA foreign_keys = OFF")
        db.execute("DELETE FROM Exemplaire WHERE id_exemp = ?", id)
    return redirect("/exemplaires")
torn sphinx
vapid hawk
#

so when you delete a user,
all the pets that reference user

on pet.owner_id = user.id
```get dropped as well
wise goblet
brazen hornet
#

Hi guys in sqlalchemy the database connection is closed automatically in ORM ? I can execute native queries in orm sqlalchemy?

brazen hornet
#

I need a serious and complete guideline for using sqlalchemy plz. If anyone can help I would appreciate it

paper flower
brazen hornet
paper flower
brazen hornet
# paper flower I don't mind but it would be better if you cold ask your questions here so other...

You have right I'm sorry. If i don't make any mistake I have seen two ways for executing queries, the first way is with a core and the second is ORM. I have read that in the core way when the script execute the . execute method then automatically creates a connection but this connection where is closed? How can ensure that my database is Safe? For the second way with ORM I make a session l, when i execute the query must I write session.close() or it works automatically? I hope my English is good enough and the message point is clear for you

paper flower
#

you could use context managers to ensure that your connection is freed

#

It won't be closed though

#

If you have some sort of shutdown event you could use engine.dispose() so close all connections before your program exits 🤔

brazen hornet
#

This application is including with fastapi so for the performance point of View it is good to make engine.dispose()? I have read that the connection pool has 10 connection, is it right this information? Please let me ask one more question, can I right native SQL query with.execute method? What's your advice for my crud project with fastapi and sqlalchemy? For the production project?

paper flower
#

You can execute raw sql with .execute too

#

I'd use orm/core where possible

brazen hornet
# paper flower 10 might be the default, yes

This situation what effect it could have when the API accept 30 request, this means the API will use 30 connection from the connection pool in the same time. This is the last question 😃 than you for your patience

paper flower
#

Most likely you can have say 100rps, and each takes ~0.2 seconds, you'd need only 20 connections for that

brazen hornet
#

Ok thank you very much for your help. If you have a good course or guide if you want send it. You have a nice day!

paper flower
brazen hornet
paper flower
lost zinc
#

How to get table name with SQLAlchemy, Let say I want to add data at specific cell by using table name and index as picture, for instance i will append to balance in date 1, How can i add Data, I am new to this framework.
SELECT balance FROM december WHERE date = 9;

torn sphinx
#

`createsql = "CREATE TABLE ACCOUNT (id INT(10) PRIMARY KEY, name VARCHAR(255), user_name VARCHAR(255))"

import mysql.connector as mysql

db = mysql.connect(
host = "localhost",
user = "root",
passwd = "simplycoding",
database = "mydb" )

cursor = db.cursor()
cursor.execute(createsql)
cursor.execute("DESC ACCOUNT")

details = cursor.fetchall()

print(details)`

what does the following code do

formal lintel
#

!code can you format properly please

delicate fieldBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

torn sphinx
#
createsql = "CREATE TABLE ACCOUNT (id INT(10) PRIMARY KEY, name VARCHAR(255), user_name VARCHAR(255))"

import mysql.connector as mysql

db = mysql.connect(
    host = "localhost",
    user = "root",
    passwd = "simplycoding",
    database = "mydb"  )

cursor = db.cursor()
cursor.execute(createsql)
cursor.execute("DESC ACCOUNT")

details = cursor.fetchall() 

print(details)```
#

I wanna know what does db.cursor, cursor.execute, fetchall does.

formal lintel
#

do you know how mysql works?

torn sphinx
#

yeah

thorny parcel
#

from the documentation

cursor = cnx.cursor([arg=value[, arg=value]...])
This method returns a MySQLCursor() object, or a subclass of it depending on the passed arguments. The returned object is a cursor.CursorBase instance. For more information about cursor objects, see Section 10.5, “cursor.MySQLCursor Class”, and Section 10.6, “Subclasses cursor.MySQLCursor”.

The MySQLCursor class instantiates objects that can execute operations such as SQL statements. Cursor objects interact with the MySQL server using a MySQLConnection object.

wispy spindle
#

Hey, I'm making a application and needs a help about sqlite3, have some way to get the name of the columns from a table, that is the same datatype that I want, in my example needs datatype of datetime, someone knows how to do that?

wispy spindle
#

Thanks

lost zinc
#

I have new question About update method with SQLAlchemy ORM, How can I update value at specific cell as UPDATE december SET balance = 1000 WHERE date = 10;

#

I have no idea.

paper flower
pearl copper
#

how to use database with python?

#

postgresql can work with python

paper flower
mint wharf
#

Let's say I have a table of books and bookRentals.
I want a query that returns all books and their latest rental, including ongoing rental. bookRentals has timestamp fields for checkout and returned. If a rental's returned value is NULL, that means it's an ongoing rental, which still counts as the "last rental" for a book.
Let's say that books and rentals are joined by a field called ISBN.

hard burrow
#

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', description=BOT_NAME, intents=intents)
bot.engine = create_async_engine(r'sqlite+aiosqlite:///C:\Tsekis\invites.db')

async def create_tables():
    async with bot.engine.begin() as conn:
        await conn.execute(text('PRAGMA foreign_keys=ON'))
        await conn.run_sync(Base.metadata.create_all)

asyncio.run(create_tables())


    return sqlite3.connect(loc, **kwargs)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Press any key to continue . . .
torn sphinx
#

"SELECT * FROM users WHERE id NOT like ? AND (gender2 = ? OR gender2 = ?) AND corp like ?"
how to make correctly much '''AND''' and '''or''' together?

wintry scaffold
#

can i get some help

#

i only want the row that Dewie is at to show up how would i have to format the db.collection.find

hybrid canyon
wintry scaffold
hybrid canyon
#

Refine your query further

wintry scaffold
#

or another stations name when the data with previous stations ends

grim vault
torn sphinx
#

I am trying to add a date value into SQLite db:
INSERT INTO SRSdatabase (lastSeen) VALUES (2022-12-11)
but the value it adds is:
1999 instead of 2022-12-11
Anyone knows why?

pure sleet
red nebula
#

Guys anyone runs python on rstudio?

#

Seaborn plots are all messed up

torn sphinx
#

I just tried to convert the datatype to other types and run the code again but the result is still the same :(

pure sleet
#

"2022-12-11"

austere salmon
elfin crown
#

Wassup mans ! I just want to know if anyone can help me for a project python ?

#

If yes come to message private please that will be really cool

robust steppe
#

Hello people
Anyone have good SQL book recommendations ? 🙏

#

Something that doesnt spend too much time on the basics perhaps

grim vault
frank cloak
#
CREATE TABLE SICRONI_GLOBAL_CHAT(
   server_id BIGINT NOT NULL,
   channel_id BIGINT NOT NULL,
   webhook_url TEXT,
   chat_type SMALLINT DEFAULT 0 NOT NULL,
   UNIQUE (server_id, channel_id),
   PRIMARY KEY (server_id, chat_type)
)

This good, right?
I should make chat_type's default be 0 though

frank cloak
frank cloak
#

What I am using uses postgresql not sqlite

naive rivet
#

Need help on SQL

#

And Tkinter

#

I want to generate an output based on value of dropdown menu

delicate fieldBOT
#

:incoming_envelope: :ok_hand: applied mute to @naive rivet until <t:1670821378:f> (10 minutes) (reason: newlines rule: sent 104 newlines in 10s).

The <@&831776746206265384> have been alerted for review.

radiant elbow
#

!unmute 832277530680623125

delicate fieldBOT
#

:incoming_envelope: :ok_hand: pardoned infraction mute for @naive rivet.

radiant elbow
#

!paste

delicate fieldBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

radiant elbow
#

otherwise the bot will mute large pastes as spam.

naive rivet
radiant elbow
#

paste the URL here

#

like the instructions in that embed say

naive rivet
#

Need help on SQL
And Tkinter
I want to generate an output based on value of dropdown menu

torn sphinx
#

I am trying to open a database in postgres through a link

#

ERR_CONNECTION_TIMED_OUT

#

this is what i get

#

what should i do ?

smoky hare
#

I want to access a .dB file from an FTP server. And I have no idea what to do.

lyric ember
#

Please I need a free database design book in pdf. Recommendations and links to the pdf will be helpful

#

I am quite struggling to get the grip of database design so wanna read a book

#

Is MySQL workspace good for designing database

#

I wanna design first then implement it in postgresql

#

I think it will not be a problem to implement the design in postgresql after designed the database in MySQL workspace

lyric ember
#

Thanks

#

I did like hundreds of search but wasn't that helpful for me. It's been 3 days Googling and trying to find some good stuff to learn database from.

#

YouTube has some videos but they are also not that good

#

Thank you for the book . I am gonna read this one.

#

Anyone has more please share

lyric ember
#

It only has some samples chapters

#

85 pages of 500

tawdry needle
#

Hi there I am working with SnowFlake and creating a connection via a python script. We would like to have a window pop up for the user to sign in, but we don't currently have SSO set up on SnowFlake. Is there a way to still make use of this authentication method without SSO or is that the only way forward?

proud crater
tawdry needle
#

@proud craterWould Okta or some Azure tool work as well?

tawdry needle
#

You rock@proud crater Thank you!

green smelt
#

Anyone here familiar with t-sql Microsoft ? Ive been trying to figure out an error now for HOURSSS

raven summit
#

!code

delicate fieldBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

livid coyote
#

Anyone particularly handy with SQLAlchemy 2.0?

livid coyote
dense imp
#

what is better place for learn DATABASES?

#

i need understand the concepts like File Organization in DBMS, and another concepts focus on teoric?

#

or just know how make querys, using the commands of SQL?

fading patrol
dense imp
#

Right

#

For example I was studying for geekforgeeks

#

But I guess that the content is very dense, because explain on how things work in background

fading patrol
dense imp
#

Right, this site have a lot information but for beginner I guess a lot information

#

And depends of your case don't necessarily know something that have there

livid coyote
#
  File "D:\Workspace\OBO\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 1177, in _tuple_getter
    return self._metadata._row_as_tuple_getter(keys)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Workspace\OBO\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 176, in _row_as_tuple_getter
    indexes = self._indexes_for_keys(keys)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Workspace\OBO\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 152, in _indexes_for_keys
    raise NotImplementedError()
NotImplementedError

Anyone run into this with SQLAlchemy 2.0 before? It happens intermittently and will often resolve on subsequent attempts, until some time has passed, in which case is throws again.

#

This is what I'm executing when it happens:

on_or_before = cast(ColumnElement, model_data >= target_time)
stmt = select(model).where(on_or_before)
results: Result = session.execute(stmt)
proven escarp
real timber
#

Is there much difference between using SQLAlchemy with reflective models vs a model defined in SQLA ? I'm wondering if there are any limitations to reflective models (other than they just represent what's on the database).

Once it's imported, is it functionally equivalent ?

soft gorge
#

What's the best way to insert a row into a database before any other operation like a select statement with sqlite

mystic shale
#

INSERT INTO

soft gorge
#

Just have that before every select statement?

mystic shale
#

maybe I'm not understanding what you want

#

you want to insert a new row into the db, right?

soft gorge
#

yes

#

before any select statement

mystic shale
#

yeah just do that before your select statements

soft gorge
#

Okay i'm thinking theres another way but i really don't think there is

#

I was trying executescript but it won't work with variables

mystic shale
#
INSERT INTO table (column1, column2, column3) VALUES (value1, value2, value3);
#

if you want to replace a row, you can do the same with INSERT OR REPLACE INTO

soft gorge
#

Okay thank you

#

I just thought there would be another way to do it within one execute

mystic shale
#

do what in one execute?

#

insert and select it at the same time?

soft gorge
#

Like a insert then a select

#

yea

#

well an insert or ignore

#

to ensure a row is returned

mystic shale
#

something like this? ```sql
INSERT INTO users (id, name, email)
SELECT 1, 'John Doe', 'johndoe@example.com'
WHERE NOT EXISTS (SELECT * FROM users WHERE id = 1);

SELECT * FROM users WHERE id = 1;

soft gorge
#

I guess

#

Problem is with sqlite at least it's like impossible to do that at once

mystic shale
#

are you doing it from the sqlite command prompt?

soft gorge
#

nah in python

#

with aiosqlite

mystic shale
#

why not sqlite3 module for python

soft gorge
#

it's with a discord bot

#

so async is "more efficient"

mystic shale
#

ah need threading?

soft gorge
#

yea

mystic shale
#

you can make a multiline comment inside the query

#

never used aiosqlite but with sqlite 3 it would be like ```py
conn.execute('''
SELECT *
FROM table
WHERE something==something
''')

soft gorge
#

Would it be more appropriate to basically make a member add them self to the database first instead of having the member added when they do a command

mystic shale
#

it would probably be easier perhaps

soft gorge
#

Yea i just feel like it’s not as professional

mystic shale
#

be careful if you are storing passwords in your db, it's easy to leave python code open for sql injection attacks

#

like if you have a login feature

#

if you do, look into parameterized queries

soft gorge
#

I got you

#

I tried that with execute script and f string but all i got was unrecognized token error

mystic shale
#

don't use fstring

#

use ?

#

question mark is like format for sql

#
conn.execute('''
    INSERT INTO users (id, name, email)
    VALUES (?, ?, ?)
''', (1, 'John Doe', 'johndoe@example.com'))
soft gorge
#

Oh i see what you mean

#

hold up let me see

mystic shale
#

you can use variables there too if you want

#

instead of the strings 'John Doe' or w/e

#

if you use fstring, I could do something like JohnDoe123'-- as my username, and then the rest of your query becomes a comment, then it won't even require a password but I can log in as JohnDoe123

#

or I can even execute code between the ' and -- if I want

#

and drop tables or something lol

#

the ? parameter prevents this

soft gorge
#
            async with aiosqlite.connect(database=self.databsePath) as db:
                async with db.cursor() as cursor:

                    sql = """
                        INSERT OR IGNORE INTO members(guild_name, guild_id, member_name, member_id) VALUES(?, ?, ?, ?)
                        SELECT * FROM members WHERE guild_id = ? AND member_id = ?
                    """, (guild_name, guild_id, member_name, member_id, guild_id, member_id)
                    await cursor.executescript(sql_script= sql)
                    await db.commit()

This is what i have

#

But now i get an error saying script argument must be unicode

mystic shale
#

did you mean to spell self.databsePath like that?

soft gorge
#

nope

#

It worked tho haha

mystic shale
#

I think it's something to do with this line await cursor.executescript(sql_script= sql) though as well

#

it's not reading it in the right codec

#

maybe reading it as binary or something, instead of utf-8

#

or whatever is the right codec for this

soft gorge
#

yea i think it's because it's getting params put in

#

It's not supposed to apparently

mystic shale
#

what's the error name?

#

aiosqlite documentation is pretty slim

soft gorge
#

ValueError: script argument must be unicode

#

It's gotta be with sqlite3

mystic shale
#

maybe you can just use sqlite3 with asyncio library and still use async and await

#

I'm not seeing anything in aiosqlite documentation about parameterized queries

soft gorge
#

True but i don't think sqlite3 allows for variables in executescript

mystic shale
#

but sqlite3 it works just fine

#

they do tho

soft gorge
#

with variables?

mystic shale
#

yeah sec I'll show you

soft gorge
#

oka

mystic shale
#

2 hr and 5 minutes in, he tells you how to parameterize it safely and why

soft gorge
#

pain

#

Still can't get execute script with variables tho even with regular sqlite3

mystic shale
#

hmm maybe the cs50 library wrapped something else to make that work

#

oh they use sqlalchemy

#

and sqlite3

soft gorge
#

I think i got something

#

I mean it's with postgreSQL but maybe this would work with sqlite3

#

Where i can manage to pass multiple statments with begin and end

#

and throw it into an execute instead of execute script

mystic shale
#

or switch to postgresql 🤣

soft gorge
#

Yea

#

I was thinking that at this point fml

#

I guess sqlite3 isn't really made for advanced sql statements

mystic shale
#

sqlite is great for simple needs

soft gorge
#

time to move on

#

Postgresql can use a local db still?

#

I don't really need a remote host

mystic shale
#

Yes it can

#

But you could also try to fstring your variables in the parameters after the query maybe

soft gorge
#

Like with the ? marks

mystic shale
#

Yeah where you input the function after you could do like f'{guild_id}' or something

#

But leave the ?

soft gorge
#

I don't think it'll work and i can't check it rn because i'm trying to change my folders blobpain

mystic shale
#

ok lol

#

hmm chat gpt says this works

#
import sqlite3

# Connect to the database
conn = sqlite3.connect("mydatabase.db")

# Create a cursor
cursor = conn.cursor()

# Define the values to be inserted
name = "Alice"
age = 21

# Define the query string with placeholders
query_string = "INSERT INTO users (name, age) VALUES (?, ?)"

# Execute the query
cursor.execute(query_string, (name, age))

# Commit the changes
conn.commit()
storm mauve
mystic shale
#

true lol

storm mauve
storm mauve
#

if an user is not in the database, you want to insert it?
just select first and then, in python code, check if it actually found someone (and if not, insert)

radiant halo
#

Hey! I'm using sqlite3 to insert users names, and data associated with them, into a database. That all works fine, however when I try to lookup the data nothing shows up before I restart my bot/script. After some searching, I believe my connection to the database isnt being closed. Problem is, I'm ending my function with commit and close..

    filename = inspect.getframeinfo(inspect.currentframe()).filename
    path = os.path.dirname(os.path.abspath(filename))
    conn = sqlite3.connect(path + '/team_database.db')
    c = conn.cursor()
    c.execute(f"INSERT INTO {team} (player_name, steam, bm) VALUES (?, ?, ?)",
              (player_name, steam, bm))
    print(f"Successfully added player to {team}'s team")
    conn.commit()
    c.close()
    conn.close()```
.
wise goblet
# radiant halo Hey! I'm using sqlite3 to insert users names, and data associated with them, int...
import sqlite3
from contextlib import contextmanager
from pathlib import Path

@contextmanager
def get_connection(path: str):
    try:
        con = sqlite3.connect(path)
        yield con
    finally:
        con.close()

@contextmanager
def get_cursor(con: sqlite3.Connection):
    try:
        cur = con.cursor()
        yield cur
    finally:
        cur.close()

def add_player_data(team, player_name, steam='Null', bm='Null'):
    with db.get_connection(str(Path(__file__).parent / "team_database.db")) as conn:
        with db.get_cursor(conn) as cursor:
            result = cursor.execute(f"INSERT INTO {team} (player_name, steam, bm) VALUES (?, ?, ?)",
              (player_name, steam, bm))
            conn.commit()
#

python way to a problem ensuring that it will be always closed

radiant halo
wise goblet
radiant halo
radiant halo
wise goblet
#

as well as replaced this path discovery with more simple analog

radiant halo
safe kernel
#

variable.commit() what does it do ?

paper flower
safe kernel
paper flower
#

It should commit current transaction

safe kernel
#

should i put one here

crimson tangle
#

how can i fix this

#

ita a ubuntu installed mongodb

#

i want to access through compess

crimson tangle
stark gust
# safe kernel

this code will break if anything other than digits would be provided as the account input (and the password in the other image). just saying, it's a bad practice to immediately try to convert the input string to int without checking if you can. possibly something like isinstance(inputvalue, int) or inputvalue.isnumeric()

safe kernel
stark gust
#

alright

torn sphinx
#

how do i get ID, name, address of all customers, plus the last payment they made and when it was made ?

#

my thought process is creating a cte that joins the 3 tables (customers,accounts and payments)

#

SELECT CUST_ID,CUST_NAME,CUST_ADDRESS,PAYMENT_AMOUNT FROM CTE GROUP BY CUST_ID ORDER BY PAYMENT DATE DESC

fleet cape
#

SELECT CUST_ID,CUST_NAME,CUST_ADDRESS,PAYMENT_AMOUNT, max(PAYMENT_DATE) FROM CTE Group BY CUST_ID,CUST_NAME,CUST_ADDRESS,PAYMENT_AMOUNT

torn sphinx
#

this is my solution

#

I havent tested it though

ancient kiln
#

first time coming across databases, installed sqlite3 and "tried" to create a basic data file but after the "mydatabase.db" line, anything I type won't have an effect. Can anyone point out whats going on please

fading patrol
strong compass
#

What do u guys think about 4/6/8 month-1 year data science bootcamp? Especially for undergraduate IT student

crimson tangle
#

help me with this auth issue

#

pls

haughty breach
#

hello, why Redis is used on broadcasting messages instead of using websockets?
In my case, I want to use Redis as a cache database on my websocket.
Is it okay if I did this flow:

1- Websocket normal send/recieve messaging

2- Whenever a message is sent/recieved store it on Redis cache

3- When websocket is closed, take all data from Redis and store it into a database (mysql, postrgresql) and clear Redis cache

4- When websocket connection is on again, get all data from database initially and redo the flow
torn sphinx
#
@bot.event
async def on_ready():
    print(f"{bot.user.name} is online!")
    setattr(bot, "db", await aiosqlite.connect("main.db"))
    async with bot.db.cursor() as cursor:
        await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, bank INTEGER, maxbank INTEGER, user INTEGER)")

async def create_balance(user):
    async with bot.db.cursor() as cursor:
        await cursor.execute("INSERT INTO bank VALUES (?, ?, ?, ?)", (0, 100, 2736652635562362, user.id,))
    await bot.db.commit()
    return

async def get_balance(user):
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT wallet, bank, maxbank FROM bank WHERE user = ?", (user.id,))
        data = await cursor.fetchone()
        if data is None:
            await create_balance(user)
            return 0, 100, 2736652635562362
        wallet, bank, maxbank = data[0], data[1], data[2]
        return wallet, bank, maxbank


async def update_wallet(user, amount: int):
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT wallet FROM bank WHERE user = ?", (user.id,))
        data = await cursor.fetchone()
        if data is None:
            await create_balance(user)
            return 0
        await cursor.execute("UPDATE bank SET wallet = ? WHERE user = ?", (data[0] + amount, user.id,))
    await bot.db.commit()

@bot.command(aliases=['bal'])
async def balance(ctx, member: nextcord.Member = None):
    if not member:
        member = ctx.author
        wallet, bank, maxbank = await get_balance(member)
        em = nextcord.Embed(title=f"{member.name}#{member.discriminator}'s Balance")
        em.add_field(name="Wallet", value=wallet)
        em.add_field(name="Bank", value=f"{bank}/{maxbank}")
        await ctx.send(embed=em)

error:

#

full error:

Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\ext\commands\core.py", line 165, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Aleccy Bot\main.py", line 86, in balance
    wallet, bank, maxbank = await get_balance(member)
  File "c:\Users\PC\Desktop\Aleccy Bot\main.py", line 62, in get_balance
    await cursor.execute("SELECT wallet, bank, maxbank FROM bank WHERE user = ?", (user.id,))
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\cursor.py", line 37, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\cursor.py", line 31, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\core.py", line 129, in _execute
    return await future
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\core.py", line 102, in run
    result = function()
sqlite3.OperationalError: no such column: maxbank```

happens when i run the command !bal
forest blaze
#

hello. can someone help me? i need a database to store images for a discord bot, which database should i use?

crimson tangle
#

to store images

#

discord will store your images

#

hmm any sql

livid coyote
#
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\orm\loading.py", line 112, in instances
    *[
     ^
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\orm\loading.py", line 113, in <listcomp>
    query_entity.row_processor(context, cursor)
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\orm\context.py", line 2571, in row_processor
    _instance = loading._instance_processor(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\orm\loading.py", line 781, in _instance_processor
    primary_key_getter = result._tuple_getter(pk_cols)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 1177, in _tuple_getter
    return self._metadata._row_as_tuple_getter(keys)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 176, in _row_as_tuple_getter
    indexes = self._indexes_for_keys(keys)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\obo\HubSpot Integration\MCE\venv\Lib\site-packages\sqlalchemy\engine\result.py", line 152, in _indexes_for_keys
    raise NotImplementedError()
NotImplementedError

Anyone seen an error like this in SQLAlchemy 2.0? It gets thrown by each one of my ORM classes in turn the first time the application runs after some time period, such that it runs fine after all of the objects have thrown the error once. That along with loading being the responsible module tells me it's something happening when the objects are first being loaded into memory, but I can't pin down specifically what is happening.

calm chasm
#

where can i get info on how to send a textfile from python to pgadmin4 database?

fading patrol
fading patrol
# calm chasm where can i get info on how to send a textfile from python to pgadmin4 database?

I assume you mean a Postgres database... this might get you started: https://pynative.com/python-postgresql-insert-update-delete-table-data-to-perform-crud-operations/

PYnative

Perform PostgreSQL CRUD operations from Python. Insert, Update and Delete single and multiple rows from PostgreSQL table using Python. use of cursor.executemany()

calm chasm
#

yes this is what i meant thank you

magic gale
#

Hello i'm new here hope someone help me !

#

I have thous 2 examples of a data i want to retrieve!
I want to know what is the best structure to store it !
In an object and one field have an array of object OR strait to an array of objects??

magic gale
#

the data is in mongoDb

haughty breach
#

yes so use an ORM, it will help u on the structure

#

make a model

#

whatever your object u want to name, could be the model name.
and the fields are; id, name, capital

#

I hope I understood ur question and answered it

calm chasm
#

can someone help me with a link for uploading a python file to pgadmin4 postgreSQL

#

i can't find it on google

thin python
#

CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
gender varchar(1) CHECK ('Male', 'Female')
);

why does this not work?

hollow crypt
#

gender varchar(1) that’s why?

real laurel
#

Hello everyone can someone help me out with a problem I have in my sqlite3

torn sphinx
# real laurel

i font think its the problem but u need to add , at the end too

real laurel
#

can you provide a little details?

torn sphinx
#

when u defined what are the values so u need to add , at the end

#

“ruler_title,”

#

idk how to explain why but its just like that

calm chasm
# hollow crypt what are you trying to do?

cur = conn.cursor()


    query = "INSERT INTO leerlingen (id, name, email, book, author) VALUES (%s,%s,%s,%s,%s)"
    with open("OLCtest_tabletext") as f:
        f_record = f.readlines()[5:]
        values = [line.strip().split(' , ') for line in f_record]
        cur.execute(query, values)
    # commit the changes
    conn.commit()
    count = cur.rowcount
    print(count, "Record inserted successfully into OLC table")

except (Exception, psycopg2.Error) as error:
    print("Failed to insert File into table", error)


finally:
        if cur is not None:
            cur.close()
        if conn is not None:
            conn.close() 
#

error is index out of range

#
def OLCtest():
    id = input("Wat is het idnummer ")
    name = input("Wat is het name ")
    email = input("Wat is het email ")
    book = input(("Naam van het book "))
    author = input("Naam van de authorr ")
    volledig = id + " , " + name + " , " + email + " , " + book + " , " + author + "\n"
    with open("OLCtest_tabletext", "a") as f:
        f.write(str(volledig))
    return print("Het is gelukt")

print(OLCtest())
#

this is the def i use to send the written part to the file

#

then i want to send the file with the written parts in it to the database

hollow crypt
calm chasm
#

this is what it is written in the file

hollow crypt
calm chasm
#
(build 223.7571.203)
#

when i print it

#
[]
hollow crypt
# calm chasm this is what i get

Clearly your list comprehension is not working the way its supposed to. f_record = f.readlines()[5:] why have your indexed f.readlines() to 5? Doing this will not give you any data. I think you should replace with f_record = f.readlines() and check

grim vault
#

It also looks like it needs cur.executemany(query, values)

calm chasm
#

now it says ```
DataBase connected
0 Record inserted successfully into table

#

so it's connected but sends 0

grim vault
#

Well, if your file only has two lines, f_record will be empty because you start with the fifth line.

calm chasm
#

i have put in more lines

#

but still same 0

#

wel fixed it myself

#

@hollow crypt @grim vault Thank you so much for helping me without you 2 i couldn't have done it thank you have a very nice day

torn sphinx
#

`# connect to db
con <- dbConnect(SQLite(), dbname="sample.sqlite")

list all tables

tables <- dbListTables(con)

exclude sqlite_sequence (contains table information)

tables <- tables[tables != "sqlite_sequence"]

view tables

tables

extract data to dataframes account, account_date_session, iap_purchase

account <- getDatabaseTables(dbname="sample.sqlite", tableName="account")
account_date_session <- getDatabaseTables(dbname="sample.sqlite", tableName="account_date_session")
iap_purchase <- getDatabaseTables(dbname="sample.sqlite", tableName="iap_purchase")`

#

Error in dbConnect(SQLite(), dbname = "sample.sqlite"): could not find function "dbConnect"
Traceback:

#

why am i getting this error

eager tide
#

got this error after passing value = " "

error : com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ')'.
torn sphinx
#

Is sigfigures an actual parameter in sql?

wise goblet
torn sphinx
#

it didn't run

#

that's why I asked

#

If there's a different way to write it maybe

torn sphinx
wise goblet
#

databases are quite different in syntax beyond standard

torn sphinx
#

postgresql

#

@wise goblet

wise goblet
torn sphinx
#

can't believe how easy it was

#

thanks mate

#

I also found something similar but they have a very big query

#

How did you find that post? I was trying to google it for long. DId you go directly on stack overflow?

#

this is the whole query that they use, but it is more generic than just enum types

#

It lists all types i think

wise goblet
torn sphinx
#

Anyways thank you

graceful widget
#

one very dumb question

#

i wonder is it possible to use a variable as a query

#

just thought of it while i was pee-ing

#

like

var1 = 'SELECT * FROM TABLE'
query.execute(var)
torn sphinx
#

lol

#

ofcourse

torn sphinx
#

Hihi, What are the usual ways of preventing SQL injections? I've read about prepared statements but I'm not sure what else is used. I appreciate the help!
I'm using Postgresql with no ORM

torn sphinx
#

what is session_count and session duration_sec

#

in row 3, session count = 12, duration = 4703. what does this mean ?

delicate fieldBOT
#

:incoming_envelope: :ok_hand: applied mute to @oak grove until <t:1671292584:f> (10 minutes) (reason: duplicates rule: sent 4 duplicated messages in 10s).

The <@&831776746206265384> have been alerted for review.

uncut moss
#

Does anyone know what is the Django equivalent to SQL's 'Point' database type? I have geolocations i want to save to my db using my Django models

twilit moss
#

Traceback (most recent call last):
File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 862, in _do_call
return await self._callback(interaction, **params) # type: ignore
File "main.py", line 51, in balance
await open_account(str(author))
File "main.py", line 68, in open_account
users[author]['Wallet'] = 0
KeyError: '928109349140824125'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/tree.py", line 1242, in _call
await command._invoke_with_namespace(interaction, namespace)
File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 887, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 880, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'bal' raised an exception: KeyError: '928109349140824125'

#

halp

fresh ermine
#

or ```from django.contrib.gis.geos import Point

uncut moss
# fresh ermine PointField

Thats whats tricky, i cannot use SQLite with that ? It would be ok but theres a ton of configurarions i read from the documentation i dont get to work on my mac. I have to switch to Ubuntu or smth

#

Would floating numbers saved to the d do the trick if i convert them to Location-objects in view.py ?

paper flower
wise goblet
#

Although i pretty much sure Postgresql can handle it too, it has even geo spatial indexes already

#

Postgres for the win 😆

torn sphinx
#
@bot.event
async def on_ready():
    print(f"{bot.user.name} is online!")
    setattr(bot, "db", await aiosqlite.connect("main.db"))
    async with bot.db.cursor() as cursor:
        await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, bank INTEGER, maxbank INTEGER, user INTEGER)")

async def create_balance(user):
    async with bot.db.cursor() as cursor:
        await cursor.execute("INSERT INTO bank VALUES (?, ?, ?, ?)", (0, 100, 2736652635562362, user.id,))
    await bot.db.commit()
    return

async def get_balance(user):
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT wallet, bank, maxbank FROM bank WHERE user = ?", (user.id,))
        data = await cursor.fetchone()
        if data is None:
            await create_balance(user)
            return 0, 100, 2736652635562362
        wallet, bank, maxbank = data[0], data[1], data[2]
        return wallet, bank, maxbank


async def update_wallet(user, amount: int):
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT wallet FROM bank WHERE user = ?", (user.id,))
        data = await cursor.fetchone()
        if data is None:
            await create_balance(user)
            return 0
        await cursor.execute("UPDATE bank SET wallet = ? WHERE user = ?", (data[0] + amount, user.id,))
    await bot.db.commit()

@bot.command(aliases=['bal'])
async def balance(ctx, member: nextcord.Member = None):
    if not member:
        member = ctx.author
        wallet, bank, maxbank = await get_balance(member)
        em = nextcord.Embed(title=f"{member.name}#{member.discriminator}'s Balance")
        em.add_field(name="Wallet", value=wallet)
        em.add_field(name="Bank", value=f"{bank}/{maxbank}")
        await ctx.send(embed=em)

error:

somber niche
#

maybe u tried to create maxbank after creating the table

#

u can do this instead:
await cursor.execute("ALTER TABLE bank ADD COLUMN maxbank DataType)

#

do this temporary it will automate create the column, after creating column remove this line or else u will get duplicate column errror

torn sphinx
somber niche
torn sphinx
#

Yeah tyy

torn sphinx
# somber niche add this line after the CREATE TABLE execution
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Aleccy Bot\main.py", line 39, in on_ready
    await cursor.execute("ALTER TABLE bank ADD COLUMN maxbank INTEGER")
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\cursor.py", line 37, in execute
    await self._execute(self._cursor.execute, sql, parameters)
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\cursor.py", line 31, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\core.py", line 129, in _execute
    return await future
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\aiosqlite\core.py", line 102, in run
    result = function()
sqlite3.OperationalError: duplicate column name: maxbank```
#

the command is working but that-

somber niche
#

u should have read properly xd

torn sphinx
#

ill check what duplicate means

#

oh

#

wdym i didnt

#

await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, bank INTEGER, user INTEGER)") await cursor.execute("ALTER TABLE bank ADD COLUMN maxbank INTEGER")

somber niche
#

await cursor.execute("ALTER TABLE bank ADD COLUMN maxbank INTEGER")

#

remove this line now

torn sphinx
#

oh okay

somber niche
#

as because maxbank now created

#

so no need of this line

torn sphinx
#

OH

#

didnt know

#

thanku sm!

somber niche
#

told u on my last sentence xd

somber niche
grim vault
# torn sphinx ` await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, ...

Be aware that after that:

await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, bank INTEGER, user INTEGER)")
await cursor.execute("ALTER TABLE bank ADD COLUMN maxbank INTEGER")

Your table columns sequence is: wallet, bank, user, maxbank
You'll need to update your insert command accordingly.
You should also change the create statement to add the new column.

await cursor.execute("CREATE TABLE IF NOT EXISTS bank (wallet INTEGER, bank INTEGER, user INTEGER, maxbank INTEGER)")
torn sphinx
#

Oh thank u!

night badge
#

im scraping names and add new records to my db daily. what im interested in is counting the occurrence of the same names and then basically show the names with the most records.
i only need two columns. name and count. i have the scraping part finished but need some help as im new to databases. would already help if i know the sql functions and read up on them.

twilit moss
#

Im new to json databases and idk the error here:

#code:
users[author] = str(author)
    users[str(author)]['Wallet'] = str(0)
    users[author]['Bank'] = 0
#err
Traceback (most recent call last):
  File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 862, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
  File "main.py", line 59, in balance
    await open_account(int(author))
  File "main.py", line 77, in open_account
    users[str(author)]['Wallet'] = str(0)
TypeError: 'str' object does not support item assignment

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/tree.py", line 1242, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 887, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "/home/runner/uNomics/venv/lib/python3.8/site-packages/discord/app_commands/commands.py", line 876, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'bal' raised an exception: TypeError: 'str' object does not support item assignment
warped turtle
#

Is there a SQL query I can use to get the number of rows before a target point?
For example, lets say I have the days of the week in a database and I want to get the count of days before friday (starting at monday.) from my database.

remote ginkgo
#

!e

""["meow"] = 0
delicate fieldBOT
#

@remote ginkgo :x: Your 3.11 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 1, in <module>
003 | TypeError: 'str' object does not support item assignment
torn sphinx
#

Hello. I want to delete all records in a database after a certain time. I am using SQLite and Peewee as ORM. Should I schedule a task for this, if true, how do I do it?

hollow crypt
torn sphinx
autumn pulsar
#
async def newsuggest(interaction: discord.Interaction):     

    cur.execute("SELECT * FROM xx WHERE x = %s",
                (interaction.guild.id,))
    exist_channels = cur.fetchone()

    if exist_channels == None:
        await interaction.response.send_message("A first suggestions channel must be configured **/update-manager-channel** ⚠",ephemeral=True)
        return
  
    feedback_modal = FeedbackModal()
    feedback_modal.user = interaction.user
    
    await interaction.response.send_modal(feedback_modal)

class FeedbackModal(discord.ui.Modal, title="Send us your feedback"):
    
    message = discord.ui.TextInput(
        style=discord.TextStyle.long,
        label="Message",
        required=False, 
        max_length=500,
        placeholder="Write to your suggestion as you want thinking!"
    )
    
async def on_submit(self, interaction: discord.Interaction):
    embed = discord.Embed(title="💡 SUGGESTIONS | SUPERKENOS 💡", 
                              description=self.message.value, 
                              color=0xAC00FF)
    embed.set_footer(
    text=f"BY: {interaction.user} - ID: {interaction.user.id}", icon_url=interaction.user.avatar)

    cur.execute("SELECT * FROM xx WHERE x = %s",
                (interaction.guild.id,))
    exist_channels = cur.fetchone()

    if exist_channels == None:
        await interaction.response.send_message("A first suggestions channel must be configured **/update-manager-channel** ⚠",ephemeral=True)
        return

        message_channel = await client.fetch_channel(str(exist_channels[1]))

        message =  await message_channel.send(embed=embed)
        await message.add_reaction("✅")
        await message.add_reaction("❌")

        is_cancelleds = False

        message2 = await interaction.response.send_message(f"{Interaction.user.mention}, your suggestion has been successfully submitted! Check <#{exist_channels[1]}>", ephemeral=True)
        if is_cancelleds == True:
         return
        await message2.delete(delay=30)
        
    async def on_error(self, interaction: discord.Interaction, error : Exception):
        traceback.print_tb(error.__traceback__)```

Problem error no cant sent:
#

there look database "select from WHERE " and other..

acoustic remnant
#

hello there i wrote a query that order my table using rank() function but i want to make it ignore the rank for the equal values (like 1st/2nd rows) is it possible to achieve using rank or there is another specific function for this or what should i do to achieve what i want and thanks!

shut forge
#

helo

#

i have a python game with rectangle colors, how to save state of color of each rect in json, with lop is more easy ?

wise goblet
shut forge
#

this is my code @wise goblet

heady cradle
#

Hi

#

Im trying to create a view named ‘AgentJobs’ which displays the number of different
jobs carried out by each Agents

#

Confused on where Im going wrong I dont get why its not identifier

#

I just got this but Idk how to do it so it can show the number of different jobs

shut forge
#

its python ?

#

what plataform you use ?

#

@heady cradle

heady cradle
#

SQL ORacle

#

Not Python

#

Nah

shut forge
#

:/

#

you use python json ?

heady cradle
#

What?

shut forge
uneven lava
#

using sqlalchemy for a postgresql db with asyncpg, should I create a new session for each request to the database (or group of requests if I need to) or should I create one session for the bot, and keep using one single session while the bot is running ?

dense imp
#

Architecture multi tenancy is recommended for Saas b2b?

somber niche
#

you want to add 1 more column or what?

torn sphinx
dark crescent
#

mood

brave bridge
#

A bit of a theoretical question: unless you maintain indices, how do you combine pagination and sorting?

#

Is it just so impractical that the best way is to just index stuff? But what if there are just too many combinations?

paper flower
gleaming arch
#

I want to log my Discord status changes (online, dnd, idle, offline) via a bot, and use that data to draw a pie chart of how much time I spend with each status

what would be an optimal schema for this use case?

I have considered using something like

CREATE TABLE StatusLog(
    before TEXT,
    after TEXT,
    ts TIMESTAMP
)
``` which keeps a record of each status change that happened with *before* and *after*
but with this, I will have to fetch all the records and do a lots of calculations in the python code

is there an efficient way to do this? I am expecting some schema which lets me query time spent with each statues directly instead of calculating that in the python code
paper flower
#

Probably user_id too in case you want to support multiple users too

gleaming arch
#

In the table I posted, I plan to store the status before change as before and the changed one as after, the time is stored in timestamp
as for the user_id, I only plan to monitor my own status so I don't think I need it

#

how would the query look like, if I want to fetch time intervals of each statuses (without having to calculate that in the python code)

ex:

status  | time
---------------
idle    | 1h
online  | 2h
dnd     | 3h
offline | 4h
grim vault
#

You can limit the inner select with WHERE "ts" between <starttimestamp> and <endtimestamp>

#

It's using the window function lag() for the previous timestamp to calculate the difference.

gleaming arch
#

oh thanks, I will need some time to read and understand what's going on there

grim vault
worthy shell
#

hi, im trying to get last row from an sqlite3 table

#

what query can i use to achieve this?

#

i don't have a primary key column in my table, or any other column with numeric values that i could ORDER BY

fading patrol
uneven lance
#

does anyone know why this offset happpens when i try to insert a list of strings into a column?

for item in strings:
        cursor.execute(f"INSERT INTO {table} ({column}) VALUES (?)", (item,))
conn.commit()
#

i dont know why there are so many null spaces above it

#

for some reason it inserts it at whatever row the other column stops at

torn sphinx
uneven lance
#

Oh yes this is not going to be for outside use, i am just using this for a personal project. And when i print the queries it prints what i am expecting

#

its not that its inserting the items wrong

#

for the first time it works fine

#

but then when i try to insert another item in a different column it puts it at where the other columns left off

#

how do i make these columns act independently?

grim vault
uneven lance
#

Oh

#

is there anyway around that?

grim vault
#

That depends on your data handling. Your insert can use more than one column or you can update a column of a ow later on.

graceful widget
#

how do i make exception for this

somber niche
#

except will handle all error

graceful widget
#

nono

#

i want to handle that specific error only

graceful widget
somber niche
#

using sqlite3?

#

or...?

graceful widget
somber niche
#

demn

torn sphinx
#

idk if this is right channel for this but my help post went dormant can anyone can help

ftp = FTP()
ftp.connect(HOST, PORT)
ftp.login()
ftp.cwd(path)
files = ftp.nlst()
for file in files:
  try:
    ftp.retrbinary("RETR " + file ,open(download_folder_path + file, 'wb').write)
ftp.quit()

I am trying to download multiple files from an FTP folder but my ftp.nlist is not working ftp.dir wont work in its place

Error
- 502 Sorry, command not implemented. :(
- files = ftp.nlist()
torn sphinx
grim vault
# graceful widget i want to handle that specific error only

You can do a select first and check if there is an entry already or use the ON CONFLICT clause of the insert to handle it in SQL.
Pseudo code:

cursor.execute("select * from armors where playerid = %s", (user.id,))
data = cursor.fetchone()
if data is None:
  curs.execute("insert into armors ...")
else:
  curs.execute("update armors set ... where playerid = %s", (..., user.id))
curs.execute("insert into armors ... on conflict(playerid) do ...")
graceful widget
#

never know ON CONFLICT is a clause

grim vault
#

It's general referred to as UPSERT (update or insert).

gilded holly
#

Hi ppl
i wanna ask for some help in related to apache airflow

i do wanna replicate my db, into leader db and follower db in my project
and can you help me by charing with me some resources and any idea that can help me

solemn lava
#

I want to ask if a Collation simply means Rules for how to sort or anything beyond that?

torn sphinx
#

I need some1 good with phpMyAdmin to help me please

floral cobalt
#

This is my error:
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Deck.children_deck - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.

#

HOW DO I LINK A TABLE TO ITSELF

#

LIKE A SET OF CARDS TO A SET OF CARDS

vocal parrot
floral cobalt
#
class Deck(db.Model,UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    Name = db.Column(db.String(300))
    date = db.Column(db.DateTime(timezone=True),default=func.now())#func gets current date and time and stores it as a default value
    #Store the foregin key in the child object for the parent, Classname(lower case).primarykey column name
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    children_deck = db.relationship('Deck')
    cards = db.relationship('Card')
#

this was my code

vocal parrot
#

Codeblock please

floral cobalt
#

im trying to have deck table that can have a deck child

#

but i dont know how to do this

#

i did children_deck

#

but thinking about this now, i would also need a parent_deck?

vocal parrot
#

Oh well true

vocal parrot
floral cobalt
#

how would i code that as i get an error rn
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Deck.children_deck - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.

floral cobalt
#

new table with 2 columns that are both foreign keys to what table?

vocal parrot
#

The Deck table

#

Sorry but I've never used sqlalchemy. I've used django and tortoise

#

You should wait around for someone with experience in sqlalchemy to help you

floral cobalt
#

whats the best way to learn django btw

vocal parrot
#

Uh idk youtube?

#

And examples in docs and github

floral cobalt
#

so many oudated videos

#

that use older versions of django

vocal parrot
vocal parrot
floral cobalt
#

rip

woven roost
#

databases are cool

full mountain
#

gyes what is the best database for like a startup which is cheapst

proven root
#

hey im useing mongo db and experanceing this error in on a shared cluster any help

pymongo.errors.OperationFailure: bad auth : authentication failed, full error: {'ok': 0, 'errmsg': 'bad auth : authentication failed', 'code': 8000, 'codeName': 'AtlasError'}```
#

i haven't changed anything about my code it just apeared

modern pike
#

hello! anybody with experience in oracle business intelligence(obi)? I am trying to automate pulling accounting subledgers from obi using python for my finance team, but am unable which module to use. Is cx_Oracle the correct module? i cant find anything about obi in cxoracle docs

vocal parrot
proven ginkgo
#

can i connect asyncpg with phpmyadmin database?

fading patrol
proven root
#

That’s the thing it’s right tho

maiden acorn
#

I need help. I keep getting this error:

#

Error: Undefined binding(s) detected when compiling SELECT. Undefined column(s): [destination] query: select * from [OffreDeplacements] where [destination] = ?

jagged frigate
#

ive learnt the MySQL syntax and heard that PostgreSQL would be prob a way better DBMS, so i was considering to change databases, however is there any specific syntax differences between these 2 or is very similar

mild rivet
#

Do primary keys make queries faster in a nonrelational database?

rapid ginkgo
#

Please tell me how can I update number_of_registered field. Can't write proper query in MongoDB for this to work

wise goblet
haughty flame
#
class Database:

    def __init__(self, config: dict[str, Any]) -> None:
        self.config = config


    async def create_pool(self):
        async with asyncpg.create_pool(dsn=self.config["postgres_url"]) as pool:
            self.pool = pool
            async with pool.acquire() as conn:
                self.conn = conn
```Hello, I have no idea how to use asyncpg, is this how you do it?
empty willow
#

Which is the best data structure to represent table attributes as class variable

haughty flame
#

Does this structure make sense? I'm trying to rewrite my MongoDB to PostgreSQL.

{
  $jsonSchema: {
    properties: {
      guild_id: {
        bsonType: 'long',
        description: 'must be long and is required'
      },
      author_id: {
        description: 'must be long and is required',
        bsonType: 'long'
      },
      title: {
        bsonType: 'string',
        description: 'must be string and is required'
      },
      link: {
        bsonType: 'string',
        description: 'must be string and is required'
      }
    },
    bsonType: 'object',
    required: [
      'guild_id',
      'author_id',
      'title',
      'link'
    ]
  }
}
```This is the schema for mongo.
vocal parrot
torn sphinx
#

hello i have quesstion how can i download browser-cookie-3???

wise goblet
# haughty flame Does this structure make sense? I'm trying to rewrite my MongoDB to PostgreSQL. ...

Picture of scheme looks good enough to me being applied to SQL.
At least assuming u made correctly, that one author can register in multiple guilds.

Oh. Except one thing

U have in author table Id, and author_id
But they serve same purpose. Delete one of them.
Same for Guild table.

If u use raw SQL, I recommend deleting id named attributes. It will be more comfortable to use foreign key as table-name+Id.
If u use ORM, then just id is fine too

wise goblet
twilit marsh
#

please can I ask you what you mean by data migrations, i am currently using mongodb and wish to be aware of pitfalls

wise goblet
# twilit marsh please can I ask you what you mean by data migrations, i am currently using mong...

Lets say you have application version 1. You already set Schema of your tables.
And then u made application version #2, added new table, or deleted some table.

SQL has mechanism for ALTER TABLE/COLUMN whatever, that will migrate whole data of your current users from previous application schema to new one, not just schema, but your data too!
Works well with Python Django ORM and SQLAlchemy/Alembic at least.

They make data migration to database, and record at its innerside, which were already applied and which not.
So when u create new migrations and application versions, only not applied one will be applied to bring your data according to new application version schema.

You are confident that.. all your data matches current application version.
Especially considering that Postgresql is having good typing and all columns defining schema. You are confident in data integrity between different tables.
Postgresql/SQL was made for this, and different stuff like FOREIGN KEY ON DELETE PROTECT/CASCADE whatever, will make sure your foreign key relationships between tables will be matching always too.

#

basically... u will not have surprises after u decided to rollout new version of application :/ Or tenth, hundrenth version.

twilit marsh
twilit marsh
wise goblet
vocal parrot
wise goblet
#

(optionally u can even write raw SQL migrations as part of the chain of migrations)

vocal parrot
#

Oh hmm ic

#

Thanks I'll look into it

soft gorge
#
  table_a 
  value1(references table_c value1)
  value2(references table_c value2)
  
  table_c
  value1
  value2

What is the most logical way to create a trigger that will ensure that when ever an insert is occurred on table_a that an insert will occur on table_c and is this a good practice?

wet linden
#

Good day! I am new to SQLite3 and DB Browser. I would want to add autoincrement to one of my columns
I am only given these options. And I still can't find a way to edit the query of the table (even after searching the internet). I would appreciate your help here. Thank you!

#

actually i found the autoincrement function already HAHAHA

ocean tapir
#

Sup, I'm trying to figure out a way to find all documents in a collection where any EmbeddedDocument in a MapField where a certain field is greater than or equal to a number. Is there any way to do this at all, or would I just have to loop through every single document and check manually?

FYI I'm using MongoEngine, so a PyMongo query would work just fine.

For the structure of my document:

Guild:
    Giveaways (MapField):
        id - Giveaway:
            end (timestamp)

I just want to check if the current time is bigger than or equal to the end time for any giveaway in the documents. (I want to list all the documents meeting the condition)

sullen glacier
#

Hello everyone !
I am wondering what kind of database solution would be the best in my case.
I have an ETL coming from ERP that I do transform.

I need to save the reworked data so that an API can call those reworked datas and supply different tools such as Salesforce, internal applications, BI etc

What would be your choice in term of intermediate storage here?
I thought of course of an Amazon RDS database but I don't want to create a normalized database here just saving datasets.

The database will be queried many times per day and for some under a batch architecture every minute.
No streaming imagined yet.

Thanks !

#

(I could use S3 of course and save flat files overwritten regularly. The API would read and send data.
I do this actually locally at the moment and it works fine. Is that something pro? Or you d never do this in a prod context?)

#

(+ other related question, what kind of EC2 instance would you choose for a prod session to be sure that the processing and the answer can be quickly handled.
I planned a Flask or FastAPI development)

primal path
#

the index keeps being printed even with the df.reset_index(drop=True)

#

fine, you?

#

good luck!

soft gorge
#

What would be the most ideal way to save notes for a specific row in it's own column or is that something that shouldn't be done?

torn sphinx
#

Anyone know a good place to host a sql database for free? like none locally?

sullen glacier
torn sphinx
#

I'm doing a small project to practice

#

I'm trying to make a basic login/registration script

torn sphinx
#

Eh nvm

paper flower
torn sphinx
paper flower
torn sphinx
#

I am bored

sullen glacier
#

well for small practicing project lots of hosting db suppliers offer free services
You re looking for relationnal databases exclusively?

sullen glacier
#

give a try to supabase then @torn sphinx. I think it s cool for testing projects

vocal parrot
#

You can host a database on railway.app

vestal oracle
#

does mysql-connector-python 8.0.31 supports mysql version 5.1.33 ?

vocal parrot
#

Idk but i feel you can really benefit from SQL relations

hard roost
#

is it possible to use excel as database

#

you need a server

soft gorge
#

What would be an easy way to ensure that a value is not negative inside of an on conflict

#

ON CONFLICT(value) DO UPDATE SET count = table.count - value OR 0 IF table.count - value < 0
something like this

grim vault
sage raft
wise night
#

Can anyone let me which datatype is used to store an image in the database?

upbeat marsh
#

What is the best database regardless of price

dreamy storm
#

Opinion ofc, but in my eyes a nice beefy Postgres database on a humungous VPS

#

Postgres is imo the most robust of the SQL databases, not incorporating nosql into consideration

#

!d aiosqlite.Connection.close

delicate fieldBOT
#
Nope.

No documentation found for the requested symbol.

dreamy storm
#

Oh

#

Well That

peak lion
#

How can i stop this?
async with aiosqlite.connect("maja.db") as db:

dreamy storm
#

Ah context manager

#

db.close()

peak lion
#

Okay and the Connection is gone

dreamy storm
#

Although the context manager should handle that itself upon exit

#

Nice to include regardless in case of Exceptions though

peak lion
#
Ignoring exception in on_application_command_error
Traceback (most recent call last):
  File "c:\Discord\Maja Projekt\MajaSystem_Test\modules\setup_new_v2_00\cog.py", line 48, in test_acces_one_role
    async with db.cursor() as cursor:
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\context.py", line 44, in __aexit__
    await self._obj.close()
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\cursor.py", line 69, in close
    await self._execute(self._cursor.close)
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\cursor.py", line 31, in _execute
    return await self._conn._execute(fn, *args, **kwargs)
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\core.py", line 130, in _execute
    raise ValueError("Connection closed")
ValueError: Connection closed```
#

Traceback (most recent call last):
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\client.py", line 489, in _run_event
    await coro(*args, **kwargs)
  File "c:\Discord\Maja Projekt\MajaSystem_Test\bot.py", line 174, in on_application_command_error
    raise error
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 888, in invoke_callback_with_hooks
    await self(interaction, *args, **kwargs)
  File "c:\Discord\Maja Projekt\MajaSystem_Test\modules\setup_new_v2_00\cog.py", line 47, in test_acces_one_role
    async with aiosqlite.connect("maja.db") as db:
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\core.py", line 161, in __aexit__
    await self.close()
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\core.py", line 179, in close
    await self._execute(self._conn.close)
  File "C:\Users\domin\AppData\Local\Programs\Python\Python310\lib\site-packages\aiosqlite\core.py", line 75, in _conn
    raise ValueError("no active connection")
ValueError: no active connection```
#
    @nextcord.slash_command(name="test_acces_one_role", description="-----", guild_ids=[config.TESTGUILD])
    async def test_acces_one_role(self, inter: nextcord.Interaction,
                                  option: str = SlashOption(name="option", description="Please choose an option", choices=["activate", "show", "delete"])):
        

        match option:
            case "activate":
                async with aiosqlite.connect("maja.db") as db:
                    async with db.cursor() as cursor:
                        
                        #Check if id is already in setup
                        await cursor.execute('SELECT id FROM setup WHERE id = ?', (inter.guild.id,))
                        
                        data = await cursor.fetchone()
                        print(data)
                        
                        if data is None:
                            view_select = admin_role_select_role_test(inter)
                            reply = nextcord.Embed(description=f"{config.DiscordSupport} Please choose an option.", colour=config.blurple)
                            await inter.response.send_message(embed=reply, view=view_select)
                            view_select.message = await inter.original_message()
                            await db.commit()
                            await db.close()
                            
                        else:
                            pass```
vale echo
#

I am so lost and stuck about intergrating MongoDB with flask. Any help would be great

torn sphinx
#

perhaps you know @low chasm (posting here because help channel closed)

torn sphinx
#

i see. i'm still a little confused because it seems like user authentication is different to what i used when using firebase in android studio/java

#

pretty sure i didn't do any of that before

vale echo
torn sphinx
#

Are there any test/blogs about out of ram performance with the most common databases? Especially text search based related databases.

supple mirage
#

include validation checks to make sure that the ward number has whole
number values from 1 to 10, and that the bed number has whole number values
from 1 to 8.
where and how do i type???
idk if this is the right channel or not

earnest mauve
#

how can i handle a select statement that found nothing

earnest mauve
#

nvm i figured something out

hasty quest
#

HI

torn sphinx
#

Hello i didn't understand this sentence. What dump means ?

Yeah it looks like any sql dump file which you can dump into a mysql instance and then use that database as any regular sql db

#

I asked to someone to extract data's from a GitHub database

lucid topaz
#

a dump is a kind of backup of a database

#

so when they say you can dump in to.. they mean you can restore it to a mysql database

torn sphinx
#

hmm

#

is this easy ?

grim knoll
#

why is pymongo not working? it says FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf' whenever i try to make a client connection

torn sphinx
#

Hello, I was recommended to enable WAL mode while using the aiosqlite library for a new Discord bot project. Some extra files were added to the same folder as my main.py script when I ran the code:

    async def open_conn(self):
        self.db = await aiosqlite.connect('data.db')
        await self.db.execute('PRAGMA journal_mode=wal')

Can anyone explain what those extra data.db files are and what they do? And is WAL mode necessary for a bot that's currently in ~50 servers? Thanks

torn sphinx
#

hi anyone knows why i cant start the server please i dont know

tranquil glen
torn sphinx
#

and how can I fix it?

#

if u have an idea ofc

vocal parrot
#

WAL mode might be insignificantly slower (1-2%) if your read operations greatly outnumber the write operations

I found this-
https://news.ycombinator.com/item?id=26108042
It seems to improve performance

polyrand

Regarding SQLite's performance, some things I've found very useful:Use WAL mode (writers don't block readers): PRAGMA journal_mode = 'WAL'

Use memory as temporary storage: PRAGMA temp_store = 2

Faster synchronization that still keeps the data safe: PRAGMA synchronous = 1

Increase cache size (in this case to 64MB), the default is 2MB PRAGM...

vocal parrot
#

But I'm not sure if that helps

waxen finch
# torn sphinx Hello, I was recommended to enable WAL mode while using the aiosqlite library fo...

in the case of "concurrency benefits", i believe WAL only really matters when you actually have multiple connections to the same database, for example two commands like this: ```py
@bot.command()
async def reader(ctx):
async with aiosqlite.connect('data.db') as conn:
... # read some stuff from the database

@bot.command()
async def writer(ctx):
async with aiosqlite.connect('data.db') as conn:
... # write some stuff``` if there are multiple commands running at the same time, and the database is using a rollback journal instead of the write-ahead log, the writing connection will block the other connections and potentially time them out with the exception, sqlite3.OperationalError: database is locked - with WAL, writer connections only block other writer connections

#

but since you have a single, global connection, it shouldn't matter too much

vocal parrot
#

I've heard it's not a good idea to use a single global connection, but rather create a new one every time you need it

#

But I'm not sure if that's true

waxen finch
#

i think the main risk is mixing up state from two transactions, which is why i personally combine it with a lock to prevent concurrent transactions

#

the writer needs an exclusive lock before it can start writing but it cant gain that exclusive lock if there are existing readers, which presumably isnt the case with WAL

vocal parrot
#

Oh hmm

supple mirage
#

include validation checks to ensure that 8 characters must be entered starting
with HN followed by 6 digits for example HN123456

torn sphinx
#

Yo i want to dump a GitHub database into my sqldatabase someone can help me please ?

uncut moss
#

Anyone know what FID as a db-field might stand for? I got a db from someone i dont know and it has objects called 'Stations'.. It has a 'station_id' but also a 'FID' field... i wonder what the original db creator intended...

#

it determines whether i should use station_id as PK or the FID

#

the CSV file had data with FID incrementing from 1 upwards but 'Station_id' runs from 200 or so upwards

torn sphinx
# waxen finch but since you have a single, global connection, it shouldn't matter too much

Hello, I should have made this more clear, it's not a 'single global connection' as such. The function I showed is a method from a class UserData that I've created to deal with reading/writing user data. So in another function (such as a bot command) I might have something along the lines of:

@commands.command()
async def money(ctx):
  user_data = UserData(ctx.author)
  await user_data.open_conn() #  Opens a DB connection
  await user_data.edit_balances(money_delta=25)  #  Add money, XP etc to the user's account
  await user_data.close_conn() #  Closes the DB connection

It is indeed possible for me to have multiple connections at once, but I'm usually only opening a connection when I'm reading or writing. So I'm guessing WAL mode will indeed help me with performance in this case? I hope this makes it more clear.

waxen finch
#

though i suggest rewriting your api to support the asynchronous context manager protocol because if an error happens to occur before your close_conn(), it might prevent aiosqlite's worker thread (and the underlying sqlite connection) from closing properly

torn sphinx
#

Alright. Thank you very much :)

soft gorge
#
  INSERT INTO transactions_count(id, current_count) VALUES(9821, 0) ON CONFLICT(id) DO UPDATE SET current_count = transactions_count.current_count + current_count; 

When I try to use this method to add to a value on conflict I get an error:
column reference "current_count" is ambiguous
I can't figure out what i should references to add the two values together

molten sparrow
#

Hello, how are you? I leave the following link to see if someone can help me http://linkode.org/#JJK7Le7E2Qa16zcsiJTPr4 , the issue is that it gives me the error django.db.utils.OperationalError: no such table: users_user and indeed not Create the USERS table in my database, I already deleted the database, I created it again, I deleted the migrations mask that is created when doing the migrations, could someone please help me

pastel wren
#

anyone have recommendations for db hosts? I'm frustrated with azure being complicated on hooking up my webapp to a new db I'm making.

grim vault
lament parcel
floral cobalt
#

How do I add a subdecks to each deck of cards
parent_id = db.Column(db.Integer, db.ForeignKey('deck.id'))#This is the foreign key for the parent deck children_deck = db.relationship('Deck', backref=db.backref('parent', remote_side=[id]), primaryjoin='Deck.parent_id == Deck.id')

torn sphinx
#

Btw, big shoutout to https://quickwit.io/. If you guys have a huge ton of text data to index (logs, etc.) and you are running on a budget (not "unlimited" ram), give it a try. It solved my problems greatly. My dataset was around 400GB text and mongodb for example ate my ram like its nothing. Lookup times under 1s were acceptable for me. Currently I am having a lookup time of 0.3s on 400GB text only consuming under 1GB of ram. And this runs on old and slow HDDs. This is not an ad, but something that really helped me.

Open-Source & Cloud-Native Log Management at any scale.

torn sphinx
#

hello
I can't install mysql server someojne can help me?

light pendant
#

Does anyone know how "expensive" it is to expunge entities from a session with SQLALchemy? I'm trying to decide between that or grabbing the columns as scalars for use in producer/consumer background jobs

hard burrow
#
sqlite_file_name = "test.db"
sqlite_url = f"sqlite+aiosqlite:///{sqlite_file_name}"

bot.engine = create_async_engine(sqlite_url)

ValueError: the greenlet library is required to use this function. DLL load failed while importing _greenlet: The specified module could not be found.

paper flower
paper flower
paper flower
hard burrow
paper flower
#

Maybe install greenlet manually

hard burrow
#

but nothing changes

hard burrow
paper flower
#

Are you sure you're not running your project inside of a virtualenv?

paper flower
#

It does not matter

hard burrow
#

no i dont, i have python 3.9

brazen hornet
#

Hello guys, I have a problem with sqlalchemy. I'm trying to write an API with fastapi which communicates with mysql. I have used the asyncio library for database transactions but I have problem with native queries. The error is sqlalchemy.exc.NoSuchColumnError: Could bot locate column in row for column 'user.user_id'. In this query I have 4 Join

#

And I have got many problems with more complex textual queries

#

Have anyone suggest me anything?

#

The sexond problem I haven is: sqlalchemy.exc.InvalidRequestError: Ambiguous column name 'user.user_id' in result set column descriptions

paper flower
hard burrow
grim knoll
#

it only happens when i add +srv to the hostname

paper flower
opal sandal
#

Hello

#

Guys is there a way where i can get the output in a particular format
like, i have two database tables and i am comparing them right now, getting all the values that are mismatch using python
but i want all the values to display in a particular format

#

these is the output i am getting which is right but i want the mismatch values of a particular column to display in a single row, as you can see in the picture the mismatch value for 1315 is printed twice

#

i want the values to print somewhat like these
my english is not very good so i dont know how should i explain this in more detail, but if anyone helps me pls feel free to ask for more details
import pandas as pd
import datacompy
CAWD=pd.read_excel("E:\Microsoft Excel\Databases\cawd_original.xlsx")
MARK=pd.read_excel("E:\Microsoft Excel\Databases\mark_revised.xlsx")

camparison=datacompy.Compare(CAWD,MARK,join_columns="PAGE,C,4")

print(camparison.report())
these is the code

#

is there anything i should try instead of report

opal sandal
#

anyone?^

brazen hornet
# paper flower Are you sure that column exists?

Yes Im sure because when I execute a simple query with that column it doesn't seem any problem. Generally I have many issues when I want to execute more complex query with asyncio and 2.0 ORM style. I don't find clear examples or tutorials and it seems a little bit chaotic the official docs

paper flower
brazen hornet
# paper flower Official documentation has a tutorial 🤔

Yes off docs have tutorials but for basic queries I didnt find something for advance queries yet. I used the method execute () and without method text () and all the problems have solved! But I don't know why. Before that I tried with select () and doesn't work

torn sphinx
#

w

lofty hull
#

hello, im unable to recollect my root password for mysql

#

what am i to do

#

i dont have any service of the server running as well

#

when i fresh install it requires me to reconfigure and im unable to recollect my password

dreamy storm
#

Do you have access to the installation directory?

lofty hull
#

is this the installation directory? @dreamy storm

dreamy storm
#

Looks like it

#

Okay so you're gonna wanna start the server in safe mode

lofty hull
#

windows safe mode then start server?

#

@dreamy storm

dreamy storm
#

Not windows safe mode, mysql safe mode

#

mysqld --skip-grant-tables

lofty hull
#

oh

#

i dont have access to cmd line

dreamy storm
#

You don't have access to cmd?

lofty hull
#

it immediately closes as i open

#

no mysql cmd line i meant

#

in normal cmd line^^

#

do i add to path?

dreamy storm
#

Mysqld should be how you invoke mysql server

#

How have you been invoking it in the past?

lofty hull
#

im unsure if i ever called it in cmd

#

@dreamy storm i dont have the bin folder as the installation is not complete how do i add to path now

#

fixed nvm

#

ty for ur time

#

cya

floral cobalt
#

How do i have nodes in falsk-sqlalchemy, as in self-relationships

floral cobalt
#

AND SHOULD I PUT MY METHODS WITH THE MODELS FILE OR IN THE VIEWS FILE WITH THEIR OWN CLASSES

steady parrot
dense imp
#

guys i am with a small problem in a design of my database

#

anyone can help me?

dense imp
#

i need create a way of create a tabela of purchase order
with fields number_order, name and description

#

but can make a purchase_order with a lot name and description how i do that?

boreal magnet
#

Do you just need to create a table with those fields?

soft gorge
#
   CREATE TABLE test(
    id BIGINT NOT NULL
    hex_color VARCHAR(7) DEFAULT "0x5865F2"
);

When I try to create a table and set the hex value as a default i'm getting error cannot use column reference in DEFAULT expression
Even when I try to set this value as TEXT DEFAULT it's giving the same error. Any idea why?

light pendant
#

The general wisdom I see online is that database entities should not have any logic associated with them, i.e. they're just dumb containers of data. However, most resources I come across on this are very Java/C# centric, and I'm wondering if the same principles apply when working with databases in Python (since there are many patterns from strict OOP languages that don't translate well to Python)

torn sphinx
grim vault
# soft gorge ```sql CREATE TABLE test( id BIGINT NOT NULL hex_color VARCHAR(7) DEF...

String literals needs to be enclosed with single quotes '. It also looks like the length is 8 not 7.

CREATE TABLE test(
  id BIGINT NOT NULL,
  hex_color CHAR(8) DEFAULT '0x5865F2'
);

Double quotes are used for SQL identifiers, that's why you get the column reference error, because the SQL parser thinks "0x5865F2" is a column name in this context.

hard burrow
#
Code:

engine = create_async_engine("sqlite+aiosqlite:///:memory:")

the greenlet library is required to use this function. DLL load failed while importing _greenlet: The specified module could not be found.

hearty token
#

Hi guys, i'm currently working with pymysql and i'm in need to specify an execution time limit of a query. Unfortunately this is not implemented in the connector. Does somebody know what the best practice is for implementing such a query maximum execution time. I know of a couple solutions but i'm wondering what the best solution is.

hearty token
grim vault
#

~~You can setup a threat which will call the interrupt() method of the connection: ~~ SQLite, sorry. Maybe pymysql has something similar.

torn sphinx
vocal parrot
# torn sphinx hello anyone knows how to transfer data from a github's databse to a mysql datab...
torn sphinx
#

alr thank you i'll check

silent grotto
#

How to convert db query to txt file?

#

Sqlite3?

#

Is there any example?

smoky latch
# silent grotto How to convert db query to txt file?

You should do it in the backend, what about writing the query in a pandas dataframe and then using .to_string ?

with open(writePath, 'a') as f:
    dfAsString = df.to_string(header=False, index=False)
    f.write(dfAsString)
hearty token
unkempt prism
soft gorge
smoky hare
#

Hi, I'm not much of a database guy, but any easy to read way to transfer data from sqlite to postgresql? I have a .db file.

silent grotto
silent grotto
unkempt prism
silent grotto
#

So they need to install excel software to view csv file

#

Isn't it easy to view if I convert db query to txt file?

#

As every android device has txt viewer....

unkempt prism
grim vault
#

CSV is a text file which uses Commas to Separate the Values inside the file.

silent grotto
#

Didn't have an idea aboit csv extension ;)

calm obsidian
#

why database when you can just write the values in a text document and then pull it from a text document like silly old me

pure cypress
#

Because a database is more efficient and can offer some guarantees about the data (e.g. Referential integrity, acid, etc)

real timber
#

How to connect to a postgres docker container, using psql from the host?

eg for the following:

docker run --name example --rm -d -e POSTGRES_PASSWORD=password -e POSTGRES_DB=db -e POSTGRES_USER=user -p 5432:5432 postgres:14.6-bullseye

Once that's running, how can I connect to it with psql ? I tried:

psql -h localhost --port 5432 --dbname db -U user

But this returns an error

psql: error: connection to server at "localhost" (::1), port 5432 failed: server closed the connection

And I'm not sure how to fix, though I was under the impression that connecting to the container with psql should be fine

unkempt prism
real timber
unkempt prism
real timber
#

I tried that -h example again, failed the same way

pure cypress
#

Are you sure the pg container is actually runnng and healthy

unkempt prism
# real timber Hm : ``` $ psql -h example --port 5432 --dbname db -U user psql: error: could n...

hate to say it though works for me!

t@ubuntu:~$ docker run --name example --rm -d -e POSTGRES_PASSWORD=password -e POSTGRES_DB=db -e POSTGRES_USER=user -p 5432:5432 postgres:14.6-bullseye
2f0903290e7ef8a106484a88d3e2d31e5dd0cb1264e739be3a10d40292c7be5d
t@ubuntu:~$ psql -h 127.0.0.1 --port 5432 --dbname db -U user
Password for user user: 
psql (15.1 (Debian 15.1-1.pgdg110+1), server 14.6 (Debian 14.6-1.pgdg110+1))
Type "help" for help.

db=# exit
t@ubuntu:~$ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
2f0903290e7e   postgres:14.6-bullseye   "docker-entrypoint.s…"   54 seconds ago   Up 53 seconds   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   example
real timber
pure cypress
#

Well try restarting it as an easy fix hopefully

real timber
pure cypress
#

You can launch a shell within the pg container and try to connect to it from within

unkempt prism
#

is it MacOS? I vaguely possible the is a checkbox somewhere to allow networking.

real timber
#

No I'm on ubuntu

real timber
pure cypress
#

Yes just to check

real timber
real timber
unkempt prism
real timber
#

os:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
real timber
unkempt prism
#

Comparing my docker ps output above I'll be interested what you have under PORTS

real timber
pure cypress
real timber
unkempt prism
pure cypress
#

Port would be the default 5432 and host localhost

real timber
unkempt prism
real timber
# pure cypress Yeah I believe so

OK that has done something:

$ docker exec -it example bash
root@1494d69fa711:/# psql -d db -U user
psql (14.6 (Debian 14.6-1.pgdg110+1))
Type "help" for help.

db=# 
pure cypress
#

Okay so it can connect, we know the server is running fine

#

That kind of confirms the issue is networking between container and host

real timber
unkempt prism
#

how have you installed psql

real timber
#

sudo apt install postgresql postgresql-contrib

pure cypress
# real timber yea, anything i should try ? Could this be some install related thing or somethi...

It should just work out of the box, but I know there are some networking options for docker. This comes to mind, but not sure what the equivalent is for.docker run https://github.com/compose-spec/compose-spec/blob/master/spec.md#network_mode

GitHub

The Compose specification. Contribute to compose-spec/compose-spec development by creating an account on GitHub.

#

Does the container show any logs when you try to connect from the host by the way?

pure cypress
#

It may also be worth trying to connect via some other tool e.g. A simple python script with psycopg

real timber
pure cypress
#

Not sure what's wrong, sorry

real timber
# pure cypress Not sure what's wrong, sorry

😩 yea it seems screwed and i'm clueless.

PostgreSQL init process complete; ready for start up.

2023-01-01 00:38:21.666 UTC [1] LOG:  starting PostgreSQL 14.6 (Debian 14.6-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-01-01 00:38:21.666 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-01-01 00:38:21.666 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-01-01 00:38:21.668 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-01-01 00:38:21.672 UTC [62] LOG:  database system was shut down at 2023-01-01 00:38:21 UTC
2023-01-01 00:38:21.678 UTC [1] LOG:  database system is ready to accept connections

is in the log but idk what that says

calm obsidian
#

its a i goofed statement

little smelt
#

how do i use cassandra with django ?

pastel wren
#

so a problem i've run across recently is that i'm trying to secure users' emails in my db by hashing their email when they sign up and then when they try to login in using that email i'd hash what the email they enter and make a select into my db with that hash as the WHERE. This doesn't work though since when i hash it when the user logs in the hash is different. Is there some way to secure users emails that avoids this issue or is my implementation of securing emails slightly off?

lament parcel
grim vault
# pastel wren so a problem i've run across recently is that i'm trying to secure users' emails...

!e If you use the same hash algorithm it should work:

import hashlib

def hash_email_sha256(email: str) -> str:
    return hashlib.sha256(email.encode("UTF-8")).hexdigest()

email_register = "username@example.com"
email_login_test = [
    "Username@example.com",
    "UserName@example.com",
    "username@example.com",
]

saved_hash = hash_email_sha256(email_register)
for login_entry in email_login_test:
    check_hash = hash_email_sha256(login_entry)
    print(f"{login_entry} -> {saved_hash == check_hash}")
delicate fieldBOT
#

@grim vault :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | Username@example.com -> False
002 | UserName@example.com -> False
003 | username@example.com -> True
grim vault
#

I would only hash the password (with some salt). If you hash the email/username you won't know who the send the forgot password link.

torn sphinx
#

anyone knows a free mysql hosting?

vocal parrot
#

railway.app has mysql

#

you get 21 days free
and if you verify with a cc you get over a month. still free

delicate fieldBOT
#

@cursive delta Per Rule 6, your invite link has been removed. If you believe this was a mistake, please let staff know!

Our server rules can be found here: https://pythondiscord.com/pages/rules

pastel wren
obsidian barn
#

you could encrypt an email, or hash it separately, but I don't think hashing does what you think

grim vault
#

reads like a simple group sum with a limit

select name, sum(points) as "total" from tablename group by name order by total desc limit 10
serene sonnet
#

how much time does pymysql need to execute a select * from table?

paper flower
pastel wren
serene sonnet
vocal parrot
#

Rather than dict, you should rather cache on redis

#

It will be faster than SQL select queries

#

Remember to update redis when updating SQL server

ivory lava
#

is it faster to query my sqlite db every iteration of a loop or do it first and search through it with python?

fading patrol
grim vault
#

I would use julianday() or unixepoch() to get a number. Also week is not supported, you'll need -7 days.

obsidian barn
wraith carbon
#

squil

torn sphinx
#
CREATE TABLE IF NOT EXISTS greetings (
    guild_id BIGINT NOT NULL,
    accent_color INT,
    ignore_bots BOOLEAN,

    welcome_channel_id BIGINT,
    goodbye_channel_id BIGINT,

    welcome_message VARCHAR(2000) DEFAULT "Hello {member}, welcome to {guild}",
    goodbye_message VARCHAR(2000) DEFAULT "{member} left." 
);
``` is there something wrong with this query? i get this error when i execute it with asyncpg ```py
  File "asyncpg/protocol/protocol.pyx", line 338, in query
asyncpg.exceptions.FeatureNotSupportedError: cannot use column reference in DEFAULT expression
torn sphinx
#

turns out sql supports single quotes only

delicate fieldBOT
#

Hey @ashen mountain!

You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.

ashen mountain
#

Im trying to setup mongodb for the first time but I’m doing something wrong

#

I keep getting this error

Traceback (most recent call last):
  File "C:\Users\Lucaq\AppData\Roaming\Python\Python310\site-packages\lightbulb\app.py", line 1163, in invoke_application_command
    await context.invoke()
  File "C:\Users\Lucaq\AppData\Roaming\Python\Python310\site-packages\lightbulb\context\base.py", line 326, in invoke
    await self.command.invoke(self)
  File "C:\Users\Lucaq\AppData\Roaming\Python\Python310\site-packages\lightbulb\commands\base.py", line 690, in invoke
    await self(context, **kwargs)
  File "C:\Users\Lucaq\AppData\Roaming\Python\Python310\site-packages\lightbulb\commands\base.py", line 605, in __call__
    return await self.callback(context, **kwargs)
  File "C:\Users\Lucaq\Novemeber Project\Bologne\bologne\extensions\ship.py", line 93, in echo
    insert_ship_doc()
  File "C:\Users\Lucaq\Novemeber Project\Bologne\bologne\extensions\ship.py", line 73, in insert_ship_doc
    collection.insert_one(ship_document)
  File "C:\Users\Lucaq\AppData\Roaming\Python\Python310\site-packages\pymongo\collection.py", line 3207, in __call__
    raise TypeError(
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Database' object it is failing because no such method exists.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Lucaq\Novemeber Project\Bologne\bologne\__main__.py", line 43, in errorHandler
    raise event.exception
lightbulb.errors.CommandInvocationError: An error occurred during command 'ship' invocation
#

i dont know what im doing wrong

#

cause i think i did everything correct

torn sphinx
#

rip ken block

wintry sparrow
#

can someone tell me why you'd use a SQL (postgres specifically) over something like mongodb?

#

i'm learning postgreSQL for school (with java) after working with monogodb (with python) and so far apparently you'd go for SQL when you have closely related data?

#

like apparently you can't query and stuff with a nonsql database but i had no issues querying with mongodb even when it came to nested objects and stuff like that it was pretty simple with pymongo

#

sql on the other hand looks like a living hell i'm confused what benefits you could get over something like mongodb unless it was performance related i suppose

#

i'm knew to databases so please excuse my ignorance 😅 sql makes my brain fog up just looking at it

forest raptor
#

Hello!

I'm using MongoDB to store my items. When I try to use the find_one() method, it returns None even though there is data there.

#
def get_balance(user_id):
        return collection.find_one({'user_id': user_id})['currency']```
wintry sparrow
#

is the user id supposed to be your primary key?

#

if so i think you have to access it with "_id" and converting the user_id into an ObjectId

forest raptor
#

Nope

#

I have a field called user_id

#

here's a datamodel

wintry sparrow
#

what's the type of the the user_id variable?

forest raptor
#

I'm not too sure

wintry sparrow
#

if it's a string that could be why it's not finding it

forest raptor
#

but Ive tried int and str

#

oh it works

#

wth

wintry sparrow
#

you've tried converting the user_id to an integer?

forest raptor
#

i changed nothing

wintry sparrow
#

oh

forest raptor
#

welp thats a good thing ig

#

ty for your help and time

#

lol

wintry sparrow
#

ofc even though i didn't do anything 😅

forest raptor
#

You still tried!

fading patrol
mint mauve
#

how can I make it that if user_id1 or user_id2 will be user.id?

    friends = db.relationship("Friend", backref="user", passive_deletes=True, primaryjoin="and_(Friend.user_id1==User.id, " "Friend.status=='friends')") 
smoky latch
# wintry sparrow can someone tell me why you'd use a SQL (postgres specifically) over something l...

Eventually you'll realise that like 90% of the data you're working with is actually relational. That means you need data integrity. Your queries will generally be simpler too (I don't know how SQL could be more complex than the MongoDB queries but eh, besides you have numerous ORMs today to make your life easier). Also, as the SQL databases avoid data duplication, that means that they'll generally be smaller.

Nowadays you can pretty much do things both ways, and notice that the technical differences aren't that relevant if you don't plan on making relatively small databases without much workload anyways.

high agate
#

How do i select all the suggestions_id rows? if you get what i mean

#

and then put all the returned values in the dictionary fruits

waxen finch
high agate
#

with the fetchone() repeatedly could i append the fetched value to the dict each time