Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
1 vote
1 answer
59 views

I'm using a self-hosted TimescaleDB instance to store logs. I have a hypertable logs that is partitioned by the timestamp column. I need to perform a fast lookup query based on the event_key column, ...
Oussama Jmâa's user avatar
1 vote
1 answer
55 views

I have a table in PostgreSQL like this: CREATE TABLE test ( id BIGSERIAL PRIMARY KEY, data_discriminator VARCHAR NOT NULL, created_at TIMESTAMPTZ NOT NULL, data JSONB ...
xtrx's user avatar
  • 35
3 votes
1 answer
94 views

I was reading this article on the Internet regarding alignment PostgreSQL. Based on the example of the article and on some work experience I had with the alignment, I did a small experiment with the ...
Xocas17's user avatar
  • 51
2 votes
0 answers
71 views

I am using PostgreSQL 17.2 and working with the postgres_air Database. I have a very simple query: SELECT status FROM postgres_air.flight WHERE status = 'Canceled'; And the following indexes: CREATE ...
Xocas17's user avatar
  • 51
0 votes
0 answers
24 views

Having a table with a metadata column of the JSON type I am failing to utilize the full power of the index. Creating a new table CREATE TABLE IF NOT EXISTS phrases ( phraseId BIGINT, metadata ...
Jan Tosovsky's user avatar
1 vote
1 answer
90 views

Having a table with a metadata column of the JSON type I am failing to utilize the full power of the index. Creating a new table CREATE TABLE IF NOT EXISTS phrases ( phraseId BIGINT, projectId ...
Jan Tosovsky's user avatar
1 vote
2 answers
148 views

We have two tables in a Postgres DB. Table1 is a small temp table, Table2 is a huge regular table (> 1 million rows): -- small, temp: CREATE TEMPORARY TABLE Table1 ( uid VARCHAR(15) , idx INTEGER ...
zheng's user avatar
  • 39
3 votes
3 answers
248 views

I have a table: create table accounts_service.operation_history ( history_id bigint generated always as identity primary key, operation_id varchar(36) not null unique, operation_type ...
Alexey Stepanov's user avatar
1 vote
1 answer
126 views

Postgres: v12 Link to test: https://www.db-fiddle.com/f/pfnFVhFq1QTxjas6BB4sZv/3 There are transactions table and logs table. logs are linked to transactions by transaction_id. I need to query logs ...
sirjay's user avatar
  • 1,770
1 vote
1 answer
96 views

Postgres: v12 Link to test: https://www.db-fiddle.com/f/7BjKHTP7RGKKDfBDPtzm99/0 There are transactions table and logs table. logs are linked to transactions by transaction_id. I need to query logs ...
sirjay's user avatar
  • 1,770
0 votes
3 answers
94 views

I have two tables, one which I will call D and one which I will call S, with a 1:N relationship between D and S. I currently have the following query that runs on these two: SELECT d.*, s.* FROM d ...
Woody1193's user avatar
  • 8,192
0 votes
2 answers
158 views

My system is using PostgreSQL as the database. I am encountering an issue when using a query to join two large tables together. I'll briefly describe the tables as follows: Location: - id: uuid - name:...
Sinh Phan's user avatar
  • 1,296
0 votes
2 answers
140 views

I'm working on an express.js project, using Sequelize as the orm, and postgres as the engine. I'm working on improving the performance of a slow select query that does many things, and one of them is ...
Daniel's user avatar
  • 532
0 votes
1 answer
448 views

I have a products table with an array column tags that contains up to 700 elements. I want to efficiently search for specific tag names for a given user to be used in a search bar. Here's my query: ...
soltex's user avatar
  • 3,611
-3 votes
2 answers
97 views

Problem The following query takes 42 seconds when most of the data in not cached: EXPLAIN (ANALYZE, BUFFERS) select count(*) from packages where company_id = 178381; ...
Jordi Chacón's user avatar
0 votes
1 answer
125 views

I have a Postgres table named shipData(total rows 700 millions). Which has ship location with reporting time and location in geometry format(combination of lat & lon). I have a shipID, I want to ...
Reayz's user avatar
  • 39
1 vote
1 answer
58 views

How can I efficiently turn a set of strings into a table such that each strings is mapped to all other strings of which it is a prefix? I use PostgreSQL 14 and deal with a table medical_codes of about ...
Frerich Raabe's user avatar
0 votes
3 answers
669 views

I am dealing with a PostgreSQL (v14) query of this kind SELECT ..., EXISTS ( SELECT 1 FROM table2 t2 WHERE t2.fk = t1.id AND LOWER(t2.table_name) = 't1' ) ...
Luca Blanchi's user avatar
0 votes
3 answers
87 views

This query: select id from user u where u.account_id = 600 returns: 61,71,68,69,70,118,116,117,248,381,384,325,265,393 and it works really fast. This query: select * from logs l where l.user_id in (...
Ham Burg's user avatar
0 votes
1 answer
245 views

I'd like to extract ranges which overlaps with another range from multirange using SQL. For example, {[5,10), [14,20), [26,28), [29,31)} with {[15,27)} should result {[14,20), [26,28)}. I can achieve ...
uniquon's user avatar
0 votes
1 answer
61 views

I have a table called tbl_inventory_detail_old as for the following DDL and it currently has 19M records. There are around 500 unique agent ids and around 35 unique product ids. CREATE TABLE public....
iuhettiarachchi's user avatar
2 votes
2 answers
655 views

We are trying to optimize a query to a partitioned table, the query looks something like this: SELECT col1, col2 FROM partitioned_table WHERE profile_id = '00000000-0000-0000-0000-000000000000' AND ...
hxcb's user avatar
  • 23
1 vote
2 answers
1k views

I have a table with ~35M rows, and trying to find "processed" records to remove from time to time. There are 14 valid statuses, and 10 of them are processed. id uuid default uuid_generate_v4(...
JJS's user avatar
  • 6,828
1 vote
1 answer
259 views

I have a non-optimized query with ILIKE filters on 6 columns in the first table, and on one more column in the second table. There are more than 13 million records in the table. This request is ...
Alex Black's user avatar
1 vote
1 answer
57 views

My model: class RecipeTag(models.Model): tag = models.CharField(max_length=300, blank=True, null=True, default=None, db_index=True) recipes = models.ManyToManyField(Recipe, blank=True) ...
Artem Mashin's user avatar
0 votes
2 answers
127 views

I have two columns: column1 with two distinct values (0, 1) and column2 with 3 distinct values ('A', 'B', 'C'). Value in column1 is always 0 for 'A' and 'B' in column2, but if the value in column2 is '...
Bunny Boss's user avatar
1 vote
1 answer
76 views

(All identifiers below are anonymized.) I have the following query in Postgres: SELECT id, dt FROM table1 t1 WHERE status is not null AND ( (NOT EXISTS (SELECT 1 FROM table2 t2 WHERE t2....
jinkins's user avatar
  • 73
1 vote
1 answer
331 views

I have 2 tables in my database as defined below: CREATE TABLE metric_events ( id uuid PRIMARY KEY, metric_id integer NOT NULL, event_at timestamp with time zone NOT NULL, code text NOT ...
user51's user avatar
  • 10.6k
3 votes
2 answers
110 views

I am still a novice to SQL, using PostgreSQL 16.2. create table users( user_id serial primary key ); create table task_pool( task_id serial primary key, order_id integer, clicker_id ...
EyeDunno's user avatar
2 votes
1 answer
108 views

I have a problem where I need to round timestamps representing end dates to the end of the current month or end of the prior month depending on where those timestamps fall relative to NOW() assuming ...
bhub's user avatar
  • 149
0 votes
2 answers
83 views

This is my message table. Now I am trying to write an query to group records by collection_id (only first instance) if type multi-store else by message.id . id | ...
sharingiscaring's user avatar
0 votes
1 answer
87 views

I am using Postgres 14.x. I have a complex query that can be observed, next to it's EXPLAIN ANALYZE, here. select * from (select * from public.select_version_of_projects('2024-03-08T08:31:08.280Z')) ...
Jorge Domínguez Arnáez's user avatar
2 votes
1 answer
960 views

I'm testing how join works with hash index in PostgreSQL 16.2. Here is a test table. Just 2 columns with numbers in text format. create table join_test ( pk varchar(20), fk varchar(20)); ...
Anton Ivanov's user avatar
2 votes
1 answer
101 views

ID Amount Brand 1 10 NULL 1 20 NULL 2 30 Mazada 2 NULL BMW 3 40 NULL 3 40 KIA 4 NULL Honda 4 NULL Honda Above is the original table, and my goal is to find any difference within the same ID for each ...
CCM's user avatar
  • 87
3 votes
2 answers
191 views

Got this question for a while and wondering if there is any faster query. I have a table with multiple entries per ID, and would like to list all columns with different values for the same ID. ID ...
CCM's user avatar
  • 87
6 votes
2 answers
4k views

I have rewritten the below query from using a correlated subquery to using a LATERAL JOIN. It is now faster, and I would like to understand why? This SO answer says that there is no golden rule and ...
Marnix.hoh's user avatar
  • 1,972
2 votes
1 answer
163 views

I have a jsonb column created via sequelize migration this way: queryInterface.addColumn('Entities', 'summary', { type: Sequelize.DataTypes.JSONB, }) My Postgres version: PostgreSQL 15.2 (Debian ...
Joe Beuckman's user avatar
  • 2,296
1 vote
0 answers
109 views

I have two queries that would produce equivalent results (though the subquery one is sorted). However, it seems like the one that uses subquery is faster and I'm not sure why. Could someone explain ...
Jacky Boen's user avatar
0 votes
2 answers
770 views

I have a PostgreSQL (v15) DB view that rolls up a bunch of data per user for a single organization, to display a report of data like fees owed/paid per user, etc. This is executed with an org ID and ...
Brian Moeskau's user avatar
0 votes
0 answers
72 views

I need to query the top few texts that are most similar based on the input content. The table structure is as follows: create table documents ( id bigserial primary ...
accbear's user avatar
  • 23
0 votes
2 answers
108 views

Say you want to optimize a query in a postgres database like: SELECT DISTINCT ON (first) first, second, third FROM my_table WHERE second > 100 AND fourth = 3 ORDER BY first, ...
Rob's user avatar
  • 3,507
3 votes
2 answers
130 views

I'm trying to use a compound (multicolumn) index on a table to assist in creating daily report counts. I am using Postgres 13, and my table looks like this: CREATE TABLE inquiries ( id bigint NOT ...
Brad Pardee's user avatar
0 votes
0 answers
58 views

I have table document with ~2.5 millions rows and more than 100 columns. I provide only used in query columns: CREATE TABLE document ( id serial PRIMARY KEY, organizationid INTEGER, status_1 ...
Bunny Boss's user avatar
0 votes
1 answer
298 views

I currently have a service in C# that uses dapper to call a stored procedure that does 2 things: if the customer exists, it grabs the customer GUID and adds it to the CustomerInformations table; if ...
Master's user avatar
  • 2,173
-1 votes
2 answers
70 views

I have customers and visits table, and I would like to know which of these two queries has the better performance: (I have indexes defined for those columns) Query 1 SELECT customers.id as id, ...
Pablo Alejandro's user avatar
1 vote
2 answers
108 views

In my Postgres 13.10 database, I have a table menus with a JSON column named dishes. This column contains values in the following format: { "desserts": [ {"id": 1, &...
ocratravis's user avatar
0 votes
1 answer
35 views

I have two tables: create table foo( id serial primary key, ts timestamp ); create table bar( id serial primary key, ts_start timestamp, ts_end timestamp ); I need to select all rows from ...
peter ignatiev's user avatar
2 votes
1 answer
366 views

Currently, I'm storing a large amount of time-series data into the following PostgreSQL table: create table view ( user_id uuid, product_id integer, banner_id integer, campaign_id integer, ...
vinnylinux's user avatar
  • 7,064
0 votes
1 answer
68 views

I want to optimize the following DB SELECT query: SELECT ls.caller_id, ls.caller_path_id, ls.caller_path_name, ls.caller_data->>'worker' AS worker,...
Johnny's user avatar
  • 67
1 vote
1 answer
738 views

I have table which has a few billion rows. There are two columns in the table: match_id uuid, group_id integer And there are indexes created on both of the above columns: create index if not exists ...
Sagar's user avatar
  • 5,606

1
2 3 4 5
12