Skip to content

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;

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…

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 dem…