Skip to content

Tag: postgresql

Is order preserved after UNION in PostgreSQL?

Here is the code: As you can see the recursive code gives the result in right order, but the non-recursive code does not. They both use union, why the difference? Answer Basically, your query is incorrect to begin with. Use UNION ALL, not UNION or you would incorrectly remove duplicate entries. (There is noth…

Return first element in array_agg()

I am writing a query to get all players for all teams. Instead of looping in the application, I decided to get the players of all teams in a single query using array_agg(). I have written the query as follows: This query gives me the result as below, in the result set the teamname is being repeated (exactly t…

Can’t extract string from database sql

My aim is to test if the user and password inserted, existed in Table1. However, if I typed (pink,floyd) which exists in the database count still null and it appears the message “user doesn’t exist”. Here’s my database : Answer It turns that the stocked user and pass parameters in Tabl…