5 ms·
> It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea. OK, what's the reason then? I didn't hear you giv
by WayneBro 10y ago
> It's a bad idea for the same reason that having a function that returns back multiple values is a bad idea.
OK, what's the reason then? I didn't hear you give one.
Every PGSQL query already return multiple values because you get a command status along with the result set.
Every Golang call returns 2 values. They even make it very easy for you to return even more values. So what is your reasoning?
- koolba 10y ago> 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.
- WayneBro 10y agoHe gave an opinion. That is not a reason.
- jhall1468 10y agoHe did give you one, you just aren't listening. 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.
- mgkimsal 10y ago> Do two queries. The problem is already solved. 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.
- Someone 10y ago"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.