> You didn't state a single reason why you think that grabbing multiple resultsets in a single trip to the database is a bad idea though...
It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea. Yes it's useful sometimes but on the whole it ends up being confusing. From a result set processing perspective it's also a pain in the ass as your app code is now tied to handling multiple results in a particular order, i.e., more/tighter coupling.
> (I bet you've UPDATEd multiple tables in one query though.)
You'd win that bet. There are a lot of ways to do this and it's a legit operation because you want N things to change at once (where N isn't in the same table).
> Reasons are often given, sure...but they're almost never based on that persons experience because PGSQL users don't have this feature. So, they'll never know just how awesome it is to have real stored procedures like TSQL has.
> Anyway, it's not about "jamming" things into one query. It's about composability and PGSQL is lacking it.
What's your goto "killer example" of what this could be used for?
I've used SQL Server quite a bit[1] and while it's not a terrible database, on the whole I don't like it. Rattling off at random: lack of MVCC (sure they have it now but it's not the default and still has warts), explicit locking that drives you nuts, defaulting to case insensitive string comparison, lack of built in functions. The inane licensing options don't help either.
I'd take Postgres over SQL Server any day of the week and twice on Sundays (i.e. side projects).
[1]: Officer I swear! It was already like that when I got there!
Having a function return the minimum and maximum of an array is returning one value. The value is an array of size 2. Having a function return an array of the minimum, maximum and the number of states in a given country is returning two values.
You are asking PG to return multiple unrelated data sets. The number of use cases that this is useful and good is pretty much for displaying reports. Do two queries. The problem is already solved.
"You are asking PG to return multiple unrelated data sets
Who talked about 'unrelated'?
Just as one can return min, max, average and standard deviation of column C in table T in one call, one can, for example, return that, the top ten records with highest C value and the records with the top ten most common values for C.
Yes, you can do two queries, but doing them in one go can be faster, some times much faster.
The risk, of course, is that one gets "one stored procedure per screen", but as long as one is aware of that, I don't see anything inherently wrong with that.
I can think of a handful of scenarios where the second result set needs to be based on something from the first, and combining them can make some sense in that case, but it's a stretch. For "long running process" or "slow query time" arguments... eh... that may be a problem, but it'd be very much an edge case for most users of the DB engine in question.
Dunno if Oracle supports this or not, but pretty sure MySQL doesn't and PG doesn't. MSSQL is the only DB engine I know that supports multiple result sets from one stored procedure. If you want to tie yourself to features of just one DB, that's great - most people do in one way or another, just don't expect everyone else to support that particular feature or syntax.
> OK, what's the reason then? I didn't hear you give one.
Read the rest of that paragraph. You only quoted the first sentence.
> Every PGSQL query already return multiple values because you get a command status along with the result set.
And most generic database driver interfaces (ex: JDBC) return that out of band. Errors get turned into exceptions and update counts get returned back as integers. That's far from perfect (particularly with JDBC) but it's usually done to fit the programming paradigms of the driver's native language.
> Every Golang call returns 2 values. They even make it very easy for you to return even more values. So what is your reasoning?
That's because Golang doesn't have exceptions. Every function that could fail needs to indicate if there's an error. It's like errno in C but per-function.
> It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea.
Every single language that lacks multiple return values has some kind of hack to compensate, like varying parameters, that breaks encapsulation and makes code inconsistent.
On a tuple, yes. That's how most language implement returning multiple values, but you need good accessors. On a struct you'll need to declare it first.
It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea. Yes it's useful sometimes but on the whole it ends up being confusing. From a result set processing perspective it's also a pain in the ass as your app code is now tied to handling multiple results in a particular order, i.e., more/tighter coupling.
> (I bet you've UPDATEd multiple tables in one query though.)
You'd win that bet. There are a lot of ways to do this and it's a legit operation because you want N things to change at once (where N isn't in the same table).
> Reasons are often given, sure...but they're almost never based on that persons experience because PGSQL users don't have this feature. So, they'll never know just how awesome it is to have real stored procedures like TSQL has.
> Anyway, it's not about "jamming" things into one query. It's about composability and PGSQL is lacking it.
What's your goto "killer example" of what this could be used for?
I've used SQL Server quite a bit[1] and while it's not a terrible database, on the whole I don't like it. Rattling off at random: lack of MVCC (sure they have it now but it's not the default and still has warts), explicit locking that drives you nuts, defaulting to case insensitive string comparison, lack of built in functions. The inane licensing options don't help either.
I'd take Postgres over SQL Server any day of the week and twice on Sundays (i.e. side projects).
[1]: Officer I swear! It was already like that when I got there!