create temp table in rule

From: Ron Peterson <rpeterso(at)mtholyoke(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: create temp table in rule
Date: 2006-04-18 18:42:10
Message-ID: 20060418184209.GB31915@mtholyoke.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Is it possible to create a temporary table within a rule?

I get a syntax error near 'CREATE TEMPORARY TABLE' if I try to do the
following:

CREATE RULE id_insert_rule AS
ON INSERT TO id_insert
DO INSTEAD
(
CREATE TEMPORARY TABLE id_temp (
LIKE
id )
ON COMMIT DELETE ROWS;

INSERT INTO id_temp (
username,
pass_md5,
pass_sha1 )
VALUES
new.username,
encode( digest( new.password, 'md5' ), 'hex' ),
encode( digest( new.password, 'sha1' ), 'hex' );

DELETE FROM
id
USING
id_temp
WHERE
id.username = id_temp.username;

INSERT INTO
id
SELECT
*
FROM
id_temp;
);

As you can see, I'm trying to create a simple 'insert or update' rule.

--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mark True 2006-04-18 18:44:29 Re: Looking for some help with cascading updates...
Previous Message Andreas Kretschmer 2006-04-18 18:31:01 Re: Looking for some help with cascading updates...