Re: Functions which use an argument to decide which table to read
От | Tom Lane |
---|---|
Тема | Re: Functions which use an argument to decide which table to read |
Дата | |
Msg-id | 7317.1255097116@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Functions which use an argument to decide which table to read ("Jonathan Harden" <jonathan.harden@zeninternet.co.uk>) |
Список | pgsql-novice |
"Jonathan Harden" <jonathan.harden@zeninternet.co.uk> writes: > I am trying to write a function which takes an argument and uses that > argument to return a set of rows from a table with the name given (or > possibly inferred) from the argument. You'd need to construct the SELECT command as a string and then EXECUTE it. Your other problem is that you don't know what row type the function is going to return, and there's no really nice way around that --- you could try declaring it as RETURNS SETOF RECORD, but then you'd have to have every calling query specify what type the result is, and that's never any fun. On the whole, this suggests to me that you've got a bad database schema design and you need to reconsider things at that level. I think what you're trying to do is effectively a form of EAV (entity-attribute-value) which just does not play very nicely with SQL databases. It's usually better to take the time up-front to nail down a better-specified model of your data. If you can't, a SQL database may not be the tool to be using. regards, tom lane
В списке pgsql-novice по дате отправления: