Skip to content

Tag: postgresql

Postgres not returning data on array_agg query as below

The problem arise when there are no data for books in specific library. Consider a following working scenario. Table name: library Table name: books Now when I do query like below: The query generates output for library 1 & 2, but not for library 3. Why and how to solve this issue? (Generate an empty list…

PostgreSQL – How to format an int as an hexa

What’s a short/simplest way of formatting an int to an hexa, with leading zeroes? For example I need to format: My query needs many of these conversions I would appreciate a short piece of code instead of a verbose one. Just need to deal with positive numbers. Answer I’m not sure it’s the sh…

Insert data into Postgresql with duplicate values

I need to insert dataset in postgresql. the problem is that there are many duplicate values in the request. As the result database should involve Or nothing if this dataset is in database. How should I make my query? P.S. The table is: Answer If you don’t want duplicates inserted, then add a unique inde…

Subselect on multiples values with like operator

How to subselect on multiple values where like operator is included? I build Table B with the ‘%’ to get all values from Table A with the like-operator. I can get the I-values from Table A with SELECT * FROM TABLE A WHERE VAL LIKE (‘I33.%’) but i build Table B to go through the whole t…