Skip to content
Advertisement

Tag: postgresql

How to Aggregate 15 minute Time series into 1 hour intervals in Postgres

In my PostgreSQL database I have a very large (over 40 mil) row table that represents traffic counts for various locations by 15 minute interval timestamps (contained in the “starttime” column). I want to bin these intervals into hourly intervals to reduce the number of rows. The format is “timestamp without time zone” so that each record looks like this:

Constraint on size of array type in Postgres

I have the following schema for a table (simplified for the sake of discussion) : A task transitions from NOT_SOLVED TO SOLVED when array_length(current_solved_by) == max_solved_by Questions: Is it a good practice to maintain another column, in this case state, which can be derived from other data (Based on size of currently_solved_by. Main reason I added the state is to

How to condense returned rows of users with multiple roles

I’m trying to wrap my head around this logic, but simply having a tough time. While trying to keep the database normalized, users can have multiple roles (example shows 2, but could have more than 2, currently have 6 total roles), and I’d like to return data to make it easily viewed on a front end UI. Tables simplified: USERS

Format JSONB column by taking the text value from same jsonb coulmn

CREATE TABLE test(id serial, data jsonb); INSERT INTO test(data) values (‘dummydata-got-uploaded’); I need to correct the jsonb column value with below query. update test set data={“addDet”: data }::jsonb where id =1; ERROR: syntax error at or near “{” LINE 1: update test set data={“addDet”: data… Expected: id | data 1 | {“addDet”: ‘dummydata-got-uploaded’ } ` Thanks in advance. Answer you

Advertisement