PostgreSQL Source Code: src/backend/access/common/attmap.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

24

27

28

32

33

34

35

36

37

38

41{

43

47 return res;

48}

49

50

51

52

53

54

55void

57{

60}

61

62

63

64

65

66

67

68

69

70

71

72

73

77 const char *msg)

78{

80 int nincols;

81 int noutcols;

82 int n;

83 int i;

84 int j;

85 bool same;

86

87

88

89

90

91 n = outdesc->natts;

93

94 j = 0;

95 nincols = noutcols = 0;

96 same = true;

97 for (i = 0; i < n; i++)

98 {

100

101 if (outatt->attisdropped)

102 continue;

103 noutcols++;

104 for (; j < indesc->natts; j++)

105 {

107

108 if (inatt->attisdropped)

109 continue;

110 nincols++;

111

112

113 if (outatt->atttypid != inatt->atttypid ||

114 (outatt->atttypmod != inatt->atttypmod && outatt->atttypmod >= 0))

116 (errcode(ERRCODE_DATATYPE_MISMATCH),

118 errdetail("Returned type %s does not match expected type %s in column \"%s\" (position %d).",

120 inatt->atttypmod),

122 outatt->atttypmod),

123 NameStr(outatt->attname),

124 noutcols)));

126 j++;

127 break;

128 }

129 if (attrMap->attnums[i] == 0)

130 same = false;

131 }

132

133

134 for (; j < indesc->natts; j++)

135 {

137 continue;

138 nincols++;

139 same = false;

140 }

141

142

143 if (!same)

145 (errcode(ERRCODE_DATATYPE_MISMATCH),

147 errdetail("Number of returned columns (%d) does not match "

148 "expected column count (%d).",

149 nincols, noutcols)));

150

151

153 {

154

156 return NULL;

157 }

158

159 return attrMap;

160}

161

162

163

164

165

166

167

168

169

170

171

172

173

177 bool missing_ok)

178{

180 int outnatts;

181 int innatts;

182 int i;

183 int nextindesc = -1;

184

185 outnatts = outdesc->natts;

186 innatts = indesc->natts;

187

189 for (i = 0; i < outnatts; i++)

190 {

193 Oid atttypid;

195 int j;

196

197 if (outatt->attisdropped)

198 continue;

200 atttypid = outatt->atttypid;

201 atttypmod = outatt->atttypmod;

202

203

204

205

206

207

208

209

210

211

212

213

214 for (j = 0; j < innatts; j++)

215 {

217

218 nextindesc++;

219 if (nextindesc >= innatts)

220 nextindesc = 0;

221

223 if (inatt->attisdropped)

224 continue;

226 {

227

228 if (atttypid != inatt->atttypid || atttypmod != inatt->atttypmod)

230 (errcode(ERRCODE_DATATYPE_MISMATCH),

231 errmsg("could not convert row type"),

232 errdetail("Attribute \"%s\" of type %s does not match corresponding attribute of type %s.",

236 attrMap->attnums[i] = inatt->attnum;

237 break;

238 }

239 }

240 if (attrMap->attnums[i] == 0 && !missing_ok)

242 (errcode(ERRCODE_DATATYPE_MISMATCH),

243 errmsg("could not convert row type"),

244 errdetail("Attribute \"%s\" of type %s does not exist in type %s.",

248 }

249 return attrMap;

250}

251

252

253

254

255

256

257

258

259

263 bool missing_ok)

264{

266

267

269

270

272 {

273

275 return NULL;

276 }

277

278 return attrMap;

279}

280

281

282

283

284

285

286

287static bool

291{

292 int i;

293

294

296 return false;

297

298 for (i = 0; i < attrMap->maplen; i++)

299 {

302

303

304

305

307 return false;

308

309 if (attrMap->attnums[i] == (i + 1))

310 continue;

311

313

314

315

316

317

318

319 if (attrMap->attnums[i] == 0 &&

323 continue;

324

325 return false;

326 }

327

328 return true;

329}

void free_attrmap(AttrMap *map)

AttrMap * make_attrmap(int maplen)

AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)

AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)

static bool check_attrmap_match(TupleDesc indesc, TupleDesc outdesc, AttrMap *attrMap)

AttrMap * build_attrmap_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg)

int errmsg_internal(const char *fmt,...)

int errdetail(const char *fmt,...)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

char * format_type_with_typemod(Oid type_oid, int32 typemod)

char * format_type_be(Oid type_oid)

void pfree(void *pointer)

void * palloc0(Size size)

FormData_pg_attribute * Form_pg_attribute

static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)

static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)