2000-01-06 07:40:54 +01:00
|
|
|
--
|
|
|
|
-- SELECT_INTO
|
|
|
|
--
|
|
|
|
SELECT *
|
1999-02-02 04:45:56 +01:00
|
|
|
INTO TABLE tmp1
|
2000-06-04 19:52:54 +02:00
|
|
|
FROM onek
|
1997-04-06 10:29:57 +02:00
|
|
|
WHERE onek.unique1 < 2;
|
2000-01-06 07:40:54 +01:00
|
|
|
DROP TABLE tmp1;
|
|
|
|
SELECT *
|
1999-02-02 04:45:56 +01:00
|
|
|
INTO TABLE tmp1
|
2000-06-04 19:52:54 +02:00
|
|
|
FROM onek2
|
1997-04-06 10:29:57 +02:00
|
|
|
WHERE onek2.unique1 < 2;
|
2000-01-06 07:40:54 +01:00
|
|
|
DROP TABLE tmp1;
|
2011-11-22 22:16:26 +01:00
|
|
|
--
|
|
|
|
-- SELECT INTO and INSERT permission, if owner is not allowed to insert.
|
|
|
|
--
|
|
|
|
CREATE SCHEMA selinto_schema;
|
|
|
|
CREATE USER selinto_user;
|
|
|
|
ALTER DEFAULT PRIVILEGES FOR ROLE selinto_user
|
|
|
|
REVOKE INSERT ON TABLES FROM selinto_user;
|
|
|
|
GRANT ALL ON SCHEMA selinto_schema TO public;
|
|
|
|
SET SESSION AUTHORIZATION selinto_user;
|
|
|
|
SELECT * INTO TABLE selinto_schema.tmp1
|
|
|
|
FROM pg_class WHERE relname like '%a%'; -- Error
|
|
|
|
ERROR: permission denied for relation tmp1
|
|
|
|
SELECT oid AS clsoid, relname, relnatts + 10 AS x
|
|
|
|
INTO selinto_schema.tmp2
|
|
|
|
FROM pg_class WHERE relname like '%b%'; -- Error
|
|
|
|
ERROR: permission denied for relation tmp2
|
|
|
|
CREATE TABLE selinto_schema.tmp3 (a,b,c)
|
|
|
|
AS SELECT oid,relname,relacl FROM pg_class
|
|
|
|
WHERE relname like '%c%'; -- Error
|
|
|
|
ERROR: permission denied for relation tmp3
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
ALTER DEFAULT PRIVILEGES FOR ROLE selinto_user
|
|
|
|
GRANT INSERT ON TABLES TO selinto_user;
|
|
|
|
SET SESSION AUTHORIZATION selinto_user;
|
|
|
|
SELECT * INTO TABLE selinto_schema.tmp1
|
|
|
|
FROM pg_class WHERE relname like '%a%'; -- OK
|
|
|
|
SELECT oid AS clsoid, relname, relnatts + 10 AS x
|
|
|
|
INTO selinto_schema.tmp2
|
|
|
|
FROM pg_class WHERE relname like '%b%'; -- OK
|
|
|
|
CREATE TABLE selinto_schema.tmp3 (a,b,c)
|
|
|
|
AS SELECT oid,relname,relacl FROM pg_class
|
|
|
|
WHERE relname like '%c%'; -- OK
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
DROP SCHEMA selinto_schema CASCADE;
|
|
|
|
NOTICE: drop cascades to 3 other objects
|
|
|
|
DETAIL: drop cascades to table selinto_schema.tmp1
|
|
|
|
drop cascades to table selinto_schema.tmp2
|
|
|
|
drop cascades to table selinto_schema.tmp3
|
|
|
|
DROP USER selinto_user;
|
2012-01-05 00:30:55 +01:00
|
|
|
--
|
|
|
|
-- CREATE TABLE AS/SELECT INTO as last command in a SQL function
|
|
|
|
-- have been known to cause problems
|
|
|
|
--
|
|
|
|
CREATE FUNCTION make_table() RETURNS VOID
|
|
|
|
AS $$
|
|
|
|
CREATE TABLE created_table AS SELECT * FROM int8_tbl;
|
|
|
|
$$ LANGUAGE SQL;
|
|
|
|
SELECT make_table();
|
|
|
|
make_table
|
|
|
|
------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT * FROM created_table;
|
|
|
|
q1 | q2
|
|
|
|
------------------+-------------------
|
|
|
|
123 | 456
|
|
|
|
123 | 4567890123456789
|
|
|
|
4567890123456789 | 123
|
|
|
|
4567890123456789 | 4567890123456789
|
|
|
|
4567890123456789 | -4567890123456789
|
|
|
|
(5 rows)
|
|
|
|
|
|
|
|
DROP TABLE created_table;
|