Skip to content
Advertisement

Tag: postgresql

Query condition where a value is in a comma separated string

I have a table in which one of the table columns third_row stores a comma-separated list of numbers as a string but when its value is A then it means a combination of all the possible numbers. How do I approach this so that the query returns all the rows that have the third_row as A and the rest where

raise notice update query result in postgresql

How can I log if field is got updated or not using RAISE NOTICE or some other command if available. Error: Answer I could something like below, but I am not sure if there another UPDATE query followed by current one, ROW_COUNT will hold new result;

I need to get count of total count for the query I had in postgresql

I created a select query as following, now I need to get the total count of the “No.of Ideas generated” column in a separate row as total which will have a count of the individual count of particular idea_sector and idea_industry combination. Query: Output: Required output: Answer You can accomplish this with grouping sets. That’s where we tell postgres, in

is it possible to do a conditional concat?

I have a query that pulls different data but for one field it concats its since the URL is partially filled in my db but the problem is if logourl is blank then I just get https://my_url.com instead of the full URL. This is having down stream impact. Is there a way to only concat if logurl is not null?

Write columns as rows (PostgreSQL)

I have a table: campaign_id media installs content_view date unique_purchase 7564 google 613 45 2021-09-01 1 7564 facebook 21 33 2021-09-02 2 3451 google 83 12 2021-09-01 0 I want to create view: write installs column values as metric_key=installs, metric_name=installs, metric_value=… write content_view and unique_purchase as metric_key=event, metric_name=column_name, metric_value=… id media_source metric_key metric_name metric_value date 7564 google installs installs 613

Postgres – How to achieve UNION behaviour with UNION ALL?

I have a table with parent and child ids. Each parent can have multiple children and each child can have multiple children again. The data looks like this. I’d like to find all children. I can use a recursive cte with a UNION ALL. This gives me the result I’d like to achieve. However I’d like to include the depth

How to pivot in postgresql

I have table like following,and I would like to transform them. I’d like to pivot like following. I tried like following statement, but it returned a lot of null columns. And I wonder I must add columns one by one when new type will be added. If someone has opinion, please let me know. Thanks Answer demo: db<>fiddle You can

Advertisement