MCPcopy Create free account
hub / github.com/apache/cloudberry / createViewAsClause

Function createViewAsClause

src/bin/pg_dump/pg_dump.c:17632–17671  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

17630 * This returns a new buffer which must be freed by the caller.
17631 */
17632static PQExpBuffer
17633createViewAsClause(Archive *fout, const TableInfo *tbinfo)
17634{
17635 PQExpBuffer query = createPQExpBuffer();
17636 PQExpBuffer result = createPQExpBuffer();
17637 PGresult *res;
17638 int len;
17639
17640 /* Fetch the view definition */
17641 appendPQExpBuffer(query,
17642 "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
17643 tbinfo->dobj.catId.oid);
17644
17645 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
17646
17647 if (PQntuples(res) != 1)
17648 {
17649 if (PQntuples(res) < 1)
17650 fatal("query to obtain definition of view \"%s\" returned no data",
17651 tbinfo->dobj.name);
17652 else
17653 fatal("query to obtain definition of view \"%s\" returned more than one definition",
17654 tbinfo->dobj.name);
17655 }
17656
17657 len = PQgetlength(res, 0, 0);
17658
17659 if (len == 0)
17660 fatal("definition of view \"%s\" appears to be empty (length zero)",
17661 tbinfo->dobj.name);
17662
17663 /* Strip off the trailing semicolon so that other things may follow. */
17664 Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
17665 appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
17666
17667 PQclear(res);
17668 destroyPQExpBuffer(query);
17669
17670 return result;
17671}
17672
17673/*
17674 * Create a dummy AS clause for a view. This is used when the real view

Callers 2

dumpTableSchemaFunction · 0.85
dumpRuleFunction · 0.85

Calls 9

createPQExpBufferFunction · 0.85
appendPQExpBufferFunction · 0.85
ExecuteSqlQueryFunction · 0.85
PQntuplesFunction · 0.85
PQgetlengthFunction · 0.85
PQgetvalueFunction · 0.85
appendBinaryPQExpBufferFunction · 0.85
PQclearFunction · 0.85
destroyPQExpBufferFunction · 0.85

Tested by

no test coverage detected