Semi-customized queries? Subset of SQL? Accessing the parser? Injection?

Поиск
Список
Период
Сортировка
От Webb Sprague
Тема Semi-customized queries? Subset of SQL? Accessing the parser? Injection?
Дата
Msg-id b11ea23c0811040921x235d92fdg288d42c7174ff123@mail.gmail.com
обсуждение исходный текст
Ответы Re: Semi-customized queries? Subset of SQL? Accessing the parser? Injection?  (Steve Atkins <steve@blighty.com>)
Список pgsql-general
Hi all,

I am writing an application that allows users to analyze demographic
and economic data, and I would like the users to be able to pick
columns, transform columns with functions (economists take the
logarithm of everything), and write customized WHERE and GROUP-BY
clauses. This is kind of like passing through a query to the DB in a
library catalog.

Has anybody found a good way to do this, especially inside the
database from a plpgsql function (select * from custom_query('table1',
'col1 > 100')) ?  I don't want to just concatenate a user supplied
WHERE clause, at least without somehow checking the resulting
statement for (1) only one statement, (2) no data modification
clauses, and (3) only one "level" in the tree.

It seems like if I could interact with an SQL parser through a script,
I could accomplish this relatively easily.  Perhaps SPI can help me
(give me hints!), though I don't really want to write any C.  Perhaps
I am wrong about the possibility of this at all.

I realize that roles and permissions can help protect the system,  but
I still feel nervous.

Has anybody done a similar thing, or tried?  The problem is that if we
try to parameterize everything, then we don't really allow the kind of
data exploration that we are shooting for and these guys / gals are
smart enough to deal with a little syntax.

Thanks!
-W

В списке pgsql-general по дате отправления:

Предыдущее
От: Jason Long
Дата:
Сообщение: Re: JDBC and setting statement_timeout
Следующее
От: "Scott Marlowe"
Дата:
Сообщение: Re: time interval format srting