Re: How do I insert a record into a table? - Mailing list pgsql-novice

From Brian Hurt
Subject Re: How do I insert a record into a table?
Date
Msg-id 46607F8A.5050306@janestcapital.com
Whole thread Raw
In response to Re: How do I insert a record into a table?  (Michael Glaesemann <grzm@seespotcode.net>)
Responses Re: How do I insert a record into a table?
List 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 by date:

Previous
From: "Robert Wimmer"
Date:
Subject: Feed a table function with a query
Next
From: Derrick Betts
Date:
Subject: Re: Feed a table function with a query