From b6e5c4ad0a815380c6c509b4c8193850334ddb1b Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 1 Jun 2005 23:27:03 +0000
Subject: [PATCH] Fix log_statement to properly recognize SELECT INTO and
 CREATE TABLE AS and DDL statements.

Backpatch fix to 8.0.X.

Per report from Murthy Kambhampaty
---
 src/backend/tcop/postgres.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 3c6c6d992ed..fcb93d847d5 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.444 2005/05/24 04:18:04 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.445 2005/06/01 23:27:03 momjian Exp $
  *
  * NOTES
  *	  this is the "main" module of the postgres backend and
@@ -498,7 +498,8 @@ log_after_parse(List *raw_parsetree_list, const char *query_string,
 		if (IsA(parsetree, PrepareStmt))
 			parsetree = (Node *) (((PrepareStmt *) parsetree)->query);
 
-		if (IsA(parsetree, SelectStmt))
+		if (IsA(parsetree, SelectStmt) &&
+			((SelectStmt *) parsetree)->into == NULL)
 			continue;		/* optimization for frequent command */
 
 		if (log_statement == LOGSTMT_MOD &&
@@ -514,6 +515,7 @@ log_after_parse(List *raw_parsetree_list, const char *query_string,
 		if ((log_statement == LOGSTMT_MOD ||
 			 log_statement == LOGSTMT_DDL) &&
 			(strncmp(commandTag, "CREATE ", strlen("CREATE ")) == 0 ||
+			 IsA(parsetree, SelectStmt) || /* SELECT INTO, CREATE AS */
 			 strncmp(commandTag, "ALTER ", strlen("ALTER ")) == 0 ||
 			 strncmp(commandTag, "DROP ", strlen("DROP ")) == 0 ||
 			 IsA(parsetree, GrantStmt) ||	/* GRANT or REVOKE */
-- 
GitLab