From: | Brian Hurt <bhurt(at)janestcapital(dot)com> |
---|---|
To: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: How do I insert a record into a table? |
Date: | 2007-06-01 20:20:26 |
Message-ID: | 46607F8A.5050306@janestcapital.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Derrick Betts | 2007-06-01 20:31:12 | Re: Feed a table function with a query |
Previous Message | Robert Wimmer | 2007-06-01 20:18:19 | Feed a table function with a query |