src/bin/pg_dump/pg_dump.c
static void
expand_table_name_patterns(Archive *fout,
						   SimpleStringList *patterns, SimpleOidList *oids,
						   bool strict_names)
{
	PQExpBuffer query;
	PGresult   *res;
	SimpleStringListCell *cell;
	int			i;

	if (patterns->head == NULL)
		return;					/* nothing to do */

	query = createPQExpBuffer();

	/*
	 * this might sometimes result in duplicate entries in the OID list, but
	 * we don't care.
	 */

	for (cell = patterns->head; cell; cell = cell->next)
	{
		/*
		 * Query must remain ABSOLUTELY devoid of unqualified names.  This
		 * would be unnecessary given a pg_table_is_visible() variant taking a
		 * search_path argument.
		 */
		appendPQExpBuffer(query,
						  "SELECT c.oid"
						  "\nFROM pg_catalog.pg_class c"
						  "\n     LEFT JOIN pg_catalog.pg_namespace n"
						  "\n     ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
						  "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
						  "\n    (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
						  RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
						  RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
						  RELKIND_PARTITIONED_TABLE);
		processSQLNamePattern(GetConnection(fout), query, cell->val, true,
							  false, "n.nspname", "c.relname", NULL,
							  "pg_catalog.pg_table_is_visible(c.oid)");

		ExecuteSqlStatement(fout, "RESET search_path");
		res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
		PQclear(ExecuteSqlQueryForSingleRow(fout,
											ALWAYS_SECURE_SEARCH_PATH_SQL));
		if (strict_names && PQntuples(res) == 0)
			fatal("no matching tables were found for pattern \"%s\"", cell->val);

		for (i = 0; i < PQntuples(res); i++)
		{
			simple_oid_list_append(oids, atooid(PQgetvalue(res, i, 0)));
		}

		PQclear(res);
		resetPQExpBuffer(query);
	}

	destroyPQExpBuffer(query);
}
/*
 * Find the OIDs of all tables matching the given list of patterns,
 * and append them to the given OID list. See also expand_dbname_patterns()
 * in pg_dumpall.c
 */
Find the OIDs of all tables matching the given list of patterns,
and append them to the given OID list.
Find the OIDs of all tables matching the given list of patterns and append them to the given OID list .
static void
expand_table_name_patterns(Archive *fout,
						   SimpleStringList *patterns, SimpleOidList *oids,
						   bool strict_names)
{
	PQExpBuffer query;
	PGresult   *res;
	SimpleStringListCell *cell;
	int			i;
	if (patterns->head == NULL)
		return;					
	query = createPQExpBuffer();
	for (cell = patterns->head; cell; cell = cell->next)
	{
		appendPQExpBuffer(query,
						  "SELECT c.oid"
						  "\nFROM pg_catalog.pg_class c"
						  "\n     LEFT JOIN pg_catalog.pg_namespace n"
						  "\n     ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
						  "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
						  "\n    (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
						  RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
						  RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
						  RELKIND_PARTITIONED_TABLE);
		processSQLNamePattern(GetConnection(fout), query, cell->val, true,
							  false, "n.nspname", "c.relname", NULL,
							  "pg_catalog.pg_table_is_visible(c.oid)");
		ExecuteSqlStatement(fout, "RESET search_path");
		res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
		PQclear(ExecuteSqlQueryForSingleRow(fout,
											ALWAYS_SECURE_SEARCH_PATH_SQL));
		if (strict_names && PQntuples(res) == 0)
			fatal("no matching tables were found for pattern \"%s\"", cell->val);
		for (i = 0; i < PQntuples(res); i++)
		{
			simple_oid_list_append(oids, atooid(PQgetvalue(res, i, 0)));
		}
		PQclear(res);
		resetPQExpBuffer(query);
	}
	destroyPQExpBuffer(query);
}
static void expand_table_name_patterns ( Archive * fout , SimpleStringList * patterns , SimpleOidList * oids , bool strict_names ) { PQExpBuffer query ; PGresult * res ; SimpleStringListCell * cell ; int i ; if ( patterns -> head == NULL ) return ; query = createPQExpBuffer ( ) ; for ( cell = patterns -> head ; cell ; cell = cell -> next ) { appendPQExpBuffer ( query , " " " \n " " \n " " \n " " \n " " \n \n " , RELKIND_RELATION , RELKIND_SEQUENCE , RELKIND_VIEW , RELKIND_MATVIEW , RELKIND_FOREIGN_TABLE , RELKIND_PARTITIONED_TABLE ) ; processSQLNamePattern ( GetConnection ( fout ) , query , cell -> val , true , false , " " , " " , NULL , " " ) ; ExecuteSqlStatement ( fout , " " ) ; res = ExecuteSqlQuery ( fout , query -> data , PGRES_TUPLES_OK ) ; PQclear ( ExecuteSqlQueryForSingleRow ( fout , ALWAYS_SECURE_SEARCH_PATH_SQL ) ) ; if ( strict_names && PQntuples ( res ) == 0 ) fatal ( " \" \" " , cell -> val ) ; for ( i = 0 ; i < PQntuples ( res ) ; i ++ ) { simple_oid_list_append ( oids , atooid ( PQgetvalue ( res , i , 0 ) ) ) ; } PQclear ( res ) ; resetPQExpBuffer ( query ) ; } destroyPQExpBuffer ( query ) ; }
Find the OIDs of all tables matching the given list of patterns,
 and append them to the given OID list.
Find the OIDs of all tables matching the given list of patterns and append them to the given OID list .
/* nothing to do */ /*
	 * this might sometimes result in duplicate entries in the OID list, but
	 * we don't care.
	 */ /*
		 * Query must remain ABSOLUTELY devoid of unqualified names.  This
		 * would be unnecessary given a pg_table_is_visible() variant taking a
		 * search_path argument.
		 */