2013-02-21 18:26:23 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* postgres_fdw.h
|
|
|
|
* Foreign-data wrapper for remote PostgreSQL servers
|
|
|
|
*
|
2015-01-07 00:43:47 +08:00
|
|
|
* Portions Copyright (c) 2012-2015, PostgreSQL Global Development Group
|
2013-02-21 18:26:23 +08:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* contrib/postgres_fdw/postgres_fdw.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef POSTGRES_FDW_H
|
|
|
|
#define POSTGRES_FDW_H
|
|
|
|
|
|
|
|
#include "foreign/foreign.h"
|
|
|
|
#include "lib/stringinfo.h"
|
|
|
|
#include "nodes/relation.h"
|
2014-11-15 08:48:53 +08:00
|
|
|
#include "utils/relcache.h"
|
2013-02-21 18:26:23 +08:00
|
|
|
|
|
|
|
#include "libpq-fe.h"
|
|
|
|
|
2013-03-12 09:31:28 +08:00
|
|
|
/* in postgres_fdw.c */
|
|
|
|
extern int set_transmission_modes(void);
|
|
|
|
extern void reset_transmission_modes(int nestlevel);
|
|
|
|
|
2013-02-21 18:26:23 +08:00
|
|
|
/* in connection.c */
|
2013-03-11 02:14:53 +08:00
|
|
|
extern PGconn *GetConnection(ForeignServer *server, UserMapping *user,
|
|
|
|
bool will_prep_stmt);
|
2013-02-21 18:26:23 +08:00
|
|
|
extern void ReleaseConnection(PGconn *conn);
|
|
|
|
extern unsigned int GetCursorNumber(PGconn *conn);
|
2013-03-11 02:14:53 +08:00
|
|
|
extern unsigned int GetPrepStmtNumber(PGconn *conn);
|
2014-02-04 10:30:02 +08:00
|
|
|
extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
|
|
|
|
bool clear, const char *sql);
|
2013-02-21 18:26:23 +08:00
|
|
|
|
|
|
|
/* in option.c */
|
|
|
|
extern int ExtractConnectionOptions(List *defelems,
|
|
|
|
const char **keywords,
|
|
|
|
const char **values);
|
|
|
|
|
|
|
|
/* in deparse.c */
|
|
|
|
extern void classifyConditions(PlannerInfo *root,
|
|
|
|
RelOptInfo *baserel,
|
2014-03-08 05:35:58 +08:00
|
|
|
List *input_conds,
|
2013-02-21 18:26:23 +08:00
|
|
|
List **remote_conds,
|
2013-03-22 07:43:59 +08:00
|
|
|
List **local_conds);
|
|
|
|
extern bool is_foreign_expr(PlannerInfo *root,
|
|
|
|
RelOptInfo *baserel,
|
|
|
|
Expr *expr);
|
2013-03-11 02:14:53 +08:00
|
|
|
extern void deparseSelectSql(StringInfo buf,
|
2013-02-21 18:26:23 +08:00
|
|
|
PlannerInfo *root,
|
|
|
|
RelOptInfo *baserel,
|
2013-03-22 12:31:11 +08:00
|
|
|
Bitmapset *attrs_used,
|
|
|
|
List **retrieved_attrs);
|
2013-02-21 18:26:23 +08:00
|
|
|
extern void appendWhereClause(StringInfo buf,
|
2013-03-11 02:14:53 +08:00
|
|
|
PlannerInfo *root,
|
2013-03-22 07:43:59 +08:00
|
|
|
RelOptInfo *baserel,
|
2013-02-21 18:26:23 +08:00
|
|
|
List *exprs,
|
2013-03-22 07:43:59 +08:00
|
|
|
bool is_first,
|
|
|
|
List **params);
|
2013-03-13 06:58:13 +08:00
|
|
|
extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
|
|
|
|
Index rtindex, Relation rel,
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 11:31:36 +08:00
|
|
|
List *targetAttrs, bool doNothing, List *returningList,
|
2013-03-22 12:31:11 +08:00
|
|
|
List **retrieved_attrs);
|
2013-03-13 06:58:13 +08:00
|
|
|
extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
|
|
|
|
Index rtindex, Relation rel,
|
2013-03-22 12:31:11 +08:00
|
|
|
List *targetAttrs, List *returningList,
|
|
|
|
List **retrieved_attrs);
|
2013-03-13 06:58:13 +08:00
|
|
|
extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
|
|
|
|
Index rtindex, Relation rel,
|
2013-03-22 12:31:11 +08:00
|
|
|
List *returningList,
|
|
|
|
List **retrieved_attrs);
|
2013-02-22 23:56:06 +08:00
|
|
|
extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
|
2013-03-22 12:31:11 +08:00
|
|
|
extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
|
2013-05-30 04:58:43 +08:00
|
|
|
List **retrieved_attrs);
|
2014-07-11 03:01:31 +08:00
|
|
|
extern void deparseStringLiteral(StringInfo buf, const char *val);
|
2015-11-04 01:46:06 +08:00
|
|
|
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
|
|
|
|
extern void appendOrderByClause(StringInfo buf, PlannerInfo *root,
|
|
|
|
RelOptInfo *baserel, List *pathkeys);
|
2013-02-21 18:26:23 +08:00
|
|
|
|
|
|
|
#endif /* POSTGRES_FDW_H */
|