Skip to content
Advertisement

Tag: postgresql

SQL select items grouped by multiple values

I have table similar this one instance value type ins_1 31 “A” ins_1 81 “B” ins_2 72 “A” ins_3 9 “B” ins_3 9 “C” … and I need select only instance(s) which has double type (A,B). The expected result will be: [“ins1”]. Answer The typical approach here is to aggregate the rows per instance and use conditional aggregation in the

Insert date now + interval 2 days

for some reason I am getting a syntax error: From what I’ve read this should be the correct syntax. Answer The interval value needs to be enclosed in single quotes: The specification ‘2 days’ as a single string is a Postgres extension to the SQL standard. A SQL standard compliant way of writing this would be interval ‘2’ day or

Get distinct members for an array of group IDs

I have 3 tables: Scorecard Group Scorecard_Group (Joint table) I am trying to write a query that fulfills the following purpose: Get the list of distinct scorecard ids WHERE Scorecard_Group.groupId IN (Pass array of groupIds) Get all Scorecard.”name” where Scorecard.”id” IN (Array of scorecardIds that we just queries) I am able to achieve this using 2 queries but I would

PostgreSQL – Adding up json values

This is my json column in pgSQL and I need to add up all of the “sum” amounts using pgSQL. So the query should return “50” using the data below. I did find something like this (Get aggregate sum of json array in Postgres NOSQL json data) that kinda works if I had my values in array, but I dont,

Implement Scan and Value functions in golang

I am trying to store some golang objects in SQL database and have implemented the scanner and value interface as follows: Is there a way that I can pass the parameter to the Value() function by pointers, as I am getting a HugeParam error that the attr passed to the Value() function is too big, when trying to convert the

Combine multiple selects for statistics generation into on result set

Hey Pros, I am far away to have good knowledge about SQL, and would ask you to give me some hints. Currently we aggregate our data with python and I would try to switch this when possible to. (SQL (Postgresql server) My goal is to have one statment that generate an average for two seperates column’s for specific time intervals

Advertisement