So I have a Table A that is missing a relation with Table B such that I want to add the relationship information preserving the order based on insert. Table B can have multiple pieces where UUIDs are unique to a grouping and the order is preserved by and index. So I can have in Table B: What I want
Tag: postgresql
UPDATE VALUES OF COLUMN IN POSTGRESQL
I have 4 tables: what i want is to update table1 with the salary values from matchsal table with conditions in the others tables, i tried this query: and i got this error: ERROR: more than one row returned by a subquery used as an expression SQL state: 21000 Answer I found the answer ^^” It is simple th…
How to calculate the difference between current row and the last row of last month?
I have a postgres table net_value as above, one row one day. How can I calculate the difference between current row and the last row of last month? Look like the output as below: Thanks! Answer Hmmm . . . Here is a method with a join: I also think an approach using window functions and a window frame should
Case statement in multiple conditions?
I want to check the column mr.name, if mr.name is null then i have to replace mr.name as mr.ticket_no. How? Can use if else or case? When i use like this it will throw an error if mr.name = null means i have to replace mr.name = mr.ticket_no. I want to check the column mr.name, if mr.name is null then
Using NEW and COPY in a Postgres Trigger
I’m trying to copy the last inserted row from a table into a csv file using a trigger. I’ve tried this in various incarnations, with or without EXECUTE but I’m still getting the error. Just cannot get it to access the NEW data. Where am I going wrong ? Answer Adrian’s answer inspired m…
How can I write a SQL query to calculate the quantity of components sold with their parent assemblies? (Postgres 11/recursive CTE?)
My goal To calculate the sum of components sold as part of their parent assemblies. I’m sure this must be a common use case, but I haven’t yet found documentation that leads to the result I’m looking for. Background I’m running Postgres 11 on CentOS 7. I have some tables like as follow…
Sequelize – Include based on specific attribute
I have a model defined as follows: I’m trying to use Sequelize to load all game object and include the User with the id equal to the playerId field. The problem is I have two attributes (leaderId, playerId) which reference the User model so using include as follows does not work: Is there a way to speci…
Display both values of same column after comparing rows (with inner join)
When you perform an inner join to compare 2 values of the same column, but different rows, with eachother. How do you include both compared values of the same column? Without error “column specified more than once” In the new table I want to see a.var2 and b.var2. Answer You need alias names for t…
How to carry over latest observed record when grouping by on SQL?
(I’ve created a similar question before, but I messed it up beyond repair. Hopefully, I can express myself better this time.) I have a table containing records that change through time, each row representing a modification in Stage and Amount. I need to group these records by Day and Stage, summing up t…
User Defined Column name in select statement in Hivesql
I need to create user defined column name like below Postgresql query into HiveSql. Could you please help me on this. Answer Use backticks: But it is not possible to preserve case due to Hive limitation. Resulted column name will be in lower case: total customers See this answer: https://stackoverflow.com/a/5…