/* prints for each segments, the index and the host ip */
static void print_segments_list()
{
	StringInfoData msg;
	CdbComponentDatabases *test_cdb = GpAliveSegmentsInfo.cdbComponentDatabases;
	initStringInfo(&msg);
	
	for (int i = 0; i < test_cdb->total_segment_dbs; ++i)
	{
		CdbComponentDatabaseInfo* component = &test_cdb->segment_db_info[i];
		appendStringInfo(&msg, "\nsegment -- index: %d, ip: %s", component->segindex, component->hostip);
	}
	
	elog(FRAGDEBUG, "%s", msg.data);
	pfree(msg.data);
}
示例#2
0
static void
setToSQL(StringInfo str, SetQuery *s)
{
    appendStringInfoString(str, "(");
    nodeToSQL(str, s->lChild);
    appendStringInfoString(str, ")");

    switch(s->setOp)
    {
        case SETOP_UNION:
            appendStringInfo(str, " UNION %s", s->all ? " ALL " : "");
        break;
        case SETOP_INTERSECTION:
            appendStringInfo(str, " INTERSECT %s", s->all ? " ALL " : "");
        break;
        case SETOP_DIFFERENCE:
            appendStringInfo(str, " MINUS %s", s->all ? " ALL " : "");
        break;
    }

    appendStringInfoString(str, "(");
    nodeToSQL(str, s->lChild);
    appendStringInfoString(str, ")");
}
示例#3
0
void
start_transaction(PlxConn *plx_conn)
{
    int        curlevel;
    StringInfo sql = NULL;

    if (!strcmp(plx_conn->plx_cluster->isolation_level, "auto commit"))
        return;

    curlevel = GetCurrentTransactionNestLevel();
    if (!is_remote_transaction)
    {
        RegisterXactCallback(xact_callback, NULL);
        RegisterSubXactCallback(subxact_callback, NULL);
        is_remote_transaction = true;
    }

    if (plx_conn->xlevel == 0)
    {
        sql = makeStringInfo();
        appendStringInfo(sql,
                         "start transaction isolation level %s;",
                         plx_conn->plx_cluster->isolation_level);
        plx_conn->xlevel = 1;
    }

    while (plx_conn->xlevel < curlevel)
    {
        if (!sql)
            sql = makeStringInfo();
        appendStringInfo(sql, "savepoint s%d; ", (int) ++(plx_conn->xlevel));
        is_remote_subtransaction = true;
    }
    if (sql)
        PQclear(PQexec(plx_conn->pq_conn, sql->data));
}
示例#4
0
/*
 * Show hook routine for "gp_connections_per_thread" option.
 *
 * See src/backend/util/misc/guc.c for option definition.
 */
const char *
show_gp_connections_per_thread(void)
{
	/*
	 * We rely on the fact that the memory context will clean up the memory
	 * for the buffer.data.
	 */
	StringInfoData buffer;

	initStringInfo(&buffer);

	appendStringInfo(&buffer, "%d", gp_connections_per_thread);

	return buffer.data;
}
示例#5
0
/*
 * pg_dependencies		- output routine for type pg_dependencies.
 */
Datum
pg_dependencies_out(PG_FUNCTION_ARGS)
{
	bytea	   *data = PG_GETARG_BYTEA_PP(0);
	MVDependencies *dependencies = statext_dependencies_deserialize(data);
	int			i,
				j;
	StringInfoData str;

	initStringInfo(&str);
	appendStringInfoChar(&str, '{');

	for (i = 0; i < dependencies->ndeps; i++)
	{
		MVDependency *dependency = dependencies->deps[i];

		if (i > 0)
			appendStringInfoString(&str, ", ");

		appendStringInfoChar(&str, '"');
		for (j = 0; j < dependency->nattributes; j++)
		{
			if (j == dependency->nattributes - 1)
				appendStringInfoString(&str, " => ");
			else if (j > 0)
				appendStringInfoString(&str, ", ");

			appendStringInfo(&str, "%d", dependency->attributes[j]);
		}
		appendStringInfo(&str, "\": %f", dependency->degree);
	}

	appendStringInfoChar(&str, '}');

	PG_RETURN_CSTRING(str.data);
}
示例#6
0
/*
 * Returns the remote ip and port of the curl response.
 * If it's not available, returns an empty string.
 * The returned value should be free'd.
 */
char* get_dest_address(CURL* curl_handle) {
	char	*dest_ip = NULL;
	long	 dest_port = 0;
	StringInfoData addr;
	initStringInfo(&addr);

	/* add dest ip and port, if any, and curl was nice to tell us */
	if (CURLE_OK == curl_easy_getinfo(curl_handle, CURLINFO_PRIMARY_IP, &dest_ip) &&
		CURLE_OK == curl_easy_getinfo(curl_handle, CURLINFO_PRIMARY_PORT, &dest_port) &&
		dest_ip && dest_port)
	{
		appendStringInfo(&addr, "'%s:%ld'", dest_ip, dest_port);
	}
	return addr.data;
}
示例#7
0
void
smgr_desc(StringInfo buf, uint8 xl_info, char *rec)
{
	uint8		info = xl_info & ~XLR_INFO_MASK;

	if (info == XLOG_SMGR_CREATE)
	{
		xl_smgr_create *xlrec = (xl_smgr_create *) rec;

		appendStringInfo(buf, "file create: %u/%u/%u",
						 xlrec->rnode.spcNode, xlrec->rnode.dbNode,
						 xlrec->rnode.relNode);
	}
	else if (info == XLOG_SMGR_TRUNCATE)
	{
		xl_smgr_truncate *xlrec = (xl_smgr_truncate *) rec;

		appendStringInfo(buf, "file truncate: %u/%u/%u to %u blocks",
						 xlrec->rnode.spcNode, xlrec->rnode.dbNode,
						 xlrec->rnode.relNode, xlrec->blkno);
	}
	else
		appendStringInfo(buf, "UNKNOWN");
}
示例#8
0
void
ReaderDumpParams(Reader *self)
{
	char		   *str;
	StringInfoData	buf;

	initStringInfo(&buf);

	str = QuoteString(self->infile);
	appendStringInfo(&buf, "INPUT = %s\n", str);
	pfree(str);

	str = QuoteString(self->parse_badfile);
	appendStringInfo(&buf, "PARSE_BADFILE = %s\n", str);
	pfree(str);

	str = QuoteString(self->logfile);
	appendStringInfo(&buf, "LOGFILE = %s\n", str);
	pfree(str);

	if (self->limit == INT64_MAX)
		appendStringInfo(&buf, "LIMIT = INFINITE\n");
	else
		appendStringInfo(&buf, "LIMIT = " int64_FMT "\n", self->limit);

	if (self->max_parse_errors == INT64_MAX)
		appendStringInfo(&buf, "PARSE_ERRORS = INFINITE\n");
	else
		appendStringInfo(&buf, "PARSE_ERRORS = " int64_FMT "\n",
						 self->max_parse_errors);
	if (PG_VALID_FE_ENCODING(self->checker.encoding))
		appendStringInfo(&buf, "ENCODING = %s\n",
						 pg_encoding_to_char(self->checker.encoding));
	appendStringInfo(&buf, "CHECK_CONSTRAINTS = %s\n",
		self->checker.check_constraints ? "YES" : "NO");

	LoggerLog(INFO, buf.data);
	pfree(buf.data);

	ParserDumpParams(self->parser);
}
示例#9
0
文件: reorg.c 项目: reorg/pg_reorg
/**
 * @fn      Datum reorg_indexdef(PG_FUNCTION_ARGS)
 * @brief   Reproduce DDL that create index at the temp table.
 *
 * reorg_indexdef(index, table)
 *
 * @param	index	Oid of target index.
 * @param	table	Oid of table of the index.
 * @retval			Create index DDL for temp table.
 */
Datum
reorg_indexdef(PG_FUNCTION_ARGS)
{
	Oid				index = PG_GETARG_OID(0);
	Oid				table = PG_GETARG_OID(1);
	IndexDef		stmt;
	StringInfoData	str;

	parse_indexdef(&stmt, index, table);
	initStringInfo(&str);
	appendStringInfo(&str, "%s index_%u ON reorg.table_%u USING %s (%s)%s",
		stmt.create, index, table, stmt.type, stmt.columns, stmt.options);

	PG_RETURN_TEXT_P(cstring_to_text(str.data));
}
示例#10
0
文件: funcs.cpp 项目: b-xiang/gpdb
Datum
RestoreQueryDXL(PG_FUNCTION_ARGS)
{
	char *szXmlString = textToString(PG_GETARG_TEXT_P(0));

	int iProcessed = executeXMLQuery(szXmlString);

	StringInfoData str;
	initStringInfo(&str);
	appendStringInfo(&str, "processed %d rows", iProcessed);

	text *ptResult = stringToText(str.data);

	PG_RETURN_TEXT_P(ptResult);
}
示例#11
0
/* Print range list in debug purposes */
static char *
print_irange(List *l)
{
	ListCell   *c;
	StringInfoData str;

	initStringInfo(&str);

	foreach (c, l)
	{
		IndexRange ir = lfirst_irange(c);

		appendStringInfo(&str, "[%d,%d]%c ", irange_lower(ir), irange_upper(ir),
			irange_is_lossy(ir) ? 'l' : 'e');
	}
示例#12
0
Datum
caql_bootstrap_regproc(PG_FUNCTION_ARGS)
{
	char	   *cstr_regprocin = "boolin";
	char	   *cstr_regoperin = "#>="; /* we should pick up a unique name */
	char	   *cstr_regclassin = "pg_class";
	char	   *cstr_regtypein = "bool";
	Datum		result;
	StringInfoData	buf;

	initStringInfo(&buf);

	SetProcessingMode(BootstrapProcessing);
	/* regproc */
	result = DirectFunctionCall1(regprocin, CStringGetDatum(cstr_regprocin));
	appendStringInfo(&buf, "regprocin(%s) = %d\n",
			cstr_regprocin, DatumGetObjectId(result));

	/* regoper */
	result = DirectFunctionCall1(regoperin, CStringGetDatum(cstr_regoperin));
	appendStringInfo(&buf, "regoperin(%s) = %d\n",
			cstr_regoperin, DatumGetObjectId(result));

	/* regclass */
	result = DirectFunctionCall1(regclassin, CStringGetDatum(cstr_regclassin));
	appendStringInfo(&buf, "regclassin(%s) = %d\n",
			cstr_regclassin, DatumGetObjectId(result));

	/* regtype */
	result = DirectFunctionCall1(regtypein, CStringGetDatum(cstr_regtypein));
	appendStringInfo(&buf, "regtypein(%s) = %d\n",
			cstr_regtypein, DatumGetObjectId(result));
	SetProcessingMode(NormalProcessing);

	PG_RETURN_TEXT_P(cstring_to_text(buf.data));
}
/*
 * CStoreEndWrite finishes a cstore data load operation. If we have an unflushed
 * stripe, we flush it. Then, we sync and close the cstore data file. Last, we
 * flush the footer to a temporary file, and atomically rename this temporary
 * file to the original footer file.
 */
void
CStoreEndWrite(TableWriteState *writeState)
{
	StringInfo tableFooterFilename = NULL;
	StringInfo tempTableFooterFileName = NULL;
	int renameResult = 0;

	StripeData *stripeData = writeState->stripeData;
	if (stripeData != NULL)
	{
		MemoryContext oldContext = MemoryContextSwitchTo(writeState->stripeWriteContext);

		StripeMetadata stripeMetadata = FlushStripe(writeState);
		MemoryContextReset(writeState->stripeWriteContext);

		MemoryContextSwitchTo(oldContext);
		AppendStripeMetadata(writeState->tableFooter, stripeMetadata);
	}

	SyncAndCloseFile(writeState->tableFile);

	tableFooterFilename = writeState->tableFooterFilename;
	tempTableFooterFileName = makeStringInfo();
	appendStringInfo(tempTableFooterFileName, "%s%s", tableFooterFilename->data,
					 CSTORE_TEMP_FILE_SUFFIX);

	CStoreWriteFooter(tempTableFooterFileName, writeState->tableFooter);

	renameResult = rename(tempTableFooterFileName->data, tableFooterFilename->data);
	if (renameResult != 0)
	{
		ereport(ERROR, (errcode_for_file_access(),
						errmsg("could not rename file \"%s\" to \"%s\": %m",
							   tempTableFooterFileName->data,
							   tableFooterFilename->data)));
	}

	pfree(tempTableFooterFileName->data);
	pfree(tempTableFooterFileName);

	MemoryContextDelete(writeState->stripeWriteContext);
	list_free_deep(writeState->tableFooter->stripeMetadataList);
	pfree(writeState->tableFooter);
	pfree(writeState->tableFooterFilename->data);
	pfree(writeState->tableFooterFilename);
	pfree(writeState->comparisonFunctionArray);
	pfree(writeState);
}
示例#14
0
static void print_literal(StringInfo s, Oid typid, char* outputstr) {
  const char* valptr;

  switch (typid) {
    case INT2OID:
    case INT4OID:
    case INT8OID:
    case OIDOID:
    case FLOAT4OID:
    case FLOAT8OID:
    case NUMERICOID:
      appendStringInfoString(s, outputstr);
      break;

    case BITOID:
    case VARBITOID:
      appendStringInfo(s, "\"B'%s'\"", outputstr);
      break;

    case BOOLOID:
      if (strcmp(outputstr, "t") == 0)
        appendStringInfoString(s, "true");
      else
        appendStringInfoString(s, "false");
      break;

    default:
      appendStringInfoChar(s, '"');
      for (valptr = outputstr; *valptr; valptr++) {
        char ch = *valptr;
        if (ch == '\n') {
          appendStringInfoString(s, "\\n");
        } else if (ch == '\r') {
          appendStringInfoString(s, "\\r");
        } else if (ch == '\t') {
          appendStringInfoString(s, "\\t");
        } else if (ch == '"') {
          appendStringInfoString(s, "\\\"");
        } else if (ch == '\\') {
          appendStringInfoString(s, "\\\\");
        } else {
          appendStringInfoChar(s, ch);
        }
      }
      appendStringInfoChar(s, '"');
      break;
  }
}
示例#15
0
文件: genam.c 项目: EMARQUIS/postgres
/*
 * BuildIndexValueDescription
 *
 * Construct a string describing the contents of an index entry, in the
 * form "(key_name, ...)=(key_value, ...)".  This is currently used
 * for building unique-constraint and exclusion-constraint error messages.
 *
 * The passed-in values/nulls arrays are the "raw" input to the index AM,
 * e.g. results of FormIndexDatum --- this is not necessarily what is stored
 * in the index, but it's what the user perceives to be stored.
 */
char *
BuildIndexValueDescription(Relation indexRelation,
						   Datum *values, bool *isnull)
{
	StringInfoData buf;
	int			natts = indexRelation->rd_rel->relnatts;
	int			i;

	initStringInfo(&buf);
	appendStringInfo(&buf, "(%s)=(",
					 pg_get_indexdef_columns(RelationGetRelid(indexRelation),
											 true));

	for (i = 0; i < natts; i++)
	{
		char	   *val;

		if (isnull[i])
			val = "null";
		else
		{
			Oid			foutoid;
			bool		typisvarlena;

			/*
			 * The provided data is not necessarily of the type stored in the
			 * index; rather it is of the index opclass's input type. So look
			 * at rd_opcintype not the index tupdesc.
			 *
			 * Note: this is a bit shaky for opclasses that have pseudotype
			 * input types such as ANYARRAY or RECORD.	Currently, the
			 * typoutput functions associated with the pseudotypes will work
			 * okay, but we might have to try harder in future.
			 */
			getTypeOutputInfo(indexRelation->rd_opcintype[i],
							  &foutoid, &typisvarlena);
			val = OidOutputFunctionCall(foutoid, values[i]);
		}

		if (i > 0)
			appendStringInfoString(&buf, ", ");
		appendStringInfoString(&buf, val);
	}

	appendStringInfoChar(&buf, ')');

	return buf.data;
}
示例#16
0
/*
 * Decode a DELETE entry
 */
static void
decoder_raw_delete(StringInfo s,
				   Relation relation,
				   HeapTuple tuple)
{
	appendStringInfo(s, "DELETE FROM ");
	print_relname(s, relation);

	/*
	 * Here the same tuple is used as old and new values, selectivity will
	 * be properly reduced by relation uses DEFAULT or INDEX as REPLICA
	 * IDENTITY.
	 */
	print_where_clause(s, relation, tuple, tuple);
	appendStringInfoString(s, ";");
}
示例#17
0
void
relmap_desc(StringInfo buf, XLogRecord *record)
{
	char	   *rec = XLogRecGetData(record);
	uint8		info = record->xl_info & ~XLR_INFO_MASK;

	if (info == XLOG_RELMAP_UPDATE)
	{
		xl_relmap_update *xlrec = (xl_relmap_update *) rec;

		appendStringInfo(buf, "update relmap: database %u tablespace %u size %u",
						 xlrec->dbid, xlrec->tsid, xlrec->nbytes);
	}
	else
		appendStringInfoString(buf, "UNKNOWN");
}
示例#18
0
Datum
cmsketch_print(PG_FUNCTION_ARGS)
{
	StringInfoData buf;
	CountMinSketch *cms;

	if (PG_ARGISNULL(0))
		PG_RETURN_NULL();

	cms = (CountMinSketch *) PG_GETARG_VARLENA_P(0);

	initStringInfo(&buf);
	appendStringInfo(&buf, "{ d = %d, w = %d, count = %ld, size = %ldkB }", cms->d, cms->w, cms->count, CountMinSketchSize(cms) / 1024);

	PG_RETURN_TEXT_P(CStringGetTextDatum(buf.data));
}
示例#19
0
char* replication_stats(void) {
  char* result;
	StringInfoData query;
  
  initStringInfo(&query);
  appendStringInfo(&query, 
    "SELECT usename, application_name, client_addr, client_hostname, client_port, "
    "   backend_start, state, sent_location, write_location, flush_location, "
    "   replay_location, sync_priority, sync_state, pg_current_xlog_location(), now()::text as measured_at "
    " FROM pg_stat_replication"
  );
  
  result = exec_to_command("RPSTAT", query.data);
  
  return result;
}
示例#20
0
文件: convert.c 项目: 50wu/gpdb
Datum
orafce_to_char_float8(PG_FUNCTION_ARGS)
{
	float8		arg0 = PG_GETARG_FLOAT8(0);
	StringInfo	buf = makeStringInfo();
	struct lconv *lconv = PGLC_localeconv();
	char	   *p;

	appendStringInfo(buf, "%f", arg0);

	for (p = buf->data; *p; p++)
		if (*p == '.')
			*p = lconv->decimal_point[0];

	PG_RETURN_TEXT_P(cstring_to_text(buf->data));
}
示例#21
0
Datum
bloom_print(PG_FUNCTION_ARGS)
{
	StringInfoData buf;
	BloomFilter *bloom;

	if (PG_ARGISNULL(0))
		PG_RETURN_NULL();

	bloom = (BloomFilter *) PG_GETARG_VARLENA_P(0);

	initStringInfo(&buf);
	appendStringInfo(&buf, "{ k = %d, m = %d, fill = %f, card = %ld, size = %ldkB }", bloom->k, bloom->m, BloomFilterFillRatio(bloom), BloomFilterCardinality(bloom), BloomFilterSize(bloom) / 1024);

	PG_RETURN_TEXT_P(CStringGetTextDatum(buf.data));
}
示例#22
0
/*
 * sort_names accepts three strings, places them in a list, then calls SortList
 * to test its sort functionality. Returns a string containing sorted lines.
 */
Datum
sort_names(PG_FUNCTION_ARGS)
{
	char *first = PG_GETARG_CSTRING(0);
	char *second = PG_GETARG_CSTRING(1);
	char *third = PG_GETARG_CSTRING(2);
	List *nameList = SortList(list_make3(first, second, third),
							  (int (*)(const void *, const void *))(&CompareStrings));
	StringInfo sortedNames = makeStringInfo();

	ListCell *nameCell = NULL;
	foreach(nameCell, nameList)
	{
		char *name = lfirst(nameCell);
		appendStringInfo(sortedNames, "%s\n", name);
	}
示例#23
0
Datum
fss_print(PG_FUNCTION_ARGS)
{
	StringInfoData buf;
	FSS *fss;

	if (PG_ARGISNULL(0))
		PG_RETURN_NULL();

	fss = fss_fix_ptrs(PG_GETARG_VARLENA_P(0));

	initStringInfo(&buf);
	appendStringInfo(&buf, "{ m = %d, h = %d, count = %ld, size = %ldkB }", fss->m, fss->h, fss->count, FSSSize(fss) / 1024);

	PG_RETURN_TEXT_P(CStringGetTextDatum(buf.data));
}
示例#24
0
/*
 * worker_copy_shard_placement implements a internal UDF to copy a table's data from
 * a healthy placement into a receiving table on an unhealthy placement. This
 * function returns a boolean reflecting success or failure.
 */
Datum
worker_copy_shard_placement(PG_FUNCTION_ARGS)
{
    text *shardRelationNameText = PG_GETARG_TEXT_P(0);
    text *nodeNameText = PG_GETARG_TEXT_P(1);
    int32 nodePort = PG_GETARG_INT32(2);
    char *shardRelationName = text_to_cstring(shardRelationNameText);
    char *nodeName = text_to_cstring(nodeNameText);
    bool fetchSuccessful = false;

    Oid shardRelationId = ResolveRelationId(shardRelationNameText);
    Relation shardTable = heap_open(shardRelationId, RowExclusiveLock);
    TupleDesc tupleDescriptor = RelationGetDescr(shardTable);
    Tuplestorestate *tupleStore = tuplestore_begin_heap(false, false, work_mem);

    StringInfo selectAllQuery = NULL;
    ShardPlacement *placement = NULL;
    Task *task = NULL;

    selectAllQuery = makeStringInfo();
    appendStringInfo(selectAllQuery, SELECT_ALL_QUERY,
                     quote_identifier(shardRelationName));

    placement = (ShardPlacement *) palloc0(sizeof(ShardPlacement));
    placement->nodeName = nodeName;
    placement->nodePort = nodePort;

    task = (Task *) palloc0(sizeof(Task));
    task->queryString = selectAllQuery;
    task->taskPlacementList = list_make1(placement);

    fetchSuccessful = ExecuteTaskAndStoreResults(task, tupleDescriptor, tupleStore);
    if (!fetchSuccessful)
    {
        ereport(ERROR, (errmsg("could not store shard rows from healthy placement"),
                        errhint("Consult recent messages in the server logs for "
                                "details.")));
    }

    CopyDataFromTupleStoreToRelation(tupleStore, shardTable);

    tuplestore_end(tupleStore);

    heap_close(shardTable, RowExclusiveLock);

    PG_RETURN_VOID();
}
示例#25
0
void
seq_desc(StringInfo buf, uint8 xl_info, char *rec)
{
	uint8		info = xl_info & ~XLR_INFO_MASK;
	xl_seq_rec *xlrec = (xl_seq_rec *) rec;

	if (info == XLOG_SEQ_LOG)
		appendStringInfoString(buf, "log: ");
	else
	{
		appendStringInfoString(buf, "UNKNOWN");
		return;
	}

	appendStringInfo(buf, "rel %u/%u/%u",
			   xlrec->node.spcNode, xlrec->node.dbNode, xlrec->node.relNode);
}
示例#26
0
文件: acl_oid.c 项目: mlt/acl
static void
format_who(StringInfo out, intptr_t opaque)
{
	HeapTuple		htup;
	AclEntryOid	   *entry = (AclEntryOid *) opaque;

	if (entry->who == PUBLIC_OID)
		return;

	htup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(entry->who));
	if (!HeapTupleIsValid(htup))
	{
		appendStringInfo(out, "#%d", entry->who);
	}
	else
	{
		char   *name = NameStr(((Form_pg_authid) GETSTRUCT(htup))->rolname);
		char   *s;
		bool	safe = true;

		for (s = name; *s; ++s)
		{
			if (!isalnum((unsigned char) *s) && *s != '_')
			{
				safe = false;
				break;
			}
		}

		if (!safe)
			appendStringInfoChar(out, '"');

		for (s = name; *s; ++s)
		{
			if (*s == '"')
				appendStringInfoChar(out, '"');

			appendStringInfoChar(out, *s);
		}

		if (!safe)
			appendStringInfoChar(out, '"');

		ReleaseSysCache(htup);
	}
}
示例#27
0
/*
 * Build a header string, in the form of given format (e.g. "%s: %s"),
 * and populate <key> and <value> in it.
 * If value is empty, return <key>.
 */
char* build_header_str(const char* format,
					   const char* key,
					   const char* value)
{
	char* header_option = NULL;

	if (value == NULL)  /* the option is just a "key" */
		header_option = pstrdup(key);
	else /* the option is a "key: value" */
	{
		StringInfoData formatter;
		initStringInfo(&formatter);
		appendStringInfo(&formatter, format, key, value);
		header_option = formatter.data;
	}
	return header_option;
}
示例#28
0
文件: jsontriga.c 项目: pgq/pgq
static void timestamp_to_json(Datum val, StringInfo dst)
{
	char buf[MAXDATELEN + 1];
	struct pg_tm tm;
	fsec_t fsec;
	Timestamp timestamp = DatumGetTimestamp(val);

	if (TIMESTAMP_NOT_FINITE(timestamp))
		EncodeSpecialTimestamp(timestamp, buf);
	else if (timestamp2tm(timestamp, NULL, &tm, &fsec, NULL, NULL) == 0)
		EncodeDateTime(&tm, fsec, false, 0, NULL, USE_XSD_DATES, buf);
	else
		ereport(ERROR,
			(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
			 errmsg("timestamp out of range")));
	appendStringInfo(dst, "\"%s\"", buf);
}
示例#29
0
char* index_info(void) {
  char* result;
	StringInfoData query;
  
  initStringInfo(&query);
  appendStringInfo(&query, 
    "SELECT '%s', indexrelid, indrelid, indnatts, indkey, indisunique"
    " FROM pg_index "
    "   INNER JOIN pg_class ON pg_class.oid = pg_index.indexrelid "
    "   INNER JOIN pg_namespace on pg_namespace.oid = pg_class.relnamespace" 
    " WHERE nspname not in ('pg_toast', 'information_schema', 'pg_catalog')  ", target_db
  );
  
  result = exec_to_command("INDNFO", query.data);
  
  return result;
}
示例#30
0
文件: brindesc.c 项目: Brar/postgres
void
brin_desc(StringInfo buf, XLogReaderState *record)
{
	char	   *rec = XLogRecGetData(record);
	uint8		info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;

	info &= XLOG_BRIN_OPMASK;
	if (info == XLOG_BRIN_CREATE_INDEX)
	{
		xl_brin_createidx *xlrec = (xl_brin_createidx *) rec;

		appendStringInfo(buf, "v%d pagesPerRange %u",
						 xlrec->version, xlrec->pagesPerRange);
	}
	else if (info == XLOG_BRIN_INSERT)
	{
		xl_brin_insert *xlrec = (xl_brin_insert *) rec;

		appendStringInfo(buf, "heapBlk %u pagesPerRange %u offnum %u",
						 xlrec->heapBlk,
						 xlrec->pagesPerRange,
						 xlrec->offnum);
	}
	else if (info == XLOG_BRIN_UPDATE)
	{
		xl_brin_update *xlrec = (xl_brin_update *) rec;

		appendStringInfo(buf, "heapBlk %u pagesPerRange %u old offnum %u, new offnum %u",
						 xlrec->insert.heapBlk,
						 xlrec->insert.pagesPerRange,
						 xlrec->oldOffnum,
						 xlrec->insert.offnum);
	}
	else if (info == XLOG_BRIN_SAMEPAGE_UPDATE)
	{
		xl_brin_samepage_update *xlrec = (xl_brin_samepage_update *) rec;

		appendStringInfo(buf, "offnum %u", xlrec->offnum);
	}
	else if (info == XLOG_BRIN_REVMAP_EXTEND)
	{
		xl_brin_revmap_extend *xlrec = (xl_brin_revmap_extend *) rec;

		appendStringInfo(buf, "targetBlk %u", xlrec->targetBlk);
	}
	else if (info == XLOG_BRIN_DESUMMARIZE)
	{
		xl_brin_desummarize *xlrec = (xl_brin_desummarize *) rec;

		appendStringInfo(buf, "pagesPerRange %u, heapBlk %u, page offset %u",
						 xlrec->pagesPerRange, xlrec->heapBlk, xlrec->regOffset);
	}
}