Skip to content

Tag: postgresql

Upsert on an array column

I am trying to do an upsert on the array column but I am not able to achieve the following result. Table name settings id primary key unique user_id foreign_key integer unique friends array tags …

posgresql exclude zero division error results

I am executing a query but for sum cases this part of the code results into zero which causes zero division error.I am trying to not show result(not select) when Pease help. Answer The simplest way is to remove the else 0: This returns NULL if nothing matches the condition. Dividing by NULL produces NULL and …

Recreating relation between two tables

I have a 1:1 relation between data that was not an explicit foreign key in the database. E.g. Table 1 has a once, b twice and c once Table 2 also has a once, b twice and c once I want to create a foreign key from Table 1 to Table 2 when the value is the same: Expected Table