Remove gratuitous uses of deprecated SELECT INTO
authorPeter Eisentraut <[email protected]>
Thu, 28 Jan 2021 13:01:41 +0000 (14:01 +0100)
committerPeter Eisentraut <[email protected]>
Thu, 28 Jan 2021 13:28:41 +0000 (14:28 +0100)
CREATE TABLE AS has been preferred over SELECT INTO (outside of ecpg
and PL/pgSQL) for a long time.  There were still a few uses of SELECT
INTO in tests and documentation, some old, some more recent.  This
changes them to CREATE TABLE AS.  Some occurrences in the tests remain
where they are specifically testing SELECT INTO parsing or similar.

Discussion: https://www.postgresql.org/message-id/flat/96dc0df3-e13a-a85d-d045-d6e2c85218da%40enterprisedb.com

15 files changed:
contrib/sepgsql/expected/label.out
contrib/sepgsql/sql/label.sql
doc/src/sgml/hstore.sgml
src/bin/pg_basebackup/t/010_pg_basebackup.pl
src/bin/pg_checksums/t/002_actions.pl
src/test/regress/expected/create_index.out
src/test/regress/expected/create_misc.out
src/test/regress/expected/random.out
src/test/regress/expected/select_implicit.out
src/test/regress/expected/select_implicit_1.out
src/test/regress/expected/select_implicit_2.out
src/test/regress/sql/create_index.sql
src/test/regress/sql/create_misc.sql
src/test/regress/sql/random.sql
src/test/regress/sql/select_implicit.sql

index 0300bc6fb45e17c621df622821e5e06f88ccd676..b1b7db55f67ab9af4612382c500075b257556c20 100644 (file)
@@ -6,7 +6,7 @@
 --
 CREATE TABLE t1 (a int, b text);
 INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');
-SELECT * INTO t2 FROM t1 WHERE a % 2 = 0;
+CREATE TABLE t2 AS SELECT * FROM t1 WHERE a % 2 = 0;
 CREATE FUNCTION f1 () RETURNS text
     AS 'SELECT sepgsql_getcon()'
     LANGUAGE sql;
index d19c6edb4ca8f4d7c315474baef09a22342e2048..76e261bee8037107eb0d8fc8595a5e4582315536 100644 (file)
@@ -7,7 +7,7 @@
 --
 CREATE TABLE t1 (a int, b text);
 INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');
-SELECT * INTO t2 FROM t1 WHERE a % 2 = 0;
+CREATE TABLE t2 AS SELECT * FROM t1 WHERE a % 2 = 0;
 
 CREATE FUNCTION f1 () RETURNS text
     AS 'SELECT sepgsql_getcon()'
index 080706280e80954b6041292eefee742e54e65223..e867fcc5aee55c4c13d82567a37a3b3d8ac72c80 100644 (file)
@@ -883,7 +883,7 @@ SELECT * FROM each('aaa=&gt;bq, b=&gt;NULL, ""=&gt;1');
   <para>
    Using a table:
 <programlisting>
-SELECT (each(h)).key, (each(h)).value INTO stat FROM testhstore;
+CREATE TABLE stat AS SELECT (each(h)).key, (each(h)).value FROM testhstore;
 </programlisting>
   </para>
 
index f674a7c94e70e4e25021834d5a9ef5cbbfe8eee1..9eba7d8d7d260b2e8862046dad9ec4fde3ca7b6a 100644 (file)
@@ -502,10 +502,10 @@ rmtree("$tempdir/backupxs_sl_R");
 
 # create tables to corrupt and get their relfilenodes
 my $file_corrupt1 = $node->safe_psql('postgres',
-   q{SELECT a INTO corrupt1 FROM generate_series(1,10000) AS a; ALTER TABLE corrupt1 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt1')}
+   q{CREATE TABLE corrupt1 AS SELECT a FROM generate_series(1,10000) AS a; ALTER TABLE corrupt1 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt1')}
 );
 my $file_corrupt2 = $node->safe_psql('postgres',
-   q{SELECT b INTO corrupt2 FROM generate_series(1,2) AS b; ALTER TABLE corrupt2 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt2')}
+   q{CREATE TABLE corrupt2 AS SELECT b FROM generate_series(1,2) AS b; ALTER TABLE corrupt2 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt2')}
 );
 
 # set page header and block sizes
index 4e4934532a30d27520d7d72ecbedaa03f64ff2ec..8a81f36a067fdac7aa149c4ab7ed32d0c255b101 100644 (file)
@@ -21,7 +21,7 @@ sub check_relation_corruption
 
    $node->safe_psql(
        'postgres',
-       "SELECT a INTO $table FROM generate_series(1,10000) AS a;
+       "CREATE TABLE $table AS SELECT a FROM generate_series(1,10000) AS a;
        ALTER TABLE $table SET (autovacuum_enabled=false);");
 
    $node->safe_psql('postgres',
index fc6afab58ab307148af5d3ae9d9834917adf0c2f..ce734f7ef36bec12210f2bb4c25ac6ef9f541a6c 100644 (file)
@@ -1582,7 +1582,7 @@ DROP TABLE syscol_table;
 --
 -- Tests for IS NULL/IS NOT NULL with b-tree indexes
 --
-SELECT unique1, unique2 INTO onek_with_null FROM onek;
+CREATE TABLE onek_with_null AS SELECT unique1, unique2 FROM onek;
 INSERT INTO onek_with_null (unique1,unique2) VALUES (NULL, -1), (NULL, NULL);
 CREATE UNIQUE INDEX onek_nulltest ON onek_with_null (unique2,unique1);
 SET enable_seqscan = OFF;
index cee35ed02f161993a5e7656de597bef5d90a4f4c..41bc4d77507fbb635327bc968134a969d1aedf4c 100644 (file)
@@ -5,7 +5,7 @@
 -- (any resemblance to real life is purely coincidental)
 --
 INSERT INTO tenk2 SELECT * FROM tenk1;
-SELECT * INTO TABLE onek2 FROM onek;
+CREATE TABLE onek2 AS SELECT * FROM onek;
 INSERT INTO fast_emp4000 SELECT * FROM slow_emp4000;
 SELECT *
    INTO TABLE Bprime
index 302c3d61c7a591f689b6d7bf8839d934f43d5077..a919b28d8daa8c3109212d724b6fdf2ddec8ee69 100644 (file)
@@ -23,7 +23,8 @@ INTERSECT
 (0 rows)
 
 -- count roughly 1/10 of the tuples
-SELECT count(*) AS random INTO RANDOM_TBL
+CREATE TABLE RANDOM_TBL AS
+  SELECT count(*) AS random
   FROM onek WHERE random() < 1.0/10;
 -- select again, the count should be different
 INSERT INTO RANDOM_TBL (random)
index 61b485fdaae915d9d7c3993cb4c704d172f94ee7..27c07de92cc94627175db7efb04a3f1ec0ab570a 100644 (file)
@@ -202,7 +202,8 @@ SELECT count(*) FROM test_missing_target x, test_missing_target y
 
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(*) INTO TABLE test_missing_target2
+CREATE TABLE test_missing_target2 AS
+SELECT count(*)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b ORDER BY x.b;
@@ -318,7 +319,8 @@ LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
                      ^
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(x.b) INTO TABLE test_missing_target3
+CREATE TABLE test_missing_target3 AS
+SELECT count(x.b)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b/2 ORDER BY x.b/2;
index f277375ebfc978a077952f3f6f88350aa0d827d4..d67521e8f83c6ccd3b92287fe6e119c6c9623eab 100644 (file)
@@ -202,7 +202,8 @@ SELECT count(*) FROM test_missing_target x, test_missing_target y
 
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(*) INTO TABLE test_missing_target2
+CREATE TABLE test_missing_target2 AS
+SELECT count(*)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b ORDER BY x.b;
@@ -318,7 +319,8 @@ LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
                      ^
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(x.b) INTO TABLE test_missing_target3
+CREATE TABLE test_missing_target3 AS
+SELECT count(x.b)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b/2 ORDER BY x.b/2;
index 91c3a24f92aa3cbb06cf7ff2d33ac8ecbc0d432b..7a353d086271d68a6ea1dda3e2399b1e1f80d308 100644 (file)
@@ -202,7 +202,8 @@ SELECT count(*) FROM test_missing_target x, test_missing_target y
 
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(*) INTO TABLE test_missing_target2
+CREATE TABLE test_missing_target2 AS
+SELECT count(*)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b ORDER BY x.b;
@@ -318,7 +319,8 @@ LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
                      ^
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(x.b) INTO TABLE test_missing_target3
+CREATE TABLE test_missing_target3 AS
+SELECT count(x.b)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b/2 ORDER BY x.b/2;
index 824cb9f9e82c8a8cc9d68e2abd8d9bd68a89f6b5..fd4f30876e18850964660ff69936c0b8a3fdaf28 100644 (file)
@@ -609,7 +609,7 @@ DROP TABLE syscol_table;
 -- Tests for IS NULL/IS NOT NULL with b-tree indexes
 --
 
-SELECT unique1, unique2 INTO onek_with_null FROM onek;
+CREATE TABLE onek_with_null AS SELECT unique1, unique2 FROM onek;
 INSERT INTO onek_with_null (unique1,unique2) VALUES (NULL, -1), (NULL, NULL);
 CREATE UNIQUE INDEX onek_nulltest ON onek_with_null (unique2,unique1);
 
index d0b04a821f8115b54b0bbd5ffd0ceb79f4d2ec6a..c7d0d064c3784d4192bff162fee8d8dcb148b401 100644 (file)
@@ -8,7 +8,7 @@
 
 INSERT INTO tenk2 SELECT * FROM tenk1;
 
-SELECT * INTO TABLE onek2 FROM onek;
+CREATE TABLE onek2 AS SELECT * FROM onek;
 
 INSERT INTO fast_emp4000 SELECT * FROM slow_emp4000;
 
index ae6b70a157bd1222ed0aa80606dab161b8df2bb0..8187b2c288ab895fff0e2d008c81f7d1326cd80b 100644 (file)
@@ -17,7 +17,8 @@ INTERSECT
   FROM onek ORDER BY random() LIMIT 1);
 
 -- count roughly 1/10 of the tuples
-SELECT count(*) AS random INTO RANDOM_TBL
+CREATE TABLE RANDOM_TBL AS
+  SELECT count(*) AS random
   FROM onek WHERE random() < 1.0/10;
 
 -- select again, the count should be different
index d81550422292e35d42b6b9d6d176b9034b5d8009..de3aef8d81c708f87978cda837dd6e8fe27c3046 100644 (file)
@@ -86,7 +86,8 @@ SELECT count(*) FROM test_missing_target x, test_missing_target y
 
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(*) INTO TABLE test_missing_target2
+CREATE TABLE test_missing_target2 AS
+SELECT count(*)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b ORDER BY x.b;
@@ -142,7 +143,8 @@ SELECT count(b) FROM test_missing_target x, test_missing_target y
 
 --   group w/o existing GROUP BY target under ambiguous condition
 --   into a table
-SELECT count(x.b) INTO TABLE test_missing_target3
+CREATE TABLE test_missing_target3 AS
+SELECT count(x.b)
 FROM test_missing_target x, test_missing_target y
    WHERE x.a = y.a
    GROUP BY x.b/2 ORDER BY x.b/2;