spi.sgml
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:62k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. <Chapter id="spi">
  2. <DocInfo>
  3. <AuthorGroup>
  4. <Author>
  5. <FirstName>Vadim</FirstName>
  6. <Surname>Mikheev</Surname>
  7. </Author>
  8. </AuthorGroup>
  9. <Date>Transcribed 1998-01-16</Date>
  10. </DocInfo>
  11. <Title>Server Programming Interface</Title>
  12. <Para>
  13. The <FirstTerm>Server Programming Interface</FirstTerm> 
  14. (<Acronym>SPI</Acronym>) gives users the
  15. ability to run <Acronym>SQL</Acronym> queries inside user-defined 
  16. <Acronym>C</Acronym> functions.
  17. The available Procedural Languages (<Acronym>PL</Acronym>) give an alternate
  18. means to access these capabilities.
  19. </Para>
  20. <Para>
  21. In fact, <Acronym>SPI</Acronym> is just a set of native interface functions
  22. to simplify access to the Parser, Planner, Optimizer and Executor. 
  23. <Acronym>SPI</Acronym> also does some memory management.
  24. </Para>
  25. <Para>
  26. To avoid misunderstanding we'll use <FirstTerm>function</FirstTerm> 
  27. to mean <Acronym>SPI</Acronym> interface functions and 
  28. <FirstTerm>procedure</FirstTerm> for user-defined C-functions 
  29. using <Acronym>SPI</Acronym>.
  30. </Para>
  31. <Para>
  32. <Acronym>SPI</Acronym> procedures are always called by some (upper) 
  33. Executor and the <Acronym>SPI</Acronym>
  34. manager uses the Executor to run your queries. Other procedures may be
  35. called by the Executor running queries from your procedure.
  36. </Para>
  37. <Para>
  38. Note, that if during execution of a query from a procedure the transaction
  39. is aborted then control will not be returned to your procedure. Rather, all work
  40. will be rolled back and the server will wait for the next command from the
  41. client.  This will be changed in future versions.
  42. </Para>
  43. <Para>
  44. Other restrictions are the inability to execute BEGIN, END and ABORT
  45. (transaction control statements) and cursor operations.  This will also be
  46. changed in the future.
  47. </Para>
  48. <Para>
  49. If successful, <Acronym>SPI</Acronym> functions return a non-negative result (either via
  50. a returned integer value or in SPI_result global variable, as described below).
  51. On error, a negative or NULL result will be returned.
  52. </Para>
  53. <Sect1>
  54. <Title>Interface Functions</Title>
  55. <REFENTRY ID="SPI-SPICONNECT">
  56. <REFMETA>
  57. <REFENTRYTITLE>SPI_connect</REFENTRYTITLE>
  58. <REFMISCINFO>SPI - Connection Management</REFMISCINFO>
  59. </REFMETA>
  60. <REFNAMEDIV>
  61. <REFNAME>SPI_connect
  62. </REFNAME>
  63. <REFPURPOSE>
  64.    Connects your procedure to the SPI manager.
  65. </REFPURPOSE>
  66. <INDEXTERM ID="IX-SPI-SPICONNECT-1"><PRIMARY>SPI</PRIMARY><SECONDARY>connecting</SECONDARY></INDEXTERM>
  67. <INDEXTERM ID="IX-SPI-SPICONNECT-2"><PRIMARY>SPI_connect</PRIMARY></INDEXTERM>
  68. </REFNAMEDIV>
  69. <REFSYNOPSISDIV>
  70. <REFSYNOPSISDIVINFO>
  71. <DATE>1997-12-24</DATE>
  72. </REFSYNOPSISDIVINFO>
  73. <SYNOPSIS>
  74. int SPI_connect(void)
  75. </SYNOPSIS>
  76. <REFSECT2 ID="R2-SPI-SPICONNECT-1">
  77. <REFSECT2INFO>
  78. <DATE>1997-12-24</DATE>
  79. </REFSECT2INFO>
  80. <TITLE>Inputs
  81. </TITLE>
  82. <PARA>None
  83. </PARA>
  84. </REFSECT2>
  85. <REFSECT2 ID="R2-SPI-SPICONNECT-2">
  86. <REFSECT2INFO>
  87. <DATE>1997-12-24</DATE>
  88. </REFSECT2INFO>
  89. <TITLE>Outputs
  90. </TITLE>
  91. <VARIABLELIST>
  92. <VARLISTENTRY>
  93. <TERM>int
  94. </TERM>
  95. <LISTITEM>
  96. <PARA>
  97. Return status
  98. <VARIABLELIST>
  99. <VARLISTENTRY>
  100. <TERM><ReturnValue>SPI_OK_CONNECT</ReturnValue>
  101. </TERM>
  102. <LISTITEM>
  103. <PARA>
  104.    if connected
  105. </PARA>
  106. </LISTITEM>
  107. </VARLISTENTRY>
  108. <VARLISTENTRY>
  109. <TERM><ReturnValue>SPI_ERROR_CONNECT</ReturnValue>
  110. </TERM>
  111. <LISTITEM>
  112. <PARA>
  113.    if not connected
  114. </PARA>
  115. </LISTITEM>
  116. </VARLISTENTRY>
  117. </VARIABLELIST>
  118. </para>
  119. </LISTITEM>
  120. </VARLISTENTRY>
  121. </VARIABLELIST>
  122. </REFSECT2>
  123. </REFSYNOPSISDIV>
  124. <REFSECT1 ID="R1-SPI-SPICONNECT-1">
  125. <REFSECT1INFO>
  126. <DATE>1997-12-24</DATE>
  127. </REFSECT1INFO>
  128. <TITLE>Description
  129. </TITLE>
  130. <PARA>
  131. <FUNCTION>SPI_connect</FUNCTION> opens a connection to the <ProductName>Postgres</ProductName> backend.
  132.    You should call this function if you will need to execute queries. Some
  133.    utility SPI functions may be called from un-connected procedures.
  134. </PARA>
  135. <PARA>
  136.    You may get <ReturnValue>SPI_ERROR_CONNECT</ReturnValue> error if <Function>SPI_connect</Function> is
  137.    called from an already connected procedure - e.g. if you directly call one
  138.    procedure from another connected one.  Actually, while the child procedure
  139.    will be able to use SPI, your parent procedure will not be able to continue
  140.    to use SPI after the child returns (if <Function>SPI_finish</Function> is called by the child).
  141.    It's bad practice.
  142. </PARA>
  143. </REFSECT1>
  144. <REFSECT1 ID="R1-SPI-SPICONNECT-2">
  145. <TITLE>Usage
  146. </TITLE>
  147. <PARA>XXX thomas 1997-12-24
  148. </PARA>
  149. </REFSECT1>
  150. <REFSECT1 ID="R1-SPI-SPICONNECT-3">
  151. <TITLE>Algorithm
  152. </TITLE>
  153. <PARA><FUNCTION>SPI_connect</FUNCTION> performs the following:
  154. </PARA>
  155. <VARIABLELIST>
  156. <VARLISTENTRY>
  157. <TERM>&bull;
  158. </TERM>
  159. <LISTITEM>
  160. <PARA>
  161.   Initializes the SPI internal
  162.    structures for query execution and memory management.
  163. </PARA>
  164. </LISTITEM>
  165. </VARLISTENTRY>
  166. </VARIABLELIST>
  167. <PARA>
  168. </PARA>
  169. </REFSECT1>
  170. <!--
  171. <REFSECT1 ID="R1-SPI-SPICONNECT-4">
  172. <TITLE>Structures
  173. </TITLE>
  174. <PARA>None
  175. </PARA>
  176. </REFSECT1>
  177. -->
  178. </REFENTRY>
  179. <!-- *********************************************** -->
  180. <!-- *********************************************** -->
  181. <!-- *********************************************** -->
  182. <REFENTRY ID="SPI-SPIFINISH">
  183. <REFMETA>
  184. <REFENTRYTITLE>SPI_finish</REFENTRYTITLE>
  185. <REFMISCINFO>SPI - Connection Management</REFMISCINFO>
  186. </REFMETA>
  187. <REFNAMEDIV>
  188. <REFNAME>SPI_finish
  189. </REFNAME>
  190. <REFPURPOSE>
  191.    Disconnects your procedure from the SPI manager.
  192. </REFPURPOSE>
  193. <INDEXTERM ID="IX-SPI-SPIFINISH-1"><PRIMARY>SPI</PRIMARY><SECONDARY>disconnecting</SECONDARY></INDEXTERM>
  194. <INDEXTERM ID="IX-SPI-SPIFINISH-2"><PRIMARY>SPI_finish</PRIMARY></INDEXTERM>
  195. </REFNAMEDIV>
  196. <REFSYNOPSISDIV>
  197. <REFSYNOPSISDIVINFO>
  198. <DATE>1997-12-24</DATE>
  199. </REFSYNOPSISDIVINFO>
  200. <SYNOPSIS>
  201. SPI_finish(void)
  202. </SYNOPSIS>
  203. <REFSECT2 ID="R2-SPI-SPIFINISH-1">
  204. <REFSECT2INFO>
  205. <DATE>1997-12-24</DATE>
  206. </REFSECT2INFO>
  207. <TITLE>Inputs
  208. </TITLE>
  209. <PARA>None
  210. </PARA>
  211. </REFSECT2>
  212. <REFSECT2 ID="R2-SPI-SPIFINISH-2">
  213. <REFSECT2INFO>
  214. <DATE>1997-12-24</DATE>
  215. </REFSECT2INFO>
  216. <TITLE>Outputs
  217. </TITLE>
  218. <VARIABLELIST>
  219. <VARLISTENTRY>
  220. <TERM>int
  221. </TERM>
  222. <LISTITEM>
  223. <PARA>
  224. <SimpleList>
  225. <Member>
  226. <ReturnValue>SPI_OK_FINISH</ReturnValue>
  227.    if properly disconnected
  228. </Member>
  229. <Member>
  230. <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue>
  231.    if called from an un-connected procedure
  232. </Member>
  233. </SimpleList>
  234. </PARA>
  235. </LISTITEM>
  236. </VARLISTENTRY>
  237. </VARIABLELIST>
  238. </REFSECT2>
  239. </REFSYNOPSISDIV>
  240. <REFSECT1 ID="R1-SPI-SPIFINISH-1">
  241. <REFSECT1INFO>
  242. <DATE>1997-12-24</DATE>
  243. </REFSECT1INFO>
  244. <TITLE>Description
  245. </TITLE>
  246. <PARA>
  247. <FUNCTION>SPI_finish</FUNCTION> closes an existing connection to the <ProductName>Postgres</ProductName> backend.
  248.    You should call this function after completing operations through the SPI manager.
  249. </para>
  250. <PARA>
  251.    You may get the error return <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue> if <Function>SPI_finish</Function> is
  252.    called without having a current valid connection.
  253.  There is no fundamental problem
  254.    with this; it means that nothing was done by the SPI manager.
  255. </PARA>
  256. </REFSECT1>
  257. <REFSECT1 ID="R1-SPI-SPIFINISH-2">
  258. <TITLE>Usage
  259. </TITLE>
  260. <PARA>
  261.    <Function>SPI_finish</Function> <Emphasis>must</Emphasis> be called as a final step by a connected procedure
  262.  or you may get
  263.    unpredictable results! Note that you can safely skip the call to <Function>SPI_finish</Function>
  264.    if you abort the transaction (via elog(ERROR)).
  265. </PARA>
  266. </REFSECT1>
  267. <REFSECT1 ID="R1-SPI-SPIFINISH-3">
  268. <TITLE>Algorithm
  269. </TITLE>
  270. <PARA><FUNCTION>SPI_finish</FUNCTION> performs the following:
  271. </PARA>
  272. <VARIABLELIST>
  273. <VARLISTENTRY>
  274. <TERM>&bull;
  275. </TERM>
  276. <LISTITEM>
  277. <PARA>
  278.    Disconnects your procedure from the SPI manager and frees all memory
  279.    allocations made by your procedure via <Function>palloc</Function> since
  280.  the <Function>SPI_connect</Function>. 
  281.    These allocations can't be used any more! See Memory management.
  282. </PARA>
  283. </LISTITEM>
  284. </VARLISTENTRY>
  285. </VARIABLELIST>
  286. <PARA>
  287. </PARA>
  288. </REFSECT1>
  289. <!--
  290. <REFSECT1 ID="R1-SPI-SPIFINISH-4">
  291. <TITLE>Structures
  292. </TITLE>
  293. <PARA>None
  294. </PARA>
  295. </REFSECT1>
  296. -->
  297. </REFENTRY>
  298. <!-- *********************************************** -->
  299. <!-- *********************************************** -->
  300. <!-- *********************************************** -->
  301. <REFENTRY ID="SPI-SPIEXEC">
  302. <REFMETA>
  303. <REFENTRYTITLE>SPI_exec</REFENTRYTITLE>
  304. <REFMISCINFO>SPI - Connection Management</REFMISCINFO>
  305. </REFMETA>
  306. <REFNAMEDIV>
  307. <REFNAME>SPI_exec
  308. </REFNAME>
  309. <REFPURPOSE>
  310.    Creates an execution plan (parser+planner+optimizer) and executes a query.
  311. </REFPURPOSE>
  312. <INDEXTERM ID="IX-SPI-SPIEXEC-1"><PRIMARY>SPI</PRIMARY><SECONDARY>executing</SECONDARY></INDEXTERM>
  313. <INDEXTERM ID="IX-SPI-SPIEXEC-2"><PRIMARY>SPI_exec</PRIMARY></INDEXTERM>
  314. </REFNAMEDIV>
  315. <REFSYNOPSISDIV>
  316. <REFSYNOPSISDIVINFO>
  317. <DATE>1997-12-24</DATE>
  318. </REFSYNOPSISDIVINFO>
  319. <SYNOPSIS>
  320. SPI_exec(<REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE>)
  321. </SYNOPSIS>
  322. <REFSECT2 ID="R2-SPI-SPIEXEC-1">
  323. <REFSECT2INFO>
  324. <DATE>1997-12-24</DATE>
  325. </REFSECT2INFO>
  326. <TITLE>Inputs
  327. </TITLE>
  328. <VARIABLELIST>
  329. <VARLISTENTRY>
  330. <TERM>
  331. char *<REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>
  332. </TERM>
  333. <LISTITEM>
  334. <PARA>
  335. String containing query plan
  336. </PARA>
  337. </LISTITEM>
  338. </VARLISTENTRY>
  339. <VARLISTENTRY>
  340. <TERM>
  341. int <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE>
  342. </TERM>
  343. <LISTITEM>
  344. <PARA>
  345. Maximum number of tuples to return
  346. </PARA>
  347. </LISTITEM>
  348. </VARLISTENTRY>
  349. </VARIABLELIST>
  350. </REFSECT2>
  351. <REFSECT2 ID="R2-SPI-SPIEXEC-2">
  352. <REFSECT2INFO>
  353. <DATE>1997-12-24</DATE>
  354. </REFSECT2INFO>
  355. <TITLE>Outputs
  356. </TITLE>
  357. <VARIABLELIST>
  358. <VARLISTENTRY>
  359. <TERM>int
  360. </TERM>
  361. <LISTITEM>
  362. <PARA>
  363. <SimpleList>
  364. <Member>
  365.    <ReturnValue>SPI_OK_EXEC</ReturnValue> if properly disconnected
  366. </Member>
  367. <Member>
  368.    <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue> if called from an un-connected procedure
  369. </Member>
  370. <Member>
  371.    <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue> if query is NULL or <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> < 0.
  372. </Member>
  373. <Member>
  374.    <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue> if procedure is unconnected.
  375. </Member>
  376. <Member>
  377.    <ReturnValue>SPI_ERROR_COPY</ReturnValue> if COPY TO/FROM stdin.
  378. </Member>
  379. <Member>
  380.    <ReturnValue>SPI_ERROR_CURSOR</ReturnValue> if DECLARE/CLOSE CURSOR, FETCH.
  381. </Member>
  382. <Member>
  383.    <ReturnValue>SPI_ERROR_TRANSACTION</ReturnValue> if BEGIN/ABORT/END.
  384. </Member>
  385. <Member>
  386.    <ReturnValue>SPI_ERROR_OPUNKNOWN</ReturnValue> if type of query is unknown (this shouldn't occur).
  387. </Member>
  388. </SimpleList>
  389. </para>
  390. <Para>
  391.    If execution of your query was successful then one of the following
  392.    (non-negative) values will be returned:
  393. <SimpleList>
  394. <Member>
  395.    <ReturnValue>SPI_OK_UTILITY</ReturnValue> if some utility (e.g. CREATE TABLE ...) was executed
  396. </Member>
  397. <Member>
  398.    <ReturnValue>SPI_OK_SELECT</ReturnValue> if SELECT (but not SELECT ... INTO!) was executed
  399. </Member>
  400. <Member>
  401.    <ReturnValue>SPI_OK_SELINTO</ReturnValue> if SELECT ... INTO was executed
  402. </Member>
  403. <Member>
  404.    <ReturnValue>SPI_OK_INSERT</ReturnValue> if INSERT (or INSERT ... SELECT) was executed
  405. </Member>
  406. <Member>
  407.    <ReturnValue>SPI_OK_DELETE</ReturnValue> if DELETE was executed
  408. </Member>
  409. <Member>
  410.    <ReturnValue>SPI_OK_UPDATE</ReturnValue> if UPDATE was executed
  411. </Member>
  412. </SimpleList>
  413. </PARA>
  414. </LISTITEM>
  415. </VARLISTENTRY>
  416. </VARIABLELIST>
  417. </REFSECT2>
  418. </REFSYNOPSISDIV>
  419. <REFSECT1 ID="R1-SPI-SPIEXEC-1">
  420. <REFSECT1INFO>
  421. <DATE>1997-12-24</DATE>
  422. </REFSECT1INFO>
  423. <TITLE>Description
  424. </TITLE>
  425. <PARA>
  426. <FUNCTION>SPI_exec</FUNCTION> creates an execution plan (parser+planner+optimizer)
  427.  and executes the query for <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> tuples.
  428. </PARA>
  429. </REFSECT1>
  430. <REFSECT1 ID="R1-SPI-SPIEXEC-2">
  431. <TITLE>Usage
  432. </TITLE>
  433. <PARA>
  434.   This should only be called from a connected procedure.
  435.    If <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> is zero then it executes the query for all tuples returned by the
  436.    query scan. Using <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> > 0 you may restrict the number of tuples for
  437.    which the query will be executed. For example,
  438. <ProgramListing>
  439. SPI_exec ("insert into table select * from table", 5);
  440. </ProgramListing>
  441. will allow at most 5 tuples to be inserted into table.
  442.    If execution of your query was successful then a non-negative value will be returned.
  443. <Note>
  444. <Para>
  445. You may pass many queries in one string or query string may be
  446.    re-written by RULEs. <Function>SPI_exec</Function> returns the result for the last query
  447.    executed.
  448. </Para>
  449. </Note>
  450. </para>
  451. <Para>
  452.    The actual number of tuples for which the (last) query was executed is
  453.    returned in the global variable SPI_processed (if not <ReturnValue>SPI_OK_UTILITY</ReturnValue>).
  454.    If <ReturnValue>SPI_OK_SELECT</ReturnValue> returned and SPI_processed &gt; 0 then you may use global
  455.    pointer SPITupleTable *SPI_tuptable to access the selected tuples:
  456.    Also NOTE, that <Function>SPI_finish</Function> frees and makes all SPITupleTables
  457.    unusable! (See Memory management).
  458. </Para>
  459. <Para>
  460.    <Function>SPI_exec</Function> may return one of the following (negative) values:
  461. <SimpleList>
  462. <Member>
  463.    <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue> if query is NULL or <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> < 0.
  464. </Member>
  465. <Member>
  466.    <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue> if procedure is unconnected.
  467. </Member>
  468. <Member>
  469.    <ReturnValue>SPI_ERROR_COPY</ReturnValue> if COPY TO/FROM stdin.
  470. </Member>
  471. <Member>
  472.    <ReturnValue>SPI_ERROR_CURSOR</ReturnValue> if DECLARE/CLOSE CURSOR, FETCH.
  473. </Member>
  474. <Member>
  475.    <ReturnValue>SPI_ERROR_TRANSACTION</ReturnValue> if BEGIN/ABORT/END.
  476. </Member>
  477. <Member>
  478.    <ReturnValue>SPI_ERROR_OPUNKNOWN</ReturnValue> if type of query is unknown (this shouldn't occur).
  479. </Member>
  480. </SimpleList>
  481. </PARA>
  482. </REFSECT1>
  483. <REFSECT1 ID="R1-SPI-SPIEXEC-3">
  484. <TITLE>Algorithm
  485. </TITLE>
  486. <PARA><FUNCTION>SPI_exec</FUNCTION> performs the following:
  487. </PARA>
  488. <VARIABLELIST>
  489. <VARLISTENTRY>
  490. <TERM>&bull;
  491. </TERM>
  492. <LISTITEM>
  493. <PARA>
  494.    Disconnects your procedure from the SPI manager and frees all memory
  495.    allocations made by your procedure via <Function>palloc</Function> since the <Function>SPI_connect</Function>. 
  496.    These allocations can't be used any more! See Memory management.
  497. </PARA>
  498. </LISTITEM>
  499. </VARLISTENTRY>
  500. </VARIABLELIST>
  501. <PARA>
  502. </PARA>
  503. </REFSECT1>
  504. <!--
  505. <REFSECT1 ID="R1-SPI-SPIEXEC-4">
  506. <TITLE>Structures
  507. </TITLE>
  508. <PARA>
  509.    If <ReturnValue>SPI_OK_SELECT</ReturnValue> returned and SPI_processed > 0 then you may use the global
  510.    pointer SPITupleTable *SPI_tuptable to access the selected tuples.
  511. <Para>
  512.    Structure SPITupleTable is defined in spi.h:
  513. <ProgramListing>
  514.    typedef struct
  515.    {
  516.        uint32      alloced;        /* # of alloced vals */
  517.        uint32      free;           /* # of free vals */
  518.        TupleDesc   tupdesc;        /* tuple descriptor */
  519.        HeapTuple  *vals;           /* tuples */
  520.    } SPITupleTable;
  521. </ProgramListing>
  522. <Para>
  523.    HeapTuple *vals is an array of pointers to tuples. TupleDesc tupdesc is
  524.    a tuple descriptor which you may pass to SPI functions dealing with
  525.    tuples.
  526. <Para>
  527.    NOTE! Functions <Function>SPI_exec</Function>, <Function>SPI_execp</Function> and <Function>SPI_prepare</Function> change both
  528.    SPI_processed and SPI_tuptable (just the pointer, not the contents of the
  529.    structure)!  So, save them in local procedure variables if you need them.
  530. <Para>
  531.    Also NOTE, that <Function>SPI_finish</Function> frees and makes all SPITupleTables
  532.    unusable! (See Memory management).
  533. </PARA>
  534. </REFSECT1>
  535. -->
  536. </REFENTRY>
  537. <!-- *********************************************** -->
  538. <!-- *********************************************** -->
  539. <!-- *********************************************** -->
  540. <REFENTRY ID="SPI-SPIPREPARE">
  541. <REFMETA>
  542. <REFENTRYTITLE>SPI_prepare</REFENTRYTITLE>
  543. <REFMISCINFO>SPI - Plan Preparation</REFMISCINFO>
  544. </REFMETA>
  545. <REFNAMEDIV>
  546. <REFNAME>SPI_prepare
  547. </REFNAME>
  548. <REFPURPOSE>
  549.    Connects your procedure to the SPI manager.
  550. </REFPURPOSE>
  551. <INDEXTERM ID="IX-SPI-SPIPREPARE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>connecting</SECONDARY></INDEXTERM>
  552. <INDEXTERM ID="IX-SPI-SPIPREPARE-2"><PRIMARY>SPI_prepare</PRIMARY></INDEXTERM>
  553. </REFNAMEDIV>
  554. <REFSYNOPSISDIV>
  555. <REFSYNOPSISDIVINFO>
  556. <DATE>1997-12-24</DATE>
  557. </REFSYNOPSISDIVINFO>
  558. <SYNOPSIS>
  559. SPI_prepare(<REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">nargs</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">argtypes</REPLACEABLE>)
  560. </SYNOPSIS>
  561. <REFSECT2 ID="R2-SPI-SPIPREPARE-1">
  562. <REFSECT2INFO>
  563. <DATE>1997-12-24</DATE>
  564. </REFSECT2INFO>
  565. <TITLE>Inputs
  566. </TITLE>
  567. <VARIABLELIST>
  568. <VARLISTENTRY>
  569. <TERM>
  570. <REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>
  571. </TERM>
  572. <LISTITEM>
  573. <PARA>
  574. Query string
  575. </PARA>
  576. </LISTITEM>
  577. </VARLISTENTRY>
  578. <VARLISTENTRY>
  579. <TERM>
  580. <REPLACEABLE CLASS="PARAMETER">nargs</REPLACEABLE>
  581. </TERM>
  582. <LISTITEM>
  583. <PARA>
  584. Number of input parameters ($1 ... $nargs - as in SQL-functions)
  585. </PARA>
  586. </LISTITEM>
  587. </VARLISTENTRY>
  588. <VARLISTENTRY>
  589. <TERM>
  590. <REPLACEABLE CLASS="PARAMETER">argtypes</REPLACEABLE>
  591. </TERM>
  592. <LISTITEM>
  593. <PARA>
  594. Pointer list of type <Acronym>OID</Acronym>s to input arguments
  595. </PARA>
  596. </LISTITEM>
  597. </VARLISTENTRY>
  598. </VARIABLELIST>
  599. </REFSECT2>
  600. <REFSECT2 ID="R2-SPI-SPIPREPARE-2">
  601. <REFSECT2INFO>
  602. <DATE>1997-12-24</DATE>
  603. </REFSECT2INFO>
  604. <TITLE>Outputs
  605. </TITLE>
  606. <VARIABLELIST>
  607. <VARLISTENTRY>
  608. <TERM>void *
  609. </TERM>
  610. <LISTITEM>
  611. <PARA>
  612. Pointer to an execution plan (parser+planner+optimizer)
  613. </PARA>
  614. </LISTITEM>
  615. </VARLISTENTRY>
  616. </VARIABLELIST>
  617. </REFSECT2>
  618. </REFSYNOPSISDIV>
  619. <REFSECT1 ID="R1-SPI-SPIPREPARE-1">
  620. <REFSECT1INFO>
  621. <DATE>1997-12-24</DATE>
  622. </REFSECT1INFO>
  623. <TITLE>Description
  624. </TITLE>
  625. <PARA>
  626. <FUNCTION>SPI_prepare</FUNCTION> 
  627.    creates and returns an execution plan (parser+planner+optimizer) but doesn't
  628.    execute the query. Should only be called from a connected procedure.
  629. </PARA>
  630. </REFSECT1>
  631. <REFSECT1 ID="R1-SPI-SPIPREPARE-2">
  632. <TITLE>Usage
  633. </TITLE>
  634. <PARA>
  635.    nargs is number of parameters ($1 ... $nargs - as in SQL-functions),
  636.    and nargs may be 0 only if there is not any $1 in query.
  637. </para>
  638. <Para>
  639.    Execution of prepared execution plans is sometimes much faster so this
  640.    feature may be useful if the same query will be executed many times.
  641. </para>
  642. <Para>
  643. The plan returned by <Function>SPI_prepare</Function> may be used only in current
  644.    invocation of the procedure since <Function>SPI_finish</Function> frees memory allocated for a plan. 
  645.    See <Function>SPI_saveplan</Function>.
  646. </para>
  647. <Para>
  648.    If successful, a non-null pointer will be returned. Otherwise, you'll get
  649.    a NULL plan.  In both cases SPI_result will be set like the value returned
  650.    by SPI_exec, except that it is set to 
  651.    <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue> if query is NULL or nargs < 0 or nargs > 0 && argtypes
  652.    is NULL.
  653. </PARA>
  654. </REFSECT1>
  655. <!--
  656. <REFSECT1 ID="R1-SPI-SPIPREPARE-3">
  657. <TITLE>Algorithm
  658. </TITLE>
  659. <PARA><FUNCTION>SPI_prepare</FUNCTION> performs the following:
  660. </PARA>
  661. <VARIABLELIST>
  662. <VARLISTENTRY>
  663. <TERM>&bull;
  664. </TERM>
  665. <LISTITEM>
  666. <PARA>
  667. TBD
  668. </PARA>
  669. </LISTITEM>
  670. </VARLISTENTRY>
  671. </VARIABLELIST>
  672. <PARA>
  673. </PARA>
  674. </REFSECT1>
  675. -->
  676. <!--
  677. <REFSECT1 ID="R1-SPI-SPIPREPARE-4">
  678. <TITLE>Structures
  679. </TITLE>
  680. <PARA>None
  681. </PARA>
  682. </REFSECT1>
  683. -->
  684. </REFENTRY>
  685. <!-- *********************************************** -->
  686. <!-- *********************************************** -->
  687. <!-- *********************************************** -->
  688. <REFENTRY ID="SPI-SPISAVEPLAN">
  689. <REFMETA>
  690. <REFENTRYTITLE>SPI_saveplan</REFENTRYTITLE>
  691. <REFMISCINFO>SPI - Plan Storage</REFMISCINFO>
  692. </REFMETA>
  693. <REFNAMEDIV>
  694. <REFNAME>SPI_saveplan
  695. </REFNAME>
  696. <REFPURPOSE>
  697.    Saves a passed plan
  698. </REFPURPOSE>
  699. <INDEXTERM ID="IX-SPI-SPISAVEPLAN-1"><PRIMARY>SPI</PRIMARY><SECONDARY>connecting</SECONDARY></INDEXTERM>
  700. <INDEXTERM ID="IX-SPI-SPISAVEPLAN-2"><PRIMARY>SPI_saveplan</PRIMARY></INDEXTERM>
  701. </REFNAMEDIV>
  702. <REFSYNOPSISDIV>
  703. <REFSYNOPSISDIVINFO>
  704. <DATE>1997-12-24</DATE>
  705. </REFSYNOPSISDIVINFO>
  706. <SYNOPSIS>
  707. SPI_saveplan(<REPLACEABLE CLASS="PARAMETER">plan</REPLACEABLE>)
  708. </SYNOPSIS>
  709. <REFSECT2 ID="R2-SPI-SPISAVEPLAN-1">
  710. <REFSECT2INFO>
  711. <DATE>1997-12-24</DATE>
  712. </REFSECT2INFO>
  713. <TITLE>Inputs
  714. </TITLE>
  715. <VARIABLELIST>
  716. <VARLISTENTRY>
  717. <TERM>
  718. void *<REPLACEABLE CLASS="PARAMETER">query</REPLACEABLE>
  719. </TERM>
  720. <LISTITEM>
  721. <PARA>
  722. Passed plan
  723. </PARA>
  724. </LISTITEM>
  725. </VARLISTENTRY>
  726. </VARIABLELIST>
  727. </REFSECT2>
  728. <REFSECT2 ID="R2-SPI-SPISAVEPLAN-2">
  729. <REFSECT2INFO>
  730. <DATE>1997-12-24</DATE>
  731. </REFSECT2INFO>
  732. <TITLE>Outputs
  733. </TITLE>
  734. <VARIABLELIST>
  735. <VARLISTENTRY>
  736. <TERM>void *
  737. </TERM>
  738. <LISTITEM>
  739. <PARA>
  740. Execution plan location. NULL if unsuccessful.
  741. </PARA>
  742. </LISTITEM>
  743. </VARLISTENTRY>
  744. <VARLISTENTRY>
  745. <TERM>SPI_result
  746. </TERM>
  747. <LISTITEM>
  748. <PARA>
  749. <SimpleList>
  750. <Member>
  751.    <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue> if plan is NULL
  752. </Member>
  753. <Member>
  754.    <ReturnValue>SPI_ERROR_UNCONNECTED</ReturnValue> if procedure is un-connected
  755. </Member>
  756. </SimpleList>
  757. </PARA>
  758. </LISTITEM>
  759. </VARLISTENTRY>
  760. </VARIABLELIST>
  761. </REFSECT2>
  762. </REFSYNOPSISDIV>
  763. <REFSECT1 ID="R1-SPI-SPISAVEPLAN-1">
  764. <REFSECT1INFO>
  765. <DATE>1997-12-24</DATE>
  766. </REFSECT1INFO>
  767. <TITLE>Description
  768. </TITLE>
  769. <PARA>
  770. <FUNCTION>SPI_saveplan</FUNCTION> 
  771.    stores a plan prepared by <Function>SPI_prepare</Function> in safe memory
  772.    protected from freeing by <Function>SPI_finish</Function> or the transaction manager.
  773. </para>
  774. <Para>
  775.    In the current version of <ProductName>Postgres</ProductName> there is no ability to
  776.  store prepared plans in the system
  777.    catalog and fetch them from there for execution. This will be implemented
  778.    in future versions.
  779.    As an alternative, there is the ability to reuse prepared plans in the
  780.    consequent invocations of your procedure in the current session.
  781.    Use <Function>SPI_execp</Function> to execute this saved plan.
  782. </PARA>
  783. </REFSECT1>
  784. <REFSECT1 ID="R1-SPI-SPISAVEPLAN-2">
  785. <TITLE>Usage
  786. </TITLE>
  787. <Para>
  788.    <Function>SPI_saveplan</Function> saves a passed plan (prepared by <Function>SPI_prepare</Function>) in memory
  789.    protected from freeing by <Function>SPI_finish</Function> and by the transaction manager and
  790.    returns a pointer to the saved plan.  You may save the pointer returned in
  791.    a local variable.  Always check if this pointer is NULL or not either when
  792.    preparing a plan or using an already prepared plan in SPI_execp (see below).
  793. <Note>
  794. <Para>
  795.    If one of the objects (a relation, function, etc.) referenced by the prepared
  796.    plan is dropped during your session (by your backend or another process) then the
  797.    results of <Function>SPI_execp</Function> for this plan will be unpredictable.
  798. </Para>
  799. </Note>
  800. </PARA>
  801. </REFSECT1>
  802. <!--
  803. <REFSECT1 ID="R1-SPI-SPISAVEPLAN-3">
  804. <TITLE>Algorithm
  805. </TITLE>
  806. <PARA><FUNCTION>SPI_saveplan</FUNCTION> performs the following:
  807. </PARA>
  808. <VARIABLELIST>
  809. <VARLISTENTRY>
  810. <TERM>&bull;
  811. </TERM>
  812. <LISTITEM>
  813. <PARA>
  814. TBD
  815. </PARA>
  816. </LISTITEM>
  817. </VARLISTENTRY>
  818. </VARIABLELIST>
  819. <PARA>
  820. </PARA>
  821. </REFSECT1>
  822. -->
  823. <!--
  824. <REFSECT1 ID="R1-SPI-SPISAVEPLAN-4">
  825. <TITLE>Structures
  826. </TITLE>
  827. <PARA>None
  828. </PARA>
  829. </REFSECT1>
  830. -->
  831. </REFENTRY>
  832. <!-- *********************************************** -->
  833. <!-- *********************************************** -->
  834. <!-- *********************************************** -->
  835. <REFENTRY ID="SPI-SPIEXECP">
  836. <REFMETA>
  837. <REFENTRYTITLE>SPI_execp</REFENTRYTITLE>
  838. <REFMISCINFO>SPI - Plan Execution</REFMISCINFO>
  839. </REFMETA>
  840. <REFNAMEDIV>
  841. <REFNAME>SPI_execp
  842. </REFNAME>
  843. <REFPURPOSE>
  844. Executes a plan from <Function>SPI_saveplan</Function>
  845. </REFPURPOSE>
  846. <INDEXTERM ID="IX-SPI-SPIEXECP-1"><PRIMARY>SPI</PRIMARY><SECONDARY>connecting</SECONDARY></INDEXTERM>
  847. <INDEXTERM ID="IX-SPI-SPIEXECP-2"><PRIMARY>SPI_execp</PRIMARY></INDEXTERM>
  848. </REFNAMEDIV>
  849. <REFSYNOPSISDIV>
  850. <REFSYNOPSISDIVINFO>
  851. <DATE>1997-12-24</DATE>
  852. </REFSYNOPSISDIVINFO>
  853. <SYNOPSIS>
  854. SPI_execp(<REPLACEABLE CLASS="PARAMETER">plan</REPLACEABLE>,
  855. <REPLACEABLE CLASS="PARAMETER">values</REPLACEABLE>,
  856. <REPLACEABLE CLASS="PARAMETER">nulls</REPLACEABLE>,
  857. <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE>)
  858. </SYNOPSIS>
  859. <REFSECT2 ID="R2-SPI-SPIEXECP-1">
  860. <REFSECT2INFO>
  861. <DATE>1997-12-24</DATE>
  862. </REFSECT2INFO>
  863. <TITLE>Inputs
  864. </TITLE>
  865. <VARIABLELIST>
  866. <VARLISTENTRY>
  867. <TERM>
  868. void *<REPLACEABLE CLASS="PARAMETER">plan</REPLACEABLE>
  869. </TERM>
  870. <LISTITEM>
  871. <PARA>
  872. Execution plan
  873. </PARA>
  874. </LISTITEM>
  875. </VARLISTENTRY>
  876. <VARLISTENTRY>
  877. <TERM>
  878. Datum *<REPLACEABLE CLASS="PARAMETER">values</REPLACEABLE>
  879. </TERM>
  880. <LISTITEM>
  881. <PARA>
  882. Actual parameter values
  883. </PARA>
  884. </LISTITEM>
  885. </VARLISTENTRY>
  886. <VARLISTENTRY>
  887. <TERM>
  888. char *<REPLACEABLE CLASS="PARAMETER">nulls</REPLACEABLE>
  889. </TERM>
  890. <LISTITEM>
  891. <PARA>
  892. Array describing what parameters get NULLs
  893. <SimpleList>
  894. <Member>'n' indicates NULL allowed</Member>
  895. <Member>' ' indicates NULL not allowed</Member>
  896. </SimpleList>
  897. </PARA>
  898. </LISTITEM>
  899. </VARLISTENTRY>
  900. <VARLISTENTRY>
  901. <TERM>
  902. int <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE>
  903. </TERM>
  904. <LISTITEM>
  905. <PARA>
  906. Number of tuples for which plan is to be executed
  907. </PARA>
  908. </LISTITEM>
  909. </VARLISTENTRY>
  910. </VARIABLELIST>
  911. </REFSECT2>
  912. <REFSECT2 ID="R2-SPI-SPIEXECP-2">
  913. <REFSECT2INFO>
  914. <DATE>1997-12-24</DATE>
  915. </REFSECT2INFO>
  916. <TITLE>Outputs
  917. </TITLE>
  918. <VARIABLELIST>
  919. <VARLISTENTRY>
  920. <TERM>int
  921. </TERM>
  922. <LISTITEM>
  923. <PARA>
  924.    Returns the same value as <Function>SPI_exec</Function> as well as
  925. <SimpleList>
  926. <Member>
  927.  <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue>
  928.  if <REPLACEABLE CLASS="PARAMETER">plan</REPLACEABLE>
  929.  is NULL or <REPLACEABLE CLASS="PARAMETER">tcount</REPLACEABLE> &lt; 0
  930. </Member>
  931. <Member>
  932.    <ReturnValue>SPI_ERROR_PARAM</ReturnValue>
  933.  if <REPLACEABLE CLASS="PARAMETER">values</REPLACEABLE>
  934.  is NULL
  935.  and <REPLACEABLE CLASS="PARAMETER">plan</REPLACEABLE>
  936.  was prepared with some parameters.
  937. </Member>
  938. </SimpleList>
  939. </para>
  940. </LISTITEM>
  941. </VARLISTENTRY>
  942. <VARLISTENTRY>
  943. <TERM>SPI_tuptable
  944. </TERM>
  945. <LISTITEM>
  946. <PARA>
  947. initialized as in
  948.    <Function>SPI_exec</Function> if successful
  949. </PARA>
  950. </LISTITEM>
  951. </VARLISTENTRY>
  952. <VARLISTENTRY>
  953. <TERM>SPI_processed
  954. </TERM>
  955. <LISTITEM>
  956. <PARA>
  957. initialized as in
  958.    <Function>SPI_exec</Function> if successful
  959. </para>
  960. </listitem>
  961. </VARLISTENTRY>
  962. </VARIABLELIST>
  963. </REFSECT2>
  964. </REFSYNOPSISDIV>
  965. <REFSECT1 ID="R1-SPI-SPIEXECP-1">
  966. <REFSECT1INFO>
  967. <DATE>1997-12-24</DATE>
  968. </REFSECT1INFO>
  969. <TITLE>Description
  970. </TITLE>
  971. <PARA>
  972. <FUNCTION>SPI_execp</FUNCTION> 
  973.    stores a plan prepared by <Function>SPI_prepare</Function> in safe memory
  974.    protected from freeing by <Function>SPI_finish</Function> or the transaction manager.
  975. </para>
  976. <Para>
  977.    In the current version of <ProductName>Postgres</ProductName> there is no ability to
  978.  store prepared plans in the system
  979.    catalog and fetch them from there for execution. This will be implemented
  980.    in future versions.
  981.    As a work arround, there is the ability to reuse prepared plans in the
  982.    consequent invocations of your procedure in the current session.
  983.    Use <Function>SPI_execp</Function> to execute this saved plan.
  984. </PARA>
  985. </REFSECT1>
  986. <REFSECT1 ID="R1-SPI-SPIEXECP-2">
  987. <TITLE>Usage
  988. </TITLE>
  989. <Para>
  990.    If <REPLACEABLE CLASS="PARAMETER">nulls</REPLACEABLE>
  991. is NULL then 
  992.    <Function>SPI_execp</Function> 
  993. assumes that all values (if any) are NOT NULL.
  994. <Note>
  995. <Para>
  996.    If one of the objects (a relation, function, etc.) referenced by the prepared
  997.    plan is dropped during your session (by your backend or another process) then the
  998.    results of <Function>SPI_execp</Function> for this plan will be unpredictable.
  999. </Para>
  1000. </Note>
  1001. </PARA>
  1002. </REFSECT1>
  1003. <!--
  1004. <REFSECT1 ID="R1-SPI-SPIEXECP-3">
  1005. <TITLE>Algorithm
  1006. </TITLE>
  1007. <PARA><FUNCTION>SPI_execp</FUNCTION> performs the following:
  1008. </PARA>
  1009. <VARIABLELIST>
  1010. <VARLISTENTRY>
  1011. <TERM>&bull;
  1012. </TERM>
  1013. <LISTITEM>
  1014. <PARA>
  1015. TBD
  1016. </PARA>
  1017. </LISTITEM>
  1018. </VARLISTENTRY>
  1019. </VARIABLELIST>
  1020. <PARA>
  1021. </PARA>
  1022. </REFSECT1>
  1023. -->
  1024. <!--
  1025. <REFSECT1 ID="R1-SPI-SPIEXECP-4">
  1026. <TITLE>Structures
  1027. </TITLE>
  1028. <PARA>None
  1029. </PARA>
  1030. </REFSECT1>
  1031. -->
  1032. </REFENTRY>
  1033. </Sect1>
  1034. <Sect1>
  1035. <Title>Interface Support Functions</Title>
  1036. <Para>
  1037. All functions described below may be used by connected and unconnected
  1038. procedures.
  1039. </Para>
  1040. <!-- *********************************************** -->
  1041. <!-- *********************************************** -->
  1042. <!-- *********************************************** -->
  1043. <REFENTRY ID="SPI-SPICOPYTUPLE">
  1044. <REFMETA>
  1045. <REFENTRYTITLE>SPI_copytuple</REFENTRYTITLE>
  1046. <REFMISCINFO>SPI - Tuple Copy</REFMISCINFO>
  1047. </REFMETA>
  1048. <REFNAMEDIV>
  1049. <REFNAME>SPI_copytuple
  1050. </REFNAME>
  1051. <REFPURPOSE>
  1052. Makes copy of tuple in upper Executor context
  1053. </REFPURPOSE>
  1054. <INDEXTERM ID="IX-SPI-SPICOPYTUPLE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>copying tuples</SECONDARY></INDEXTERM>
  1055. <INDEXTERM ID="IX-SPI-SPICOPYTUPLE-2"><PRIMARY>SPI_copytuple</PRIMARY></INDEXTERM>
  1056. </REFNAMEDIV>
  1057. <REFSYNOPSISDIV>
  1058. <REFSYNOPSISDIVINFO>
  1059. <DATE>1997-12-24</DATE>
  1060. </REFSYNOPSISDIVINFO>
  1061. <SYNOPSIS>
  1062. SPI_copytuple(<REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>)
  1063. </SYNOPSIS>
  1064. <REFSECT2 ID="R2-SPI-SPICOPYTUPLE-1">
  1065. <REFSECT2INFO>
  1066. <DATE>1997-12-24</DATE>
  1067. </REFSECT2INFO>
  1068. <TITLE>Inputs
  1069. </TITLE>
  1070. <VARIABLELIST>
  1071. <VARLISTENTRY>
  1072. <TERM>
  1073. HeapTuple <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1074. </TERM>
  1075. <LISTITEM>
  1076. <PARA>
  1077. Input tuple to be copied
  1078. </PARA>
  1079. </LISTITEM>
  1080. </VARLISTENTRY>
  1081. </VARIABLELIST>
  1082. </REFSECT2>
  1083. <REFSECT2 ID="R2-SPI-SPICOPYTUPLE-2">
  1084. <REFSECT2INFO>
  1085. <DATE>1997-12-24</DATE>
  1086. </REFSECT2INFO>
  1087. <TITLE>Outputs
  1088. </TITLE>
  1089. <VARIABLELIST>
  1090. <VARLISTENTRY>
  1091. <TERM>
  1092. HeapTuple
  1093. </TERM>
  1094. <LISTITEM>
  1095. <PARA>
  1096. Copied tuple
  1097. <SimpleList>
  1098. <Member>
  1099.  <ReturnValue>non-NULL</ReturnValue>
  1100.  if <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1101.  is not NULL and the copy was successful
  1102. </Member>
  1103. <Member>
  1104.    <ReturnValue>NULL</ReturnValue>
  1105.  only if <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1106.  is NULL
  1107. </Member>
  1108. </SimpleList>
  1109. </para>
  1110. </LISTITEM>
  1111. </VARLISTENTRY>
  1112. </VARIABLELIST>
  1113. </REFSECT2>
  1114. </REFSYNOPSISDIV>
  1115. <REFSECT1 ID="R1-SPI-SPICOPYTUPLE-1">
  1116. <REFSECT1INFO>
  1117. <DATE>1997-12-24</DATE>
  1118. </REFSECT1INFO>
  1119. <TITLE>Description
  1120. </TITLE>
  1121. <PARA>
  1122. <FUNCTION>SPI_copytuple</FUNCTION> 
  1123.    makes a copy of tuple in upper Executor context. See the section on Memory Management.
  1124. </PARA>
  1125. </REFSECT1>
  1126. <REFSECT1 ID="R1-SPI-SPICOPYTUPLE-2">
  1127. <TITLE>Usage
  1128. </TITLE>
  1129. <Para>
  1130. TBD
  1131. </PARA>
  1132. </REFSECT1>
  1133. <!--
  1134. <REFSECT1 ID="R1-SPI-SPICOPYTUPLE-3">
  1135. <TITLE>Algorithm
  1136. </TITLE>
  1137. <PARA>
  1138. </PARA>
  1139. </REFSECT1>
  1140. -->
  1141. <!--
  1142. <REFSECT1 ID="R1-SPI-SPICOPYTUPLE-4">
  1143. <TITLE>Structures
  1144. </TITLE>
  1145. <PARA>None
  1146. </PARA>
  1147. </REFSECT1>
  1148. -->
  1149. </REFENTRY>
  1150. <!-- *********************************************** -->
  1151. <!-- *********************************************** -->
  1152. <!-- *********************************************** -->
  1153. <REFENTRY ID="SPI-SPIMODIFYTUPLE">
  1154. <REFMETA>
  1155. <REFENTRYTITLE>SPI_modifytuple</REFENTRYTITLE>
  1156. <REFMISCINFO>SPI - Tuple Modify</REFMISCINFO>
  1157. </REFMETA>
  1158. <REFNAMEDIV>
  1159. <REFNAME>SPI_modifytuple
  1160. </REFNAME>
  1161. <REFPURPOSE>
  1162. Modifies tuple of relation
  1163. </REFPURPOSE>
  1164. <INDEXTERM ID="IX-SPI-SPIMODIFYTUPLE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>modifying tuples</SECONDARY></INDEXTERM>
  1165. <INDEXTERM ID="IX-SPI-SPIMODIFYTUPLE-2"><PRIMARY>SPI_modifytuple</PRIMARY></INDEXTERM>
  1166. </REFNAMEDIV>
  1167. <REFSYNOPSISDIV>
  1168. <REFSYNOPSISDIVINFO>
  1169. <DATE>1997-12-24</DATE>
  1170. </REFSYNOPSISDIVINFO>
  1171. <SYNOPSIS>
  1172. SPI_modifytuple(<REPLACEABLE CLASS="PARAMETER">rel</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE> , <REPLACEABLE CLASS="PARAMETER">nattrs</REPLACEABLE>
  1173. , <REPLACEABLE CLASS="PARAMETER">attnum</REPLACEABLE> , <REPLACEABLE CLASS="PARAMETER">Values</REPLACEABLE> , <REPLACEABLE CLASS="PARAMETER">Nulls</REPLACEABLE>)
  1174. </SYNOPSIS>
  1175. <REFSECT2 ID="R2-SPI-SPIMODIFYTUPLE-1">
  1176. <REFSECT2INFO>
  1177. <DATE>1997-12-24</DATE>
  1178. </REFSECT2INFO>
  1179. <TITLE>Inputs
  1180. </TITLE>
  1181. <VARIABLELIST>
  1182. <VARLISTENTRY>
  1183. <TERM>
  1184. Relation <REPLACEABLE CLASS="PARAMETER">rel</REPLACEABLE>
  1185. </TERM>
  1186. <LISTITEM>
  1187. <PARA>
  1188. </PARA>
  1189. </LISTITEM>
  1190. </VARLISTENTRY>
  1191. <VARLISTENTRY>
  1192. <TERM>
  1193. HeapTuple <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1194. </TERM>
  1195. <LISTITEM>
  1196. <PARA>
  1197. Input tuple to be modified
  1198. </PARA>
  1199. </LISTITEM>
  1200. </VARLISTENTRY>
  1201. <VARLISTENTRY>
  1202. <TERM>
  1203. int <REPLACEABLE CLASS="PARAMETER">nattrs</REPLACEABLE>
  1204. </TERM>
  1205. <LISTITEM>
  1206. <PARA>
  1207. Number of attribute numbers in attnum
  1208. </PARA>
  1209. </LISTITEM>
  1210. </VARLISTENTRY>
  1211. <VARLISTENTRY>
  1212. <TERM>
  1213. int * <REPLACEABLE CLASS="PARAMETER">attnum</REPLACEABLE>
  1214. </TERM>
  1215. <LISTITEM>
  1216. <PARA>
  1217. Array of numbers of the attributes which are to be changed
  1218. </PARA>
  1219. </LISTITEM>
  1220. </VARLISTENTRY>
  1221. <VARLISTENTRY>
  1222. <TERM>
  1223. Datum * <REPLACEABLE CLASS="PARAMETER">Values</REPLACEABLE>
  1224. </TERM>
  1225. <LISTITEM>
  1226. <PARA>
  1227. New values for the attributes specified
  1228. </PARA>
  1229. </LISTITEM>
  1230. </VARLISTENTRY>
  1231. <VARLISTENTRY>
  1232. <TERM>
  1233. char * <REPLACEABLE CLASS="PARAMETER">Nulls</REPLACEABLE>
  1234. </TERM>
  1235. <LISTITEM>
  1236. <PARA>
  1237. Which attributes are NULL, if any
  1238. </PARA>
  1239. </LISTITEM>
  1240. </VARLISTENTRY>
  1241. </VARIABLELIST>
  1242. </REFSECT2>
  1243. <REFSECT2 ID="R2-SPI-SPIMODIFYTUPLE-2">
  1244. <REFSECT2INFO>
  1245. <DATE>1997-12-24</DATE>
  1246. </REFSECT2INFO>
  1247. <TITLE>Outputs
  1248. </TITLE>
  1249. <VARIABLELIST>
  1250. <VARLISTENTRY>
  1251. <TERM>
  1252. HeapTuple
  1253. </TERM>
  1254. <LISTITEM>
  1255. <PARA>
  1256. New tuple with modifications
  1257. <SimpleList>
  1258. <Member>
  1259.  <ReturnValue>non-NULL</ReturnValue>
  1260.  if <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1261.  is not NULL and the modify was successful
  1262. </Member>
  1263. <Member>
  1264.    <ReturnValue>NULL</ReturnValue>
  1265.  only if <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1266.  is NULL
  1267. </Member>
  1268. </SimpleList>
  1269. </para>
  1270. </LISTITEM>
  1271. </VARLISTENTRY>
  1272. <VARLISTENTRY>
  1273. <TERM>
  1274. SPI_result
  1275. </TERM>
  1276. <LISTITEM>
  1277. <PARA>
  1278. <SimpleList>
  1279. <Member>
  1280.    <ReturnValue>SPI_ERROR_ARGUMENT</ReturnValue> if rel is NULL or tuple is NULL or natts &le; 0 or
  1281.    attnum is NULL or Values is NULL.
  1282. </Member>
  1283. <Member>
  1284.    <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue> if there is an invalid 
  1285.    attribute number in attnum (attnum &le; 0 or &gt; number of
  1286.    attributes in tuple)
  1287. </Member>
  1288. </SimpleList>
  1289. </para>
  1290. </LISTITEM>
  1291. </VARLISTENTRY>
  1292. </VARIABLELIST>
  1293. </REFSECT2>
  1294. </REFSYNOPSISDIV>
  1295. <REFSECT1 ID="R1-SPI-SPIMODIFYTUPLE-1">
  1296. <REFSECT1INFO>
  1297. <DATE>1997-12-24</DATE>
  1298. </REFSECT1INFO>
  1299. <TITLE>Description
  1300. </TITLE>
  1301. <PARA>
  1302. <FUNCTION>SPI_modifytuple</FUNCTION> 
  1303. Modifies a tuple in upper Executor context. See the section on Memory Management.
  1304. </PARA>
  1305. </REFSECT1>
  1306. <REFSECT1 ID="R1-SPI-SPIMODIFYTUPLE-2">
  1307. <TITLE>Usage
  1308. </TITLE>
  1309. <Para>
  1310. If successful, a pointer to the new tuple is returned. The new tuple is
  1311. allocated in upper Executor context (see Memory management). Passed tuple
  1312. is not changed.
  1313. </PARA>
  1314. </REFSECT1>
  1315. <!--
  1316. <REFSECT1 ID="R1-SPI-SPIMODIFYTUPLE-3">
  1317. <TITLE>Algorithm
  1318. </TITLE>
  1319. <PARA>
  1320. </PARA>
  1321. </REFSECT1>
  1322. -->
  1323. <!--
  1324. <REFSECT1 ID="R1-SPI-SPIMODIFYTUPLE-4">
  1325. <TITLE>Structures
  1326. </TITLE>
  1327. <PARA>None
  1328. </PARA>
  1329. </REFSECT1>
  1330. -->
  1331. </REFENTRY>
  1332. <!-- *********************************************** -->
  1333. <!-- *********************************************** -->
  1334. <!-- *********************************************** -->
  1335. <REFENTRY ID="SPI-SPIFNUMBER">
  1336. <REFMETA>
  1337. <REFENTRYTITLE>SPI_fnumber</REFENTRYTITLE>
  1338. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1339. </REFMETA>
  1340. <REFNAMEDIV>
  1341. <REFNAME>SPI_fnumber
  1342. </REFNAME>
  1343. <REFPURPOSE>
  1344. Finds the attribute number for specified attribute
  1345. </REFPURPOSE>
  1346. <INDEXTERM ID="IX-SPI-SPIFNUMBER-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1347. <INDEXTERM ID="IX-SPI-SPIFNUMBER-2"><PRIMARY>SPI_fnumber</PRIMARY></INDEXTERM>
  1348. </REFNAMEDIV>
  1349. <REFSYNOPSISDIV>
  1350. <REFSYNOPSISDIVINFO>
  1351. <DATE>1997-12-24</DATE>
  1352. </REFSYNOPSISDIVINFO>
  1353. <SYNOPSIS>
  1354. SPI_fnumber(<REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fname</REPLACEABLE>)
  1355. </SYNOPSIS>
  1356. <REFSECT2 ID="R2-SPI-SPIFNUMBER-1">
  1357. <REFSECT2INFO>
  1358. <DATE>1997-12-24</DATE>
  1359. </REFSECT2INFO>
  1360. <TITLE>Inputs
  1361. </TITLE>
  1362. <VARIABLELIST>
  1363. <VARLISTENTRY>
  1364. <TERM>
  1365. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1366. </TERM>
  1367. <LISTITEM>
  1368. <PARA>
  1369. Input tuple description
  1370. </PARA>
  1371. </LISTITEM>
  1372. </VARLISTENTRY>
  1373. <VARLISTENTRY>
  1374. <TERM>
  1375. char * <REPLACEABLE CLASS="PARAMETER">fname</REPLACEABLE>
  1376. </TERM>
  1377. <LISTITEM>
  1378. <PARA>
  1379. Field name
  1380. </PARA>
  1381. </LISTITEM>
  1382. </VARLISTENTRY>
  1383. </VARIABLELIST>
  1384. </REFSECT2>
  1385. <REFSECT2 ID="R2-SPI-SPIFNUMBER-2">
  1386. <REFSECT2INFO>
  1387. <DATE>1997-12-24</DATE>
  1388. </REFSECT2INFO>
  1389. <TITLE>Outputs
  1390. </TITLE>
  1391. <VARIABLELIST>
  1392. <VARLISTENTRY>
  1393. <TERM>
  1394. int
  1395. </TERM>
  1396. <LISTITEM>
  1397. <PARA>
  1398. Attribute number
  1399. <SimpleList>
  1400. <Member>
  1401. Valid one-based index number of attribute
  1402. </Member>
  1403. <Member>
  1404. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue> if the named attribute is not found
  1405. </Member>
  1406. </SimpleList>
  1407. </para>
  1408. </LISTITEM>
  1409. </VARLISTENTRY>
  1410. </VARIABLELIST>
  1411. </REFSECT2>
  1412. </REFSYNOPSISDIV>
  1413. <REFSECT1 ID="R1-SPI-SPIFNUMBER-1">
  1414. <REFSECT1INFO>
  1415. <DATE>1997-12-24</DATE>
  1416. </REFSECT1INFO>
  1417. <TITLE>Description
  1418. </TITLE>
  1419. <PARA>
  1420. <FUNCTION>SPI_fnumber</FUNCTION> 
  1421.    returns the attribute number for the attribute with name in fname.
  1422. </PARA>
  1423. </REFSECT1>
  1424. <REFSECT1 ID="R1-SPI-SPIFNUMBER-2">
  1425. <TITLE>Usage
  1426. </TITLE>
  1427. <Para>
  1428. Attribute numbers are 1 based.
  1429. </PARA>
  1430. </REFSECT1>
  1431. <!--
  1432. <REFSECT1 ID="R1-SPI-SPIFNUMBER-3">
  1433. <TITLE>Algorithm
  1434. </TITLE>
  1435. <PARA>
  1436. </PARA>
  1437. </REFSECT1>
  1438. -->
  1439. <!--
  1440. <REFSECT1 ID="R1-SPI-SPIFNUMBER-4">
  1441. <TITLE>Structures
  1442. </TITLE>
  1443. <PARA>None
  1444. </PARA>
  1445. </REFSECT1>
  1446. -->
  1447. </REFENTRY>
  1448. <!-- *********************************************** -->
  1449. <!-- *********************************************** -->
  1450. <!-- *********************************************** -->
  1451. <REFENTRY ID="SPI-SPIFNAME">
  1452. <REFMETA>
  1453. <REFENTRYTITLE>SPI_fname</REFENTRYTITLE>
  1454. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1455. </REFMETA>
  1456. <REFNAMEDIV>
  1457. <REFNAME>SPI_fname
  1458. </REFNAME>
  1459. <REFPURPOSE>
  1460. Finds the attribute name for the specified attribute
  1461. </REFPURPOSE>
  1462. <INDEXTERM ID="IX-SPI-SPIFNAME-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1463. <INDEXTERM ID="IX-SPI-SPIFNAME-2"><PRIMARY>SPI_fname</PRIMARY></INDEXTERM>
  1464. </REFNAMEDIV>
  1465. <REFSYNOPSISDIV>
  1466. <REFSYNOPSISDIVINFO>
  1467. <DATE>1997-12-24</DATE>
  1468. </REFSYNOPSISDIVINFO>
  1469. <SYNOPSIS>
  1470. SPI_fname(<REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fname</REPLACEABLE>)
  1471. </SYNOPSIS>
  1472. <REFSECT2 ID="R2-SPI-SPIFNAME-1">
  1473. <REFSECT2INFO>
  1474. <DATE>1997-12-24</DATE>
  1475. </REFSECT2INFO>
  1476. <TITLE>Inputs
  1477. </TITLE>
  1478. <VARIABLELIST>
  1479. <VARLISTENTRY>
  1480. <TERM>
  1481. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1482. </TERM>
  1483. <LISTITEM>
  1484. <PARA>
  1485. Input tuple description
  1486. </PARA>
  1487. </LISTITEM>
  1488. </VARLISTENTRY>
  1489. <VARLISTENTRY>
  1490. <TERM>
  1491. char * <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>
  1492. </TERM>
  1493. <LISTITEM>
  1494. <PARA>
  1495. Attribute number
  1496. </PARA>
  1497. </LISTITEM>
  1498. </VARLISTENTRY>
  1499. </VARIABLELIST>
  1500. </REFSECT2>
  1501. <REFSECT2 ID="R2-SPI-SPIFNAME-2">
  1502. <REFSECT2INFO>
  1503. <DATE>1997-12-24</DATE>
  1504. </REFSECT2INFO>
  1505. <TITLE>Outputs
  1506. </TITLE>
  1507. <VARIABLELIST>
  1508. <VARLISTENTRY>
  1509. <TERM>
  1510. char *
  1511. </TERM>
  1512. <LISTITEM>
  1513. <PARA>
  1514. Attribute name
  1515. <SimpleList>
  1516. <Member>
  1517. NULL if fnumber is out of range
  1518. </Member>
  1519. <Member>
  1520. SPI_result set to
  1521. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue> on error
  1522. </Member>
  1523. </SimpleList>
  1524. </para>
  1525. </LISTITEM>
  1526. </VARLISTENTRY>
  1527. </VARIABLELIST>
  1528. </REFSECT2>
  1529. </REFSYNOPSISDIV>
  1530. <REFSECT1 ID="R1-SPI-SPIFNAME-1">
  1531. <REFSECT1INFO>
  1532. <DATE>1997-12-24</DATE>
  1533. </REFSECT1INFO>
  1534. <TITLE>Description
  1535. </TITLE>
  1536. <PARA>
  1537. <FUNCTION>SPI_fname</FUNCTION> 
  1538.    returns the attribute name for the specified attribute.
  1539. </PARA>
  1540. </REFSECT1>
  1541. <REFSECT1 ID="R1-SPI-SPIFNAME-2">
  1542. <TITLE>Usage
  1543. </TITLE>
  1544. <Para>
  1545. Attribute numbers are 1 based.
  1546. </PARA>
  1547. </REFSECT1>
  1548. <REFSECT1 ID="R1-SPI-SPIFNAME-3">
  1549. <TITLE>Algorithm
  1550. </TITLE>
  1551. <PARA>
  1552. Returns a newly-allocated copy of the attribute name.
  1553. </PARA>
  1554. </REFSECT1>
  1555. <!--
  1556. <REFSECT1 ID="R1-SPI-SPIFNAME-4">
  1557. <TITLE>Structures
  1558. </TITLE>
  1559. <PARA>None
  1560. </PARA>
  1561. </REFSECT1>
  1562. -->
  1563. </REFENTRY>
  1564. <!-- *********************************************** -->
  1565. <!-- *********************************************** -->
  1566. <!-- *********************************************** -->
  1567. <REFENTRY ID="SPI-SPIGETVALUE">
  1568. <REFMETA>
  1569. <REFENTRYTITLE>SPI_getvalue</REFENTRYTITLE>
  1570. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1571. </REFMETA>
  1572. <REFNAMEDIV>
  1573. <REFNAME>SPI_getvalue
  1574. </REFNAME>
  1575. <REFPURPOSE>
  1576. Returns the string value of the specified attribute
  1577. </REFPURPOSE>
  1578. <INDEXTERM ID="IX-SPI-SPIGETVALUE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1579. <INDEXTERM ID="IX-SPI-SPIGETVALUE-2"><PRIMARY>SPI_getvalue</PRIMARY></INDEXTERM>
  1580. </REFNAMEDIV>
  1581. <REFSYNOPSISDIV>
  1582. <REFSYNOPSISDIVINFO>
  1583. <DATE>1997-12-24</DATE>
  1584. </REFSYNOPSISDIVINFO>
  1585. <SYNOPSIS>
  1586. SPI_getvalue(<REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>)
  1587. </SYNOPSIS>
  1588. <REFSECT2 ID="R2-SPI-SPIGETVALUE-1">
  1589. <REFSECT2INFO>
  1590. <DATE>1997-12-24</DATE>
  1591. </REFSECT2INFO>
  1592. <TITLE>Inputs
  1593. </TITLE>
  1594. <VARIABLELIST>
  1595. <VARLISTENTRY>
  1596. <TERM>
  1597. HeapTuple <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1598. </TERM>
  1599. <LISTITEM>
  1600. <PARA>
  1601. Input tuple to be examined
  1602. </PARA>
  1603. </LISTITEM>
  1604. </VARLISTENTRY>
  1605. <VARLISTENTRY>
  1606. <TERM>
  1607. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1608. </TERM>
  1609. <LISTITEM>
  1610. <PARA>
  1611. Input tuple description
  1612. </PARA>
  1613. </LISTITEM>
  1614. </VARLISTENTRY>
  1615. <VARLISTENTRY>
  1616. <TERM>
  1617. int <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>
  1618. </TERM>
  1619. <LISTITEM>
  1620. <PARA>
  1621. Attribute number
  1622. </PARA>
  1623. </LISTITEM>
  1624. </VARLISTENTRY>
  1625. </VARIABLELIST>
  1626. </REFSECT2>
  1627. <REFSECT2 ID="R2-SPI-SPIGETVALUE-2">
  1628. <REFSECT2INFO>
  1629. <DATE>1997-12-24</DATE>
  1630. </REFSECT2INFO>
  1631. <TITLE>Outputs
  1632. </TITLE>
  1633. <VARIABLELIST>
  1634. <VARLISTENTRY>
  1635. <TERM>
  1636. char *
  1637. </TERM>
  1638. <LISTITEM>
  1639. <PARA>
  1640. Attribute value or NULL if
  1641. <SimpleList>
  1642. <Member>
  1643. attribute is NULL
  1644. </Member>
  1645. <Member>
  1646. fnumber is out of range
  1647. (SPI_result set to
  1648. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue>)
  1649. </Member>
  1650. <Member>
  1651. no output function available
  1652. (SPI_result set to
  1653. <ReturnValue>SPI_ERROR_NOOUTFUNC</ReturnValue>)
  1654. </Member>
  1655. </SimpleList>
  1656. </para>
  1657. </LISTITEM>
  1658. </VARLISTENTRY>
  1659. </VARIABLELIST>
  1660. </REFSECT2>
  1661. </REFSYNOPSISDIV>
  1662. <REFSECT1 ID="R1-SPI-SPIGETVALUE-1">
  1663. <REFSECT1INFO>
  1664. <DATE>1997-12-24</DATE>
  1665. </REFSECT1INFO>
  1666. <TITLE>Description
  1667. </TITLE>
  1668. <PARA>
  1669. <FUNCTION>SPI_getvalue</FUNCTION> 
  1670.    returns an external (string) representation of the value of the specified attribute.
  1671. </PARA>
  1672. </REFSECT1>
  1673. <REFSECT1 ID="R1-SPI-SPIGETVALUE-2">
  1674. <TITLE>Usage
  1675. </TITLE>
  1676. <Para>
  1677. Attribute numbers are 1 based.
  1678. </PARA>
  1679. </REFSECT1>
  1680. <REFSECT1 ID="R1-SPI-SPIGETVALUE-3">
  1681. <TITLE>Algorithm
  1682. </TITLE>
  1683. <PARA>
  1684. Allocates memory as required by the value.
  1685. </PARA>
  1686. </REFSECT1>
  1687. <!--
  1688. <REFSECT1 ID="R1-SPI-SPIGETVALUE-4">
  1689. <TITLE>Structures
  1690. </TITLE>
  1691. <PARA>None
  1692. </PARA>
  1693. </REFSECT1>
  1694. -->
  1695. </REFENTRY>
  1696. <!-- *********************************************** -->
  1697. <!-- *********************************************** -->
  1698. <!-- *********************************************** -->
  1699. <REFENTRY ID="SPI-SPIGETBINVAL">
  1700. <REFMETA>
  1701. <REFENTRYTITLE>SPI_getbinval</REFENTRYTITLE>
  1702. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1703. </REFMETA>
  1704. <REFNAMEDIV>
  1705. <REFNAME>SPI_getbinval
  1706. </REFNAME>
  1707. <REFPURPOSE>
  1708. Returns the binary value of the specified attribute
  1709. </REFPURPOSE>
  1710. <INDEXTERM ID="IX-SPI-SPIGETBINVAL-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1711. <INDEXTERM ID="IX-SPI-SPIGETBINVAL-2"><PRIMARY>SPI_getbinval</PRIMARY></INDEXTERM>
  1712. </REFNAMEDIV>
  1713. <REFSYNOPSISDIV>
  1714. <REFSYNOPSISDIVINFO>
  1715. <DATE>1997-12-24</DATE>
  1716. </REFSYNOPSISDIVINFO>
  1717. <SYNOPSIS>
  1718. SPI_getbinval(<REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">isnull</REPLACEABLE>)
  1719. </SYNOPSIS>
  1720. <REFSECT2 ID="R2-SPI-SPIGETBINVAL-1">
  1721. <REFSECT2INFO>
  1722. <DATE>1997-12-24</DATE>
  1723. </REFSECT2INFO>
  1724. <TITLE>Inputs
  1725. </TITLE>
  1726. <VARIABLELIST>
  1727. <VARLISTENTRY>
  1728. <TERM>
  1729. HeapTuple <REPLACEABLE CLASS="PARAMETER">tuple</REPLACEABLE>
  1730. </TERM>
  1731. <LISTITEM>
  1732. <PARA>
  1733. Input tuple to be examined
  1734. </PARA>
  1735. </LISTITEM>
  1736. </VARLISTENTRY>
  1737. <VARLISTENTRY>
  1738. <TERM>
  1739. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1740. </TERM>
  1741. <LISTITEM>
  1742. <PARA>
  1743. Input tuple description
  1744. </PARA>
  1745. </LISTITEM>
  1746. </VARLISTENTRY>
  1747. <VARLISTENTRY>
  1748. <TERM>
  1749. int <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>
  1750. </TERM>
  1751. <LISTITEM>
  1752. <PARA>
  1753. Attribute number
  1754. </PARA>
  1755. </LISTITEM>
  1756. </VARLISTENTRY>
  1757. </VARIABLELIST>
  1758. </REFSECT2>
  1759. <REFSECT2 ID="R2-SPI-SPIGETBINVAL-2">
  1760. <REFSECT2INFO>
  1761. <DATE>1997-12-24</DATE>
  1762. </REFSECT2INFO>
  1763. <TITLE>Outputs
  1764. </TITLE>
  1765. <VARIABLELIST>
  1766. <VARLISTENTRY>
  1767. <TERM>
  1768. Datum
  1769. </TERM>
  1770. <LISTITEM>
  1771. <PARA>
  1772. Attribute binary value
  1773. </PARA>
  1774. </LISTITEM>
  1775. </VARLISTENTRY>
  1776. <VARLISTENTRY>
  1777. <TERM>
  1778. bool * <REPLACEABLE CLASS="PARAMETER">isnull</REPLACEABLE>
  1779. </TERM>
  1780. <LISTITEM>
  1781. <PARA>
  1782. flag for null value in attribute
  1783. </PARA>
  1784. </LISTITEM>
  1785. </VARLISTENTRY>
  1786. <VARLISTENTRY>
  1787. <TERM>
  1788. SPI_result
  1789. </TERM>
  1790. <LISTITEM>
  1791. <PARA>
  1792. <SimpleList>
  1793. <Member>
  1794. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue>
  1795. </Member>
  1796. </SimpleList>
  1797. </PARA>
  1798. </LISTITEM>
  1799. </VARLISTENTRY>
  1800. </VARIABLELIST>
  1801. </REFSECT2>
  1802. </REFSYNOPSISDIV>
  1803. <REFSECT1 ID="R1-SPI-SPIGETBINVAL-1">
  1804. <REFSECT1INFO>
  1805. <DATE>1997-12-24</DATE>
  1806. </REFSECT1INFO>
  1807. <TITLE>Description
  1808. </TITLE>
  1809. <PARA>
  1810. <FUNCTION>SPI_getbinval</FUNCTION> 
  1811.    returns the binary value of the specified attribute.
  1812. </PARA>
  1813. </REFSECT1>
  1814. <REFSECT1 ID="R1-SPI-SPIGETBINVAL-2">
  1815. <TITLE>Usage
  1816. </TITLE>
  1817. <Para>
  1818. Attribute numbers are 1 based.
  1819. </PARA>
  1820. </REFSECT1>
  1821. <REFSECT1 ID="R1-SPI-SPIGETBINVAL-3">
  1822. <TITLE>Algorithm
  1823. </TITLE>
  1824. <PARA>
  1825. Does not allocate new space for the binary value.
  1826. </PARA>
  1827. </REFSECT1>
  1828. <!--
  1829. <REFSECT1 ID="R1-SPI-SPIGETBINVAL-4">
  1830. <TITLE>Structures
  1831. </TITLE>
  1832. <PARA>None
  1833. </PARA>
  1834. </REFSECT1>
  1835. -->
  1836. </REFENTRY>
  1837. <!-- *********************************************** -->
  1838. <!-- *********************************************** -->
  1839. <!-- *********************************************** -->
  1840. <REFENTRY ID="SPI-SPIGETTYPE">
  1841. <REFMETA>
  1842. <REFENTRYTITLE>SPI_gettype</REFENTRYTITLE>
  1843. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1844. </REFMETA>
  1845. <REFNAMEDIV>
  1846. <REFNAME>SPI_gettype
  1847. </REFNAME>
  1848. <REFPURPOSE>
  1849. Returns the type name of the specified attribute
  1850. </REFPURPOSE>
  1851. <INDEXTERM ID="IX-SPI-SPIGETTYPE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1852. <INDEXTERM ID="IX-SPI-SPIGETTYPE-2"><PRIMARY>SPI_gettype</PRIMARY></INDEXTERM>
  1853. </REFNAMEDIV>
  1854. <REFSYNOPSISDIV>
  1855. <REFSYNOPSISDIVINFO>
  1856. <DATE>1997-12-24</DATE>
  1857. </REFSYNOPSISDIVINFO>
  1858. <SYNOPSIS>
  1859. SPI_gettype(<REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>)
  1860. </SYNOPSIS>
  1861. <REFSECT2 ID="R2-SPI-SPIGETTYPE-1">
  1862. <REFSECT2INFO>
  1863. <DATE>1997-12-24</DATE>
  1864. </REFSECT2INFO>
  1865. <TITLE>Inputs
  1866. </TITLE>
  1867. <VARIABLELIST>
  1868. <VARLISTENTRY>
  1869. <TERM>
  1870. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1871. </TERM>
  1872. <LISTITEM>
  1873. <PARA>
  1874. Input tuple description
  1875. </PARA>
  1876. </LISTITEM>
  1877. </VARLISTENTRY>
  1878. <VARLISTENTRY>
  1879. <TERM>
  1880. int <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>
  1881. </TERM>
  1882. <LISTITEM>
  1883. <PARA>
  1884. Attribute number
  1885. </PARA>
  1886. </LISTITEM>
  1887. </VARLISTENTRY>
  1888. </VARIABLELIST>
  1889. </REFSECT2>
  1890. <REFSECT2 ID="R2-SPI-SPIGETTYPE-2">
  1891. <REFSECT2INFO>
  1892. <DATE>1997-12-24</DATE>
  1893. </REFSECT2INFO>
  1894. <TITLE>Outputs
  1895. </TITLE>
  1896. <VARIABLELIST>
  1897. <VARLISTENTRY>
  1898. <TERM>
  1899. char *
  1900. </TERM>
  1901. <LISTITEM>
  1902. <PARA>
  1903. The type name for the specified attribute number
  1904. </PARA>
  1905. </LISTITEM>
  1906. </VARLISTENTRY>
  1907. <VARLISTENTRY>
  1908. <TERM>
  1909. SPI_result
  1910. </TERM>
  1911. <LISTITEM>
  1912. <PARA>
  1913. <SimpleList>
  1914. <Member>
  1915. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue>
  1916. </Member>
  1917. </SimpleList>
  1918. </PARA>
  1919. </LISTITEM>
  1920. </VARLISTENTRY>
  1921. </VARIABLELIST>
  1922. </REFSECT2>
  1923. </REFSYNOPSISDIV>
  1924. <REFSECT1 ID="R1-SPI-SPIGETTYPE-1">
  1925. <REFSECT1INFO>
  1926. <DATE>1997-12-24</DATE>
  1927. </REFSECT1INFO>
  1928. <TITLE>Description
  1929. </TITLE>
  1930. <PARA>
  1931. <FUNCTION>SPI_gettype</FUNCTION> 
  1932.    returns a copy of the type name for the specified attribute.
  1933. </PARA>
  1934. </REFSECT1>
  1935. <REFSECT1 ID="R1-SPI-SPIGETTYPE-2">
  1936. <TITLE>Usage
  1937. </TITLE>
  1938. <Para>
  1939. Attribute numbers are 1 based.
  1940. </PARA>
  1941. </REFSECT1>
  1942. <REFSECT1 ID="R1-SPI-SPIGETTYPE-3">
  1943. <TITLE>Algorithm
  1944. </TITLE>
  1945. <PARA>
  1946. Does not allocate new space for the binary value.
  1947. </PARA>
  1948. </REFSECT1>
  1949. <!--
  1950. <REFSECT1 ID="R1-SPI-SPIGETTYPE-4">
  1951. <TITLE>Structures
  1952. </TITLE>
  1953. <PARA>None
  1954. </PARA>
  1955. </REFSECT1>
  1956. -->
  1957. </REFENTRY>
  1958. <!-- *********************************************** -->
  1959. <!-- *********************************************** -->
  1960. <!-- *********************************************** -->
  1961. <REFENTRY ID="SPI-SPIGETTYPEID">
  1962. <REFMETA>
  1963. <REFENTRYTITLE>SPI_gettypeid</REFENTRYTITLE>
  1964. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  1965. </REFMETA>
  1966. <REFNAMEDIV>
  1967. <REFNAME>SPI_gettypeid
  1968. </REFNAME>
  1969. <REFPURPOSE>
  1970. Returns the type <Acronym>OID</Acronym> of the specified attribute
  1971. </REFPURPOSE>
  1972. <INDEXTERM ID="IX-SPI-SPIGETTYPEID-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  1973. <INDEXTERM ID="IX-SPI-SPIGETTYPEID-2"><PRIMARY>SPI_gettypeid</PRIMARY></INDEXTERM>
  1974. </REFNAMEDIV>
  1975. <REFSYNOPSISDIV>
  1976. <REFSYNOPSISDIVINFO>
  1977. <DATE>1997-12-24</DATE>
  1978. </REFSYNOPSISDIVINFO>
  1979. <SYNOPSIS>
  1980. SPI_gettypeid(<REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>)
  1981. </SYNOPSIS>
  1982. <REFSECT2 ID="R2-SPI-SPIGETTYPEID-1">
  1983. <REFSECT2INFO>
  1984. <DATE>1997-12-24</DATE>
  1985. </REFSECT2INFO>
  1986. <TITLE>Inputs
  1987. </TITLE>
  1988. <VARIABLELIST>
  1989. <VARLISTENTRY>
  1990. <TERM>
  1991. TupleDesc <REPLACEABLE CLASS="PARAMETER">tupdesc</REPLACEABLE>
  1992. </TERM>
  1993. <LISTITEM>
  1994. <PARA>
  1995. Input tuple description
  1996. </PARA>
  1997. </LISTITEM>
  1998. </VARLISTENTRY>
  1999. <VARLISTENTRY>
  2000. <TERM>
  2001. int <REPLACEABLE CLASS="PARAMETER">fnumber</REPLACEABLE>
  2002. </TERM>
  2003. <LISTITEM>
  2004. <PARA>
  2005. Attribute number
  2006. </PARA>
  2007. </LISTITEM>
  2008. </VARLISTENTRY>
  2009. </VARIABLELIST>
  2010. </REFSECT2>
  2011. <REFSECT2 ID="R2-SPI-SPIGETTYPEID-2">
  2012. <REFSECT2INFO>
  2013. <DATE>1997-12-24</DATE>
  2014. </REFSECT2INFO>
  2015. <TITLE>Outputs
  2016. </TITLE>
  2017. <VARIABLELIST>
  2018. <VARLISTENTRY>
  2019. <TERM>
  2020. <Acronym>OID</Acronym>
  2021. </TERM>
  2022. <LISTITEM>
  2023. <PARA>
  2024. The type <Acronym>OID</Acronym> for the specified attribute number
  2025. </PARA>
  2026. </LISTITEM>
  2027. </VARLISTENTRY>
  2028. <VARLISTENTRY>
  2029. <TERM>
  2030. SPI_result
  2031. </TERM>
  2032. <LISTITEM>
  2033. <PARA>
  2034. <SimpleList>
  2035. <Member>
  2036. <ReturnValue>SPI_ERROR_NOATTRIBUTE</ReturnValue>
  2037. </Member>
  2038. </SimpleList>
  2039. </PARA>
  2040. </LISTITEM>
  2041. </VARLISTENTRY>
  2042. </VARIABLELIST>
  2043. </REFSECT2>
  2044. </REFSYNOPSISDIV>
  2045. <REFSECT1 ID="R1-SPI-SPIGETTYPEID-1">
  2046. <REFSECT1INFO>
  2047. <DATE>1997-12-24</DATE>
  2048. </REFSECT1INFO>
  2049. <TITLE>Description
  2050. </TITLE>
  2051. <PARA>
  2052. <FUNCTION>SPI_gettypeid</FUNCTION> 
  2053.    returns the type <Acronym>OID</Acronym> for the specified attribute.
  2054. </PARA>
  2055. </REFSECT1>
  2056. <REFSECT1 ID="R1-SPI-SPIGETTYPEID-2">
  2057. <TITLE>Usage
  2058. </TITLE>
  2059. <Para>
  2060. Attribute numbers are 1 based.
  2061. </PARA>
  2062. </REFSECT1>
  2063. <REFSECT1 ID="R1-SPI-SPIGETTYPEID-3">
  2064. <TITLE>Algorithm
  2065. </TITLE>
  2066. <PARA>
  2067. TBD
  2068. </PARA>
  2069. </REFSECT1>
  2070. <!--
  2071. <REFSECT1 ID="R1-SPI-SPIGETTYPEID-4">
  2072. <TITLE>Structures
  2073. </TITLE>
  2074. <PARA>None
  2075. </PARA>
  2076. </REFSECT1>
  2077. -->
  2078. </REFENTRY>
  2079. <!-- *********************************************** -->
  2080. <!-- *********************************************** -->
  2081. <!-- *********************************************** -->
  2082. <REFENTRY ID="SPI-SPIGETRELNAME">
  2083. <REFMETA>
  2084. <REFENTRYTITLE>SPI_getrelname</REFENTRYTITLE>
  2085. <REFMISCINFO>SPI - Tuple Information</REFMISCINFO>
  2086. </REFMETA>
  2087. <REFNAMEDIV>
  2088. <REFNAME>SPI_getrelname
  2089. </REFNAME>
  2090. <REFPURPOSE>
  2091. Returns the name of the specified relation
  2092. </REFPURPOSE>
  2093. <INDEXTERM ID="IX-SPI-SPIGETRELNAME-1"><PRIMARY>SPI</PRIMARY><SECONDARY>decoding tuples</SECONDARY></INDEXTERM>
  2094. <INDEXTERM ID="IX-SPI-SPIGETRELNAME-2"><PRIMARY>SPI_getrelname</PRIMARY></INDEXTERM>
  2095. </REFNAMEDIV>
  2096. <REFSYNOPSISDIV>
  2097. <REFSYNOPSISDIVINFO>
  2098. <DATE>1997-12-24</DATE>
  2099. </REFSYNOPSISDIVINFO>
  2100. <SYNOPSIS>
  2101. SPI_getrelname(<REPLACEABLE CLASS="PARAMETER">rel</REPLACEABLE>)
  2102. </SYNOPSIS>
  2103. <REFSECT2 ID="R2-SPI-SPIGETRELNAME-1">
  2104. <REFSECT2INFO>
  2105. <DATE>1997-12-24</DATE>
  2106. </REFSECT2INFO>
  2107. <TITLE>Inputs
  2108. </TITLE>
  2109. <VARIABLELIST>
  2110. <VARLISTENTRY>
  2111. <TERM>
  2112. Relation <REPLACEABLE CLASS="PARAMETER">rel</REPLACEABLE>
  2113. </TERM>
  2114. <LISTITEM>
  2115. <PARA>
  2116. Input relation
  2117. </PARA>
  2118. </LISTITEM>
  2119. </VARLISTENTRY>
  2120. </VARIABLELIST>
  2121. </REFSECT2>
  2122. <REFSECT2 ID="R2-SPI-SPIGETRELNAME-2">
  2123. <REFSECT2INFO>
  2124. <DATE>1997-12-24</DATE>
  2125. </REFSECT2INFO>
  2126. <TITLE>Outputs
  2127. </TITLE>
  2128. <VARIABLELIST>
  2129. <VARLISTENTRY>
  2130. <TERM>
  2131. char *
  2132. </TERM>
  2133. <LISTITEM>
  2134. <PARA>
  2135. The name of the specified relation
  2136. </PARA>
  2137. </LISTITEM>
  2138. </VARLISTENTRY>
  2139. </VARIABLELIST>
  2140. </REFSECT2>
  2141. </REFSYNOPSISDIV>
  2142. <REFSECT1 ID="R1-SPI-SPIGETRELNAME-1">
  2143. <REFSECT1INFO>
  2144. <DATE>1997-12-24</DATE>
  2145. </REFSECT1INFO>
  2146. <TITLE>Description
  2147. </TITLE>
  2148. <PARA>
  2149. <FUNCTION>SPI_getrelname</FUNCTION> 
  2150.    returns the name of the specified relation.
  2151. </PARA>
  2152. </REFSECT1>
  2153. <REFSECT1 ID="R1-SPI-SPIGETRELNAME-2">
  2154. <TITLE>Usage
  2155. </TITLE>
  2156. <Para>
  2157. TBD
  2158. </PARA>
  2159. </REFSECT1>
  2160. <REFSECT1 ID="R1-SPI-SPIGETRELNAME-3">
  2161. <TITLE>Algorithm
  2162. </TITLE>
  2163. <PARA>
  2164. Copies the relation name into new storage.
  2165. </PARA>
  2166. </REFSECT1>
  2167. <!--
  2168. <REFSECT1 ID="R1-SPI-SPIGETRELNAME-4">
  2169. <TITLE>Structures
  2170. </TITLE>
  2171. <PARA>None
  2172. </PARA>
  2173. </REFSECT1>
  2174. -->
  2175. </REFENTRY>
  2176. <!-- *********************************************** -->
  2177. <!-- *********************************************** -->
  2178. <!-- *********************************************** -->
  2179. <REFENTRY ID="SPI-SPIPALLOC">
  2180. <REFMETA>
  2181. <REFENTRYTITLE>SPI_palloc</REFENTRYTITLE>
  2182. <REFMISCINFO>SPI - Memory Management</REFMISCINFO>
  2183. </REFMETA>
  2184. <REFNAMEDIV>
  2185. <REFNAME>SPI_palloc
  2186. </REFNAME>
  2187. <REFPURPOSE>
  2188. Allocates memory in upper Executor context
  2189. </REFPURPOSE>
  2190. <INDEXTERM ID="IX-SPI-SPIPALLOC-1"><PRIMARY>SPI</PRIMARY><SECONDARY>allocating space</SECONDARY></INDEXTERM>
  2191. <INDEXTERM ID="IX-SPI-SPIPALLOC-2"><PRIMARY>SPI_palloc</PRIMARY></INDEXTERM>
  2192. </REFNAMEDIV>
  2193. <REFSYNOPSISDIV>
  2194. <REFSYNOPSISDIVINFO>
  2195. <DATE>1997-12-24</DATE>
  2196. </REFSYNOPSISDIVINFO>
  2197. <SYNOPSIS>
  2198. SPI_palloc(<REPLACEABLE CLASS="PARAMETER">size</REPLACEABLE>)
  2199. </SYNOPSIS>
  2200. <REFSECT2 ID="R2-SPI-SPIPALLOC-1">
  2201. <REFSECT2INFO>
  2202. <DATE>1997-12-24</DATE>
  2203. </REFSECT2INFO>
  2204. <TITLE>Inputs
  2205. </TITLE>
  2206. <VARIABLELIST>
  2207. <VARLISTENTRY>
  2208. <TERM>
  2209. Size <REPLACEABLE CLASS="PARAMETER">size</REPLACEABLE>
  2210. </TERM>
  2211. <LISTITEM>
  2212. <PARA>
  2213. Octet size of storage to allocate
  2214. </PARA>
  2215. </LISTITEM>
  2216. </VARLISTENTRY>
  2217. </VARIABLELIST>
  2218. </REFSECT2>
  2219. <REFSECT2 ID="R2-SPI-SPIPALLOC-2">
  2220. <REFSECT2INFO>
  2221. <DATE>1997-12-24</DATE>
  2222. </REFSECT2INFO>
  2223. <TITLE>Outputs
  2224. </TITLE>
  2225. <VARIABLELIST>
  2226. <VARLISTENTRY>
  2227. <TERM>
  2228. void *
  2229. </TERM>
  2230. <LISTITEM>
  2231. <PARA>
  2232. New storage space of specified size
  2233. </PARA>
  2234. </LISTITEM>
  2235. </VARLISTENTRY>
  2236. </VARIABLELIST>
  2237. </REFSECT2>
  2238. </REFSYNOPSISDIV>
  2239. <REFSECT1 ID="R1-SPI-SPIPALLOC-1">
  2240. <REFSECT1INFO>
  2241. <DATE>1997-12-24</DATE>
  2242. </REFSECT1INFO>
  2243. <TITLE>Description
  2244. </TITLE>
  2245. <PARA>
  2246. <FUNCTION>SPI_palloc</FUNCTION> 
  2247.    allocates memory in upper Executor context. See section on memory management.
  2248. </PARA>
  2249. </REFSECT1>
  2250. <REFSECT1 ID="R1-SPI-SPIPALLOC-2">
  2251. <TITLE>Usage
  2252. </TITLE>
  2253. <Para>
  2254. TBD
  2255. </PARA>
  2256. </REFSECT1>
  2257. <!--
  2258. <REFSECT1 ID="R1-SPI-SPIPALLOC-3">
  2259. <TITLE>Algorithm
  2260. </TITLE>
  2261. <PARA>
  2262. TBD
  2263. </PARA>
  2264. </REFSECT1>
  2265. -->
  2266. <!--
  2267. <REFSECT1 ID="R1-SPI-SPIPALLOC-4">
  2268. <TITLE>Structures
  2269. </TITLE>
  2270. <PARA>None
  2271. </PARA>
  2272. </REFSECT1>
  2273. -->
  2274. </REFENTRY>
  2275. <!-- *********************************************** -->
  2276. <!-- *********************************************** -->
  2277. <!-- *********************************************** -->
  2278. <REFENTRY ID="SPI-SPIREPALLOC">
  2279. <REFMETA>
  2280. <REFENTRYTITLE>SPI_repalloc</REFENTRYTITLE>
  2281. <REFMISCINFO>SPI - Memory Management</REFMISCINFO>
  2282. </REFMETA>
  2283. <REFNAMEDIV>
  2284. <REFNAME>SPI_repalloc
  2285. </REFNAME>
  2286. <REFPURPOSE>
  2287. Re-allocates memory in upper Executor context
  2288. </REFPURPOSE>
  2289. <INDEXTERM ID="IX-SPI-SPIREPALLOC-1"><PRIMARY>SPI</PRIMARY><SECONDARY>allocating space</SECONDARY></INDEXTERM>
  2290. <INDEXTERM ID="IX-SPI-SPIREPALLOC-2"><PRIMARY>SPI_repalloc</PRIMARY></INDEXTERM>
  2291. </REFNAMEDIV>
  2292. <REFSYNOPSISDIV>
  2293. <REFSYNOPSISDIVINFO>
  2294. <DATE>1997-12-24</DATE>
  2295. </REFSYNOPSISDIVINFO>
  2296. <SYNOPSIS>
  2297. SPI_repalloc(<REPLACEABLE CLASS="PARAMETER">pointer</REPLACEABLE>, <REPLACEABLE CLASS="PARAMETER">size</REPLACEABLE>)
  2298. </SYNOPSIS>
  2299. <REFSECT2 ID="R2-SPI-SPIREPALLOC-1">
  2300. <REFSECT2INFO>
  2301. <DATE>1997-12-24</DATE>
  2302. </REFSECT2INFO>
  2303. <TITLE>Inputs
  2304. </TITLE>
  2305. <VARIABLELIST>
  2306. <VARLISTENTRY>
  2307. <TERM>
  2308. void * <REPLACEABLE CLASS="PARAMETER">pointer</REPLACEABLE>
  2309. </TERM>
  2310. <LISTITEM>
  2311. <PARA>
  2312. Pointer to existing storage
  2313. </PARA>
  2314. </LISTITEM>
  2315. </VARLISTENTRY>
  2316. <VARLISTENTRY>
  2317. <TERM>
  2318. Size <REPLACEABLE CLASS="PARAMETER">size</REPLACEABLE>
  2319. </TERM>
  2320. <LISTITEM>
  2321. <PARA>
  2322. Octet size of storage to allocate
  2323. </PARA>
  2324. </LISTITEM>
  2325. </VARLISTENTRY>
  2326. </VARIABLELIST>
  2327. </REFSECT2>
  2328. <REFSECT2 ID="R2-SPI-SPIREPALLOC-2">
  2329. <REFSECT2INFO>
  2330. <DATE>1997-12-24</DATE>
  2331. </REFSECT2INFO>
  2332. <TITLE>Outputs
  2333. </TITLE>
  2334. <VARIABLELIST>
  2335. <VARLISTENTRY>
  2336. <TERM>
  2337. void *
  2338. </TERM>
  2339. <LISTITEM>
  2340. <PARA>
  2341. New storage space of specified size with contents copied from existing area
  2342. </PARA>
  2343. </LISTITEM>
  2344. </VARLISTENTRY>
  2345. </VARIABLELIST>
  2346. </REFSECT2>
  2347. </REFSYNOPSISDIV>
  2348. <REFSECT1 ID="R1-SPI-SPIREPALLOC-1">
  2349. <REFSECT1INFO>
  2350. <DATE>1997-12-24</DATE>
  2351. </REFSECT1INFO>
  2352. <TITLE>Description
  2353. </TITLE>
  2354. <PARA>
  2355. <FUNCTION>SPI_repalloc</FUNCTION> 
  2356.    re-allocates memory in upper Executor context. See section on memory management.
  2357. </PARA>
  2358. </REFSECT1>
  2359. <REFSECT1 ID="R1-SPI-SPIREPALLOC-2">
  2360. <TITLE>Usage
  2361. </TITLE>
  2362. <Para>
  2363. TBD
  2364. </PARA>
  2365. </REFSECT1>
  2366. <!--
  2367. <REFSECT1 ID="R1-SPI-SPIREPALLOC-3">
  2368. <TITLE>Algorithm
  2369. </TITLE>
  2370. <PARA>
  2371. TBD
  2372. </PARA>
  2373. </REFSECT1>
  2374. -->
  2375. <!--
  2376. <REFSECT1 ID="R1-SPI-SPIREPALLOC-4">
  2377. <TITLE>Structures
  2378. </TITLE>
  2379. <PARA>None
  2380. </PARA>
  2381. </REFSECT1>
  2382. -->
  2383. </REFENTRY>
  2384. <!-- *********************************************** -->
  2385. <!-- *********************************************** -->
  2386. <!-- *********************************************** -->
  2387. <REFENTRY ID="SPI-SPIPFREE">
  2388. <REFMETA>
  2389. <REFENTRYTITLE>SPI_pfree</REFENTRYTITLE>
  2390. <REFMISCINFO>SPI - Memory Management</REFMISCINFO>
  2391. </REFMETA>
  2392. <REFNAMEDIV>
  2393. <REFNAME>SPI_pfree
  2394. </REFNAME>
  2395. <REFPURPOSE>
  2396. Frees memory from upper Executor context
  2397. </REFPURPOSE>
  2398. <INDEXTERM ID="IX-SPI-SPIPFREE-1"><PRIMARY>SPI</PRIMARY><SECONDARY>allocating space</SECONDARY></INDEXTERM>
  2399. <INDEXTERM ID="IX-SPI-SPIPFREE-2"><PRIMARY>SPI_pfree</PRIMARY></INDEXTERM>
  2400. </REFNAMEDIV>
  2401. <REFSYNOPSISDIV>
  2402. <REFSYNOPSISDIVINFO>
  2403. <DATE>1997-12-24</DATE>
  2404. </REFSYNOPSISDIVINFO>
  2405. <SYNOPSIS>
  2406. SPI_pfree(<REPLACEABLE CLASS="PARAMETER">pointer</REPLACEABLE>)
  2407. </SYNOPSIS>
  2408. <REFSECT2 ID="R2-SPI-SPIPFREE-1">
  2409. <REFSECT2INFO>
  2410. <DATE>1997-12-24</DATE>
  2411. </REFSECT2INFO>
  2412. <TITLE>Inputs
  2413. </TITLE>
  2414. <VARIABLELIST>
  2415. <VARLISTENTRY>
  2416. <TERM>
  2417. void * <REPLACEABLE CLASS="PARAMETER">pointer</REPLACEABLE>
  2418. </TERM>
  2419. <LISTITEM>
  2420. <PARA>
  2421. Pointer to existing storage
  2422. </PARA>
  2423. </LISTITEM>
  2424. </VARLISTENTRY>
  2425. </VARIABLELIST>
  2426. </REFSECT2>
  2427. <REFSECT2 ID="R2-SPI-SPIPFREE-2">
  2428. <REFSECT2INFO>
  2429. <DATE>1997-12-24</DATE>
  2430. </REFSECT2INFO>
  2431. <TITLE>Outputs
  2432. </TITLE>
  2433. <VARIABLELIST>
  2434. <VARLISTENTRY>
  2435. <TERM>
  2436. None
  2437. </TERM>
  2438. <LISTITEM>
  2439. <PARA>
  2440. </PARA>
  2441. </LISTITEM>
  2442. </VARLISTENTRY>
  2443. </VARIABLELIST>
  2444. </REFSECT2>
  2445. </REFSYNOPSISDIV>
  2446. <REFSECT1 ID="R1-SPI-SPIPFREE-1">
  2447. <REFSECT1INFO>
  2448. <DATE>1997-12-24</DATE>
  2449. </REFSECT1INFO>
  2450. <TITLE>Description
  2451. </TITLE>
  2452. <PARA>
  2453. <FUNCTION>SPI_pfree</FUNCTION> 
  2454.    frees memory in upper Executor context. See section on memory management.
  2455. </PARA>
  2456. </REFSECT1>
  2457. <REFSECT1 ID="R1-SPI-SPIPFREE-2">
  2458. <TITLE>Usage
  2459. </TITLE>
  2460. <Para>
  2461. TBD
  2462. </PARA>
  2463. </REFSECT1>
  2464. <!--
  2465. <REFSECT1 ID="R1-SPI-SPIPFREE-3">
  2466. <TITLE>Algorithm
  2467. </TITLE>
  2468. <PARA>
  2469. TBD
  2470. </PARA>
  2471. </REFSECT1>
  2472. -->
  2473. <!--
  2474. <REFSECT1 ID="R1-SPI-SPIPFREE-4">
  2475. <TITLE>Structures
  2476. </TITLE>
  2477. <PARA>None
  2478. </PARA>
  2479. </REFSECT1>
  2480. -->
  2481. </REFENTRY>
  2482. </Sect1>
  2483. <Sect1>
  2484. <Title>Memory Management</Title>
  2485. <Para>
  2486.    Server allocates memory in memory contexts in such way that allocations
  2487. made in one context may be freed by context destruction without affecting
  2488. allocations made in other contexts. All allocations (via <Function>palloc</Function>, etc) are
  2489. made in the context which are chosen as current one. You'll get
  2490. unpredictable results if you'll try to free (or reallocate) memory allocated
  2491. not in current context.
  2492. </Para>
  2493. <Para>
  2494.    Creation and switching between memory contexts are subject of SPI manager
  2495. memory management.
  2496. </Para>
  2497. <Para>
  2498.    SPI procedures deal with two memory contexts: upper Executor memory
  2499. context and procedure memory context (if connected). 
  2500. </Para>
  2501. <Para>
  2502.    Before a procedure is connected to the SPI manager, current memory context
  2503. is upper Executor context so all allocation made by the procedure itself via
  2504. <Function>palloc</Function>/<Function>repalloc</Function> or by SPI utility functions before connecting to SPI are
  2505. made in this context.
  2506. </Para>
  2507. <Para>
  2508.    After <Function>SPI_connect</Function> is called current context is the procedure's one.  All
  2509. allocations made via <Function>palloc</Function>/<Function>repalloc</Function> or by SPI utility functions (except
  2510. for <Function>SPI_copytuple</Function>, <Function>SPI_modifytuple</Function>,
  2511.  <Function>SPI_palloc</Function> and <Function>SPI_repalloc</Function>) are
  2512. made in this context.
  2513. </Para>
  2514. <Para>
  2515.    When a procedure disconnects from the SPI manager (via <Function>SPI_finish</Function>) the
  2516. current context is restored to the upper Executor context and all allocations
  2517. made in the procedure memory context are freed and can't be used any more!
  2518. </Para>
  2519. <Para>
  2520.    If you want to return something to the upper Executor then you have to
  2521. allocate memory for this in the upper context!
  2522. </Para>
  2523. <Para>
  2524.    SPI has no ability to automatically free allocations in the upper Executor
  2525. context!
  2526. </Para>
  2527. <Para>
  2528.    SPI automatically frees memory allocated during execution of a query when
  2529. this query is done!
  2530. </Para>
  2531. </Sect1>
  2532. <Sect1>
  2533. <Title>Visibility of Data Changes</Title>
  2534. <Para>
  2535. <ProductName>Postgres</ProductName> data changes visibility rule: during a query execution, data
  2536. changes made by the query itself (via SQL-function, SPI-function, triggers)
  2537. are invisible to the query scan.  For example, in query
  2538.    INSERT INTO a SELECT * FROM a
  2539.    tuples inserted are invisible for SELECT' scan.  In effect, this
  2540. duplicates the database table within itself (subject to unique index
  2541. rules, of course) without recursing.
  2542. </Para>
  2543. <Para>
  2544.    Changes made by query Q are visible by queries which are started after
  2545. query Q, no matter whether they are started inside Q (during the execution
  2546. of Q) or after Q is done.
  2547. </Para>
  2548. </Sect1>
  2549. <Sect1>
  2550. <Title>Examples</Title>
  2551. <Para>
  2552.    This example of SPI usage demonstrates the visibility rule.
  2553.    There are more complex examples in in src/test/regress/regress.c and
  2554. in contrib/spi.
  2555. </Para>
  2556. <Para>
  2557.    This is a very simple example of SPI usage. The procedure execq accepts
  2558. an SQL-query in its first argument and tcount in its second, executes the
  2559. query using SPI_exec and returns the number of tuples for which the query
  2560. executed:
  2561. <ProgramListing>
  2562. #include "executor/spi.h" /* this is what you need to work with SPI */
  2563. int execq(text *sql, int cnt);
  2564. int
  2565. execq(text *sql, int cnt)
  2566. {
  2567. int ret;
  2568. int proc = 0;
  2569. SPI_connect();
  2570. ret = SPI_exec(textout(sql), cnt);
  2571. proc = SPI_processed;
  2572. /*
  2573.  * If this is SELECT and some tuple(s) fetched -
  2574.  * returns tuples to the caller via elog (NOTICE).
  2575.  */
  2576. if ( ret == SPI_OK_SELECT && SPI_processed > 0 )
  2577. {
  2578. TupleDesc tupdesc = SPI_tuptable->tupdesc;
  2579. SPITupleTable *tuptable = SPI_tuptable;
  2580. char buf[8192];
  2581. int i;
  2582. for (ret = 0; ret < proc; ret++)
  2583. {
  2584. HeapTuple tuple = tuptable->vals[ret];
  2585. for (i = 1, buf[0] = 0; i <= tupdesc->natts; i++)
  2586. sprintf(buf + strlen (buf), " %s%s",
  2587. SPI_getvalue(tuple, tupdesc, i),
  2588. (i == tupdesc->natts) ? " " : " |");
  2589. elog (NOTICE, "EXECQ: %s", buf);
  2590. }
  2591. }
  2592. SPI_finish();
  2593. return (proc);
  2594. }
  2595. </ProgramListing>
  2596. </Para>
  2597. <Para>
  2598.    Now, compile and create the function:
  2599. <ProgramListing>
  2600. create function execq (text, int4) returns int4 as '...path_to_so' language 'c';
  2601. </ProgramListing>
  2602. <ProgramListing>
  2603. vac=> select execq('create table a (x int4)', 0);
  2604. execq
  2605. -----
  2606.     0
  2607. (1 row)
  2608. vac=> insert into a values (execq('insert into a values (0)',0));
  2609. INSERT 167631 1
  2610. vac=> select execq('select * from a',0);
  2611. NOTICE:EXECQ:  0 <<< inserted by execq
  2612. NOTICE:EXECQ:  1 <<< value returned by execq and inserted by upper INSERT
  2613. execq
  2614. -----
  2615.     2
  2616. (1 row)
  2617. vac=> select execq('insert into a select x + 2 from a',1);
  2618. execq
  2619. -----
  2620.     1
  2621. (1 row)
  2622. vac=> select execq('select * from a', 10);
  2623. NOTICE:EXECQ:  0 
  2624. NOTICE:EXECQ:  1 
  2625. NOTICE:EXECQ:  2 <<< 0 + 2, only one tuple inserted - as specified
  2626. execq
  2627. -----
  2628.     3            <<< 10 is max value only, 3 is real # of tuples
  2629. (1 row)
  2630. vac=> delete from a;
  2631. DELETE 3
  2632. vac=> insert into a values (execq('select * from a', 0) + 1);
  2633. INSERT 167712 1
  2634. vac=> select * from a;
  2635. x
  2636. -
  2637. 1                <<< no tuples in a (0) + 1
  2638. (1 row)
  2639. vac=> insert into a values (execq('select * from a', 0) + 1);
  2640. NOTICE:EXECQ:  0 
  2641. INSERT 167713 1
  2642. vac=> select * from a;
  2643. x
  2644. -
  2645. 1
  2646. 2                <<< there was single tuple in a + 1
  2647. (2 rows)
  2648. --   This demonstrates data changes visibility rule:
  2649. vac=> insert into a select execq('select * from a', 0) * x from a;
  2650. NOTICE:EXECQ:  1 
  2651. NOTICE:EXECQ:  2 
  2652. NOTICE:EXECQ:  1 
  2653. NOTICE:EXECQ:  2 
  2654. NOTICE:EXECQ:  2 
  2655. INSERT 0 2
  2656. vac=> select * from a;
  2657. x
  2658. -
  2659. 1
  2660. 2
  2661. 2                <<< 2 tuples * 1 (x in first tuple)
  2662. 6                <<< 3 tuples (2 + 1 just inserted) * 2 (x in second tuple)
  2663. (4 rows)             ^^^^^^^^ 
  2664.                      tuples visible to execq() in different invocations
  2665. </ProgramListing>
  2666. </Para>
  2667. </Sect1>
  2668. </Chapter>