Re: How do I insert a record into a table?

Поиск
Список
Период
Сортировка
От Brian Hurt
Тема Re: How do I insert a record into a table?
Дата
Msg-id 46607F8A.5050306@janestcapital.com
обсуждение исходный текст
Ответ на Re: How do I insert a record into a table?  (Michael Glaesemann <grzm@seespotcode.net>)
Ответы Re: How do I insert a record into a table?  (Michael Glaesemann <grzm@seespotcode.net>)
Список pgsql-novice
Michael Glaesemann wrote:

>
> On Jun 1, 2007, at 14:54 , Brian Hurt wrote:
>
>> This is the current solution I'm going with. The main problem I  have
>> with this is stylistic- it changes the result psql displays  from an
>> insert response to a select response.
>
>
> If you'd like, you could throw in a RAISE NOTICE (or other level) so
> you get some other information.


If I just do an insert into the table, I see:
bhurt_dev=# INSERT INTO test1(id, name) VALUES (1, 'foo');
INSERT 0 1
bhurt_dev=#

But if I define:
CREATE FUNCTION insert_test1(p_id INT, p_name VARCHAR) RETURNS VOID
AS $_$
BEGIN
    INSERT INTO test1(id, name) VALUES(p_id, p_name);
END
$_$ LANGUAGE plpgsql;

CREATE VIEW view1 AS SELECT * FROM test1;

CREATE RULE rule1 AS ON INSERT TO view1 DO INSTEAD SELECT
insert_test1(NEW.id, NEW.name);

and then do:
bhurt_dev=# INSERT INTO view1(id, name) VALUES (2, 'bar');
 insert_test1
--------------

(1 row)

bhurt_dev=#

See the difference?

It's stylistic, and doesn't actually change anything.

Brian


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

Предыдущее
От: "Robert Wimmer"
Дата:
Сообщение: Feed a table function with a query
Следующее
От: Derrick Betts
Дата:
Сообщение: Re: Feed a table function with a query