Questions tagged [postgresql]

PostgreSQL is an open-source, Relational Database Management System (RDBMS) available for many platforms including Linux, UNIX, MS Windows and Mac OS X. Please mention your PostgreSQL version when asking questions. Always include the "sql" tag and possibly the "plpgsql" tag if applicable.

Filter by
Sorted by
Tagged with
1 vote
0 answers
25 views

Database recording users' consent to be subject to commands of other users

I am adding a database to my application that fulfils these requirements: There is a set of users and a set of commands. Each user can consent to any number of other users to have commands done on ...
1 vote
0 answers
31 views

Update table with data from another table under certain criteria

I need to update a lot of data from one table based on criteria from another table. My tables and records in those tables look like this: This is Users table where i can have many records for single ...
  • 341
1 vote
0 answers
36 views

Get the difference between two sets from database

Hello beautiful people! I have created a script where I have two database functions (Feed and Product) where I have a list of Feeds in a store and a list of Product in the store. What I have done is ...
2 votes
1 answer
98 views

Extracting authors and books from XML and inserting them into PostgreSQL

There is a tree of start folder, it's subfolders, their subfolders, etc. In each folder, subfolder, etc. there are the same structured XML files stored. books.xml ...
4 votes
1 answer
203 views

Postgres DB design

I need to develop a database to handle muting people in an online community. The DB needs to keep track of the currently muted people. When somebody gets unmuted, that entry gets moved to an archive ...
2 votes
0 answers
49 views

A Python base class for a family of Postgres server manager classes

I'm working on a repo the purpose of which is to create and manage a local PostGIS server. (PostGIS is a bit niche, but it boils down to a few extra spatial data types and built-in SQL function. With ...
0 votes
1 answer
63 views

Get Gzip file from endpoint, extract data and add to database

I currently have a script that fires a request to an API endpoint which returns a csv.gzip file - which roughly contains 75,000 rows and 15 columns. I download this ...
  • 327
1 vote
0 answers
85 views

Postgresql: reduce the number of joins needed to get the information about followers and following [closed]

This query is part of a mobile application backend I am working on. It is hosted on Supabase (open source Firebase alternative): It's purpose is to retrieve the profile 'preview' - the most important ...
  • 119
1 vote
1 answer
39 views

PostgreSQL query which return metrics joining different tables

I have a query that can be seen on this fiddle and I'm relatively new to PSQL, having a few months of experience. DB Fiddle As mentioned in the comment I should put the query here and the code is ...
  • 271
2 votes
0 answers
19 views

Plpgsql function that redacts substrings wrapped with double pipes `||`

I'm using Postgres 14 and I've written a function (for use with Hasura GraphQL Computed Fields) that transforms a TEXT field, replacing all instances of spoiler-annotated text (e.g. ...
2 votes
0 answers
83 views

Go REST API feedback [closed]

My intention is to create an API as generic and DRY as possible using Go. To achieve this, I have made some more or less common decisions: To use AJAX call to avoid reloading page when updating the ...
  • 121
2 votes
0 answers
34 views

Implementing a tables inheritance mechanism with PostgreSQL which allows to always reference the parent table in a foreign key

Context Postgresql has an INHERITS keyword which lets you inherit one table from another, but it is known to have several caveats, mainly because it is not a true ...
2 votes
1 answer
98 views

Django User Model to authenticate using email address and password

This is my second Django project for an actual client and I want some review on one of my important models. This model will be responsible for authenticating users using their E-Mail Addresses and ...
4 votes
2 answers
150 views

Historical database design for school system

Context We are a multi-academy trust designing a database system (more of a warehousing solution) to aggregate educational data from our 13 schools into a single source. The data will be mostly ...
  • 223
0 votes
1 answer
21 views

Comparing two columns across tables for a remaining subset

How can I find the unique phone numbers (and collapse them into a single column) from table_1 (while keeping the IDs and date fields), and remove phone numbers that appear in table_2? table_1 id ...
  • 1
2 votes
1 answer
35 views

Find coherent datetime ranges in postgresql

My Data consists of rows containing a Length/Duration in Minutes, a Begin & EndTime. The precision is 1min (or larger). the table looks something like that: ...
  • 121
5 votes
1 answer
89 views

PostgreSQL: Grouping and Aggregating on multiple columns

Problem Statement: I am working on this simple dataset from Kaggle. I have provided a snippet of data with only required columns in below table. Dataset is quite simple, it has all IPL (cricket) ...
  • 53
1 vote
1 answer
61 views

Simple website sql database

I'm getting into backend with postgresql and I would like to know how much of my example would fit for a real website database, just for storing and then displaying it on website. ...
  • 163
1 vote
2 answers
61 views

Querying and rendering an HTML table of ISP performance statistics

I have multiples measurements and I want to render it into tables like this Measurements Operator browsings FTP DL FTP UL Location Event Date Operator avg min max avg min max avg min max Verizon ...
  • 107
1 vote
1 answer
63 views

Queries using ORM and PostgreSQL

After yesterday suggestions, I was told... recommended to move over to ORM and I did. I choosed to use PeeWee together with PostgreSQL. Queries for storing and get information from postgreSQL This is ...
1 vote
0 answers
25 views

Scalable and Optimised group chat system

I have a simple chat system. I have built this to scale so I would appreciate optimisation tips or alternative table structures too. This does not include the pub/ sub queue system. Users ...
1 vote
0 answers
35 views

Fetch the nearest city, optimised with Redis on a Lambda

I have a lambda function which returns the nearest city from a latitude and longitude. My algorithm for this is resource heavy and time consuming. To optimise this, I hash the coordinates into a 6 ...
  • 111
1 vote
2 answers
1k views

A discord.py bot that logs every messages sent in a discord server

Hello Code Review community ! I'm making a bot with discord.py that listens to every message sent in a server and stores it in a database that could be retrieved by admin/mod later. Here's the ...
  • 103
1 vote
0 answers
441 views

Discord bot using SQLAlchemy

Right now I'm making a Discord Bot written in Python. I'm using SQLAlchemy to deal with the database. My structure is: One database.py containing a ...
  • 11
0 votes
0 answers
39 views

MTG Metagame Schema

So there's another question about storing information about a trading card game, but in my situation I have to store not only raw tournament information but a lot of statistics I've extracted from it: ...
2 votes
1 answer
86 views

Getting new vs. returning customers in Postgres

I have this work task, to write a SQL query that would show how many of the active customers are new (= do not have prior transactions) as opposed to returning per a given period. There is nothing ...
4 votes
0 answers
740 views

Simple Connection Pooling with psycopg2 and PostgreSQL

I am currently using a SimpleConnectionPool from psycopg2 to lease transactions to a PostgreSQL database and would like a review ...
  • 65
1 vote
1 answer
23 views

Avoding CT and other sins?

I'm a SQL learner. In answering the question* For the region with the largest sales total_amt_usd, how many total orders were placed? for the following schema: (I am unsure of the dialect is but I ...
  • 401
1 vote
1 answer
510 views

Creating SQL Table from a Go Struct

I have been building an API in Go, which I want to link to a Postgres SQL table. I have always used NoSQL previously but thought ...
2 votes
1 answer
66 views

Managing a store in PostgreSQL

I have been trying to improve python combined with Postgres. At this moment im only sending two values to database which are etc: ...
1 vote
0 answers
146 views

Creating a transaction with node-pg and Express

I'm trying to write a TRANSACTION with node-postgres in an Express API. [The code below works as it's supposed to, mostly ...
1 vote
0 answers
24 views

Postgresql - query returns different results on 2 copies of same database [closed]

I have the following postgresql query that was created for use in a production database to return a daily recap of counts. This query runs and returns correct results in the "staging"/test ...
  • 111
1 vote
0 answers
318 views

Golang DB connection with AWS SSM Parameters and context

I'm working on setting up an app backend that's deployed automatically using infrastructure-as-code and a ci/cd pipeline. As a result of that I need the app server to gather DB credentials ...
  • 1,037
4 votes
1 answer
781 views

Historical Funding Rate Miner for ftx.com

I recently started to take a look at the Go programming language and decided to write a small project without practical use. The objectives were: Regularly poll the latest funding rates from https://...
  • 389
3 votes
0 answers
126 views

Updating user information in SQL

Newbie here. I have this gqlgen api with sqlc update code, which updates the user by given id with provided fields: ...
  • 131
6 votes
1 answer
672 views

Air Quality/Environment Monitoring Web App using Plotly Dash

Overview & Motivation This project manages and displays sensor data (temperature, humidity, Air Quality Index). The sensor data is displayed by the sensor manufacturer, PurpleAir, but their tool ...
2 votes
1 answer
112 views

Any ideas how do I prettify this SQL query?

This question is abut coding style. I'd like to see how would you improve this code look considering readability as well. Feel free to upvote others solutions you find good. #1 Initial version: ...
  • 137
2 votes
0 answers
29 views

A task to store user's favorited projects in postgres using python

I am not happy with two functions calling get_user() since while testing I mock get_user and to test with get_user_returns_null case, it returns Null for both ...
  • 195
4 votes
1 answer
274 views

Discord bot with Psycopg

I've made a Discord Bot in Python that uses the Psycopg module to make calls to a PostgreSQL database in order to display information. https://github.com/Chombler/cardbot Specifically, I call this ...
2 votes
1 answer
81 views

Selecting changes from a temporal table

I'm using Temporal Tables on postgresql (https://github.com/arkhipov/temporal_tables) and C# with dapper. I'm storing an entity together with its changes. Here's an example entity, with an Id and two ...
3 votes
1 answer
49 views

Getting weather and cycling data (yr.no, oslobysykkel)

What I am trying to do, is to get weather data, data about bike trips and populate the postgresql database in order to be able to work with this data from Power BI/Tableau/any other tool. I have two ...
  • 291
3 votes
2 answers
66 views

Fetching all nodes of a directed graph by an id of any node

Task: Rowset of all reachable(in any direction) nodes from any node in a graph. In other words I need to extract all nodes of a particular graph from a table in the database where graph specified by ...
1 vote
1 answer
26 views

SQL Negation: Find X when X does not do Y

I'm learning The essence of SQL by Rozenshtein indirectly from the SQL Cookbook which has a section on it with modern SQL ...
  • 113
2 votes
0 answers
34 views

Handling failures in DB transactions

This code is meant to retry the db operation when a DB connection breaks: OperationalError. A transaction can fail for example when a db is being restarted and a commit fails. Or when a network error ...
  • 121
4 votes
1 answer
122 views

Postgres Shopping Database using Python

So I have just started to work with SQL and I have tested my script and is working very well when it comes to my database. The database is used for shopping. What I mean by that is that I scrape a ...
1 vote
0 answers
171 views

querying users from table if user.id is found in another table

I am using flask with sqlAlchemy to connect with a postgresql database with two tables Users table (id, name) ...
  • 111
3 votes
1 answer
70 views

Modelling user preference system with categories

I am modelling a user preference system with the following requirements a user can have attributes (foods they eat) a user can have dynamic categories of preferences users which have all their ...
  • 43
3 votes
0 answers
43 views

Django migration script to add metadata

I made a simple django migration that adds two field to our Invoices model : first_payment and first_paying_month. ...
  • 131
1 vote
0 answers
16 views

Moving hierarchy with the most revisions with more performance (SQL)

I have hierarchical table for my features with a parent-child relation. There was an unique constraint missing, why I have branches in the data, where multiple children relate to one parent. To add ...
  • 61
2 votes
1 answer
63 views

My Django custom user model

I followed a video on YouTube to create a custom user model, this is my attempt: ...