![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I would like to create a function that accepts an array of IDs (integers) and loops over them, returning the the rows (setof rowtype...?) that match them. |
|
As a final extension, I would like to be able to return rows formed by a join across a few tables (return a setof RECORD type?). I suppose I can just create the view I like then use a similar function to the single-table version.... |
#3
| |||
| |||
|
|
You could return SETOF RECORD but then your queries will need to provide a column definition list. Another way would be to create a custom type that describes a result record and return SETOF that type. But before you do any of this, perhaps you should think about whether you really need a function at all, or whether you can use views and WHERE clauses. |
#4
| |||
| |||
|
|
You could return SETOF RECORD but then your queries will need to provide a column definition list. Another way would be to create a custom type that describes a result record and return SETOF that type. But before you do any of this, perhaps you should think about whether you really need a function at all, or whether you can use views and WHERE clauses. Michael, Thanks for the reply. The reason all of this comes up is that I have an application in which the user can create "sets" of IDs. I then want to be able to do logical operations on the sets of IDs and then return the database objects based on the ID's in those sets. I tried the function version using "ANY" and the simple query using "IN" and found an order of magnitude difference in speed (IN is faster). So, it appears that using views and where clauses is the way to go here. One last question--is there a limit to the length of a SQL query (in terms of characters), as some of these sets could be very large (up to 40000 integers)? |
#5
| |||
| |||
|
|
Thanks for the reply. The reason all of this comes up is that I have an application in which the user can create "sets" of IDs. I then want to be able to do logical operations on the sets of IDs and then return the database objects based on the ID's in those sets. I tried the function version using "ANY" and the simple query using "IN" and found an order of magnitude difference in speed (IN is faster). So, it appears that using views and where clauses is the way to go here. One last question--is there a limit to the length of a SQL query (in terms of characters), as some of these sets could be very large (up to 40000 integers)? |
![]() |
| Thread Tools | |
| Display Modes | |
| |