src/bin/pg_dump/pg_dump.c
static PQExpBuffer
createViewAsClause(Archive *fout, const TableInfo *tbinfo)
{
	PQExpBuffer query = createPQExpBuffer();
	PQExpBuffer result = createPQExpBuffer();
	PGresult   *res;
	int			len;

	/* Fetch the view definition */
	appendPQExpBuffer(query,
					  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
					  tbinfo->dobj.catId.oid);

	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);

	if (PQntuples(res) != 1)
	{
		if (PQntuples(res) < 1)
			fatal("query to obtain definition of view \"%s\" returned no data",
				  tbinfo->dobj.name);
		else
			fatal("query to obtain definition of view \"%s\" returned more than one definition",
				  tbinfo->dobj.name);
	}

	len = PQgetlength(res, 0, 0);

	if (len == 0)
		fatal("definition of view \"%s\" appears to be empty (length zero)",
			  tbinfo->dobj.name);

	/* Strip off the trailing semicolon so that other things may follow. */
	Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
	appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);

	PQclear(res);
	destroyPQExpBuffer(query);

	return result;
}
/*
 * Create the AS clause for a view or materialized view. The semicolon is
 * stripped because a materialized view must add a WITH NO DATA clause.
 *
 * This returns a new buffer which must be freed by the caller.
 */
Create the AS clause for a view or materialized view. The semicolon is
stripped because a materialized view must add a WITH NO DATA clause.

This returns a new buffer which must be freed by the caller.
Create the AS clause for a view or materialized view . The semicolon is stripped because a materialized view must add a WITH NO DATA clause . This returns a new buffer which must be freed by the caller .
static PQExpBuffer
createViewAsClause(Archive *fout, const TableInfo *tbinfo)
{
	PQExpBuffer query = createPQExpBuffer();
	PQExpBuffer result = createPQExpBuffer();
	PGresult   *res;
	int			len;
	appendPQExpBuffer(query,
					  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
					  tbinfo->dobj.catId.oid);
	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
	if (PQntuples(res) != 1)
	{
		if (PQntuples(res) < 1)
			fatal("query to obtain definition of view \"%s\" returned no data",
				  tbinfo->dobj.name);
		else
			fatal("query to obtain definition of view \"%s\" returned more than one definition",
				  tbinfo->dobj.name);
	}
	len = PQgetlength(res, 0, 0);
	if (len == 0)
		fatal("definition of view \"%s\" appears to be empty (length zero)",
			  tbinfo->dobj.name);
	Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
	appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
	PQclear(res);
	destroyPQExpBuffer(query);
	return result;
}
static PQExpBuffer createViewAsClause ( Archive * fout , const TableInfo * tbinfo ) { PQExpBuffer query = createPQExpBuffer ( ) ; PQExpBuffer result = createPQExpBuffer ( ) ; PGresult * res ; int len ; appendPQExpBuffer ( query , " " , tbinfo -> dobj . catId . oid ) ; res = ExecuteSqlQuery ( fout , query -> data , PGRES_TUPLES_OK ) ; if ( PQntuples ( res ) != 1 ) { if ( PQntuples ( res ) < 1 ) fatal ( " \" \" " , tbinfo -> dobj . name ) ; else fatal ( " \" \" " , tbinfo -> dobj . name ) ; } len = PQgetlength ( res , 0 , 0 ) ; if ( len == 0 ) fatal ( " \" \" " , tbinfo -> dobj . name ) ; Assert ( PQgetvalue ( res , 0 , 0 ) [ len - 1 ] == ' ' ) ; appendBinaryPQExpBuffer ( result , PQgetvalue ( res , 0 , 0 ) , len - 1 ) ; PQclear ( res ) ; destroyPQExpBuffer ( query ) ; return result ; }
Create the AS clause for a view or materialized view.
Create the AS clause for a view or materialized view .
/* Fetch the view definition */ /* Strip off the trailing semicolon so that other things may follow. */