Re: triggers and execute...

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: triggers and execute...
Дата
Msg-id 20090429220742.GD6316@alvh.no-ip.org
обсуждение исходный текст
Ответ на Re: triggers and execute...  (Scott Marlowe <scott.marlowe@gmail.com>)
Список pgsql-general
Scott Marlowe escribió:

> Oh man, it just gets worse.  I really need a simple elegant solution
> here, because if I try to build the query by hand null inputs make
> life a nightmare.  I had built something like this:
>
> q = 'insert into '||schem||'.page_access_'||part||' values (
>                 '||new.paid||',
>                 '''||new.timestamp||''',
>                 '||new.total_time||',
>                 '''||new.http_host||''',
>                 '''||new.php_self||''',
>                 '''||new.query_string||''',
>                 '''||new.remote_addr||''',
>                 '''||new.logged_in||''',
>                 '||new.uid||',
>                 '''||new.http_user_agent||''',
>                 '''||new.server_addr||''',
>                 '''||new.notes||'''
>         )';
>         execute q;
>
> But if any of the fields referenced are null, the whole query string
> is now null.  So the next step is to use coalesce to build a query
> string?  That get insane very quickly.  There's got to be some quoting
> trick or something to let me use new.*, please someone see this and
> know what that trick is.

Agreed, it is ugly.  I don't think there's a better way to do it though.

One thing you could try is getting the column names and types from the
catalogs to build the insert statement.  That way you don't have to list
each column separately, and you don't need to fiddle with whether each
value needs quotes or not.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

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

Предыдущее
От: paulo matadr
Дата:
Сообщение: Understand this error
Следующее
От: "Michael P. Soulier"
Дата:
Сообщение: Re: how do you get there from here?