国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

directory search
前言 何為PostgreSQL? PostgreSQL簡史 格式約定 更多信息 臭蟲匯報指導(dǎo) I. 教程 章1. 從頭開始 1.1. 安裝 1.2. 體系基本概念 1.3. 創(chuàng)建一個數(shù)據(jù)庫 1.4. 訪問數(shù)據(jù)庫 章2. SQL語言 2.1. 介紹 2.2. 概念 2.3. 創(chuàng)建新表 2.4. 向表中添加行 2.5. 查詢一個表 2.6. 表間鏈接 2.7. 聚集函數(shù) 2.8. 更新 2.9. 刪除 章3. 高級特性 3.1. 介紹 3.2. 視圖 3.3. 外鍵 3.4. 事務(wù) 3.5. 窗口函數(shù) 3.6. 繼承 3.7. 結(jié)論 II. SQL語言 章4. SQL語法 4.1. 詞法結(jié)構(gòu) 4.2. 值表達式 4.3. 調(diào)用函數(shù) 章5. 數(shù)據(jù)定義 5.1. 表的基本概念 5.2. 缺省值 5.3. 約束 5.4. 系統(tǒng)字段 5.5. 修改表 5.6. 權(quán)限 5.7. 模式 5.8. 繼承 5.9. 分區(qū) 5.10. 其它數(shù)據(jù)庫對象 5.11. 依賴性跟蹤 章 6. 數(shù)據(jù)操作 6.1. 插入數(shù)據(jù) 6.2. 更新數(shù)據(jù) 6.3. 刪除數(shù)據(jù) 章7. 查詢 7.1. 概述 7.2. 表表達式 7.3. 選擇列表 7.4. 組合查詢 7.5. 行排序 7.6. LIMIT和OFFSET 7.7. VALUES列表 7.8. WITH的查詢(公用表表達式) 章8. 數(shù)據(jù)類型 8.1. 數(shù)值類型 8.2. 貨幣類型 8.3. 字符類型 8.4. 二進制數(shù)據(jù)類型 8.5. 日期/時間類型 8.6. 布爾類型 8.7. 枚舉類型 8.8. 幾何類型 8.9. 網(wǎng)絡(luò)地址類型 8.10. 位串類型 8.11. 文本搜索類型 8.12. UUID類型 8.13. XML類型 8.14. 數(shù)組 8.15. 復(fù)合類型 8.16. 對象標(biāo)識符類型 8.17. 偽類型 章 9. 函數(shù)和操作符 9.1. 邏輯操作符 9.2. 比較操作符 9.3. 數(shù)學(xué)函數(shù)和操作符 9.4. 字符串函數(shù)和操作符 9.5. 二進制字符串函數(shù)和操作符 9.6. 位串函數(shù)和操作符 9.7. 模式匹配 9.8. 數(shù)據(jù)類型格式化函數(shù) 9.9. 時間/日期函數(shù)和操作符 9.10. 支持枚舉函數(shù) 9.11. 幾何函數(shù)和操作符 9.12. 網(wǎng)絡(luò)地址函數(shù)和操作符 9.13. 文本檢索函數(shù)和操作符 9.14. XML函數(shù) 9.15. 序列操作函數(shù) 9.16. 條件表達式 9.17. 數(shù)組函數(shù)和操作符 9.18. 聚合函數(shù) 9.19. 窗口函數(shù) 9.20. 子查詢表達式 9.21. 行和數(shù)組比較 9.22. 返回集合的函數(shù) 9.23. 系統(tǒng)信息函數(shù) 9.24. 系統(tǒng)管理函數(shù) 9.25. 觸發(fā)器函數(shù) 章10. 類型轉(zhuǎn)換 10.3. 函數(shù) 10.2. 操作符 10.1. 概述 10.4. 值存儲 10.5. UNION 章11. 索引 11.1. 介紹 11.2. 索引類型 11.3. 多字段索引 11.4. 索引和ORDER BY 11.5. 組合多個索引 11.6. 唯一索引 11.7. 表達式上的索引 11.8. 部分索引 11.9. 操作類和操作簇 11.10. 檢查索引的使用 章12. Full Text Search 12.1. Introduction 12.2. Tables and Indexes 12.3. Controlling Text Search 12.4. Additional Features 12.5. Parsers 12.6. Dictionaries 12.7. Configuration Example 12.8. Testing and Debugging Text Search 12.9. GiST and GIN Index Types 12.10. psql Support 12.11. Limitations 12.12. Migration from Pre-8.3 Text Search 章13. 并發(fā)控制 13.1. 介紹 13.2. 事務(wù)隔離 13.3. 明確鎖定 13.4. 應(yīng)用層數(shù)據(jù)完整性檢查 13.5. 鎖和索引 章14. 性能提升技巧 14.1. 使用EXPLAIN 14.2. 規(guī)劃器使用的統(tǒng)計信息 14.3. 用明確的JOIN語句控制規(guī)劃器 14.4. 向數(shù)據(jù)庫中添加記錄 14.5. 非持久性設(shè)置 III. 服務(wù)器管理 章15. 安裝指導(dǎo) 15.1. 簡版 15.2. 要求 15.3. 獲取源碼 15.4. 升級 15.5. 安裝過程 15.6. 安裝后的設(shè)置 15.7. 支持的平臺 15.8. 特殊平臺的要求 章16. Installation from Source Code on Windows 16.1. Building with Visual C++ or the Platform SDK 16.2. Building libpq with Visual C++ or Borland C++ 章17. 服務(wù)器安裝和操作 17.1. PostgreSQL用戶帳戶 17.2. 創(chuàng)建數(shù)據(jù)庫集群 17.3. 啟動數(shù)據(jù)庫服務(wù)器 17.4. 管理內(nèi)核資源 17.5. 關(guān)閉服務(wù) 17.6. 防止服務(wù)器欺騙 17.7. 加密選項 17.8. 用SSL進行安全的TCP/IP連接 17.9. Secure TCP/IP Connections with SSH Tunnels 章18. 服務(wù)器配置 18.1. 設(shè)置參數(shù) 18.2. 文件位置 18.3. 連接和認(rèn)證 18.4. 資源消耗 18.5. 預(yù)寫式日志 18.6. 查詢規(guī)劃 18.7. 錯誤報告和日志 18.8. 運行時統(tǒng)計 18.9. 自動清理 18.10. 客戶端連接缺省 18.12. 版本和平臺兼容性 18.11. 鎖管理 18.13. 預(yù)置選項 18.14. 自定義的選項 18.15. 開發(fā)人員選項 18.16. 短選項 章19. 用戶認(rèn)證 19.1. pg_hba.conf 文件 19.2. 用戶名映射 19.3. 認(rèn)證方法 19.4. 用戶認(rèn)證 章20. 數(shù)據(jù)庫角色和權(quán)限 20.1. 數(shù)據(jù)庫角色 20.2. 角色屬性 20.3. 權(quán)限 20.4. 角色成員 20.5. 函數(shù)和觸發(fā)器 章21. 管理數(shù)據(jù)庫 21.1. 概述 21.2. 創(chuàng)建一個數(shù)據(jù)庫 21.3. 臨時庫 21.4. 數(shù)據(jù)庫配置 21.5. 刪除數(shù)據(jù)庫 21.6. 表空間 章22. 本土化 22.1. 區(qū)域支持 22.2. 字符集支持 章23. 日常數(shù)據(jù)庫維護工作 23.1. Routine Vacuuming日常清理 23.2. 經(jīng)常重建索引 23.3. 日志文件維護 章24. 備份和恢復(fù) 24.1. SQL轉(zhuǎn)儲 24.2. 文件系統(tǒng)級別的備份 24.3. 在線備份以及即時恢復(fù)(PITR) 24.4. 版本間遷移 章25. 高可用性與負(fù)載均衡,復(fù)制 25.1. 不同解決方案的比較 25.2. 日志傳送備份服務(wù)器 25.3. 失效切換 25.4. 日志傳送的替代方法 25.5. 熱備 章26. 恢復(fù)配置 26.1. 歸檔恢復(fù)設(shè)置 26.2. 恢復(fù)目標(biāo)設(shè)置 26.3. 備服務(wù)器設(shè)置 章27. 監(jiān)控數(shù)據(jù)庫的活動 27.1. 標(biāo)準(zhǔn)Unix工具 27.2. 統(tǒng)計收集器 27.3. 查看鎖 27.4. 動態(tài)跟蹤 章28. 監(jiān)控磁盤使用情況 28.1. 判斷磁盤的使用量 28.2. 磁盤滿導(dǎo)致的失效 章29. 可靠性和預(yù)寫式日志 29.1. 可靠性 29.2. 預(yù)寫式日志(WAL) 29.3. 異步提交 29.4. WAL配置 29.5. WAL內(nèi)部 章30. Regression Tests 30.1. Running the Tests 30.2. Test Evaluation 30.3. Variant Comparison Files 30.4. Test Coverage Examination IV. 客戶端接口 章31. libpq-C庫 31.1. 數(shù)據(jù)庫聯(lián)接函數(shù) 31.2. 連接狀態(tài)函數(shù) 31.3. 命令執(zhí)行函數(shù) 31.4. 異步命令處理 31.5. 取消正在處理的查詢 31.6. 捷徑接口 31.7. 異步通知 31.8. 與COPY命令相關(guān)的函數(shù) 31.9. Control Functions 控制函數(shù) 31.10. 其他函數(shù) 31.11. 注意信息處理 31.12. 事件系統(tǒng) 31.13. 環(huán)境變量 31.14. 口令文件 31.15. 連接服務(wù)的文件 31.16. LDAP查找連接參數(shù) 31.17. SSL支持 31.18. 在多線程程序里的行為 31.19. 制作libpq程序 31.20. 例子程序 章32. 大對象 32.1. 介紹 32.2. 實現(xiàn)特點 32.3. 客戶端接口 32.4. 服務(wù)器端函數(shù) 32.5. 例子程序 章33. ECPG - Embedded SQL in C 33.1. The Concept 33.2. Connecting to the Database Server 33.3. Closing a Connection 33.4. Running SQL Commands 33.5. Choosing a Connection 33.6. Using Host Variables 33.7. Dynamic SQL 33.8. pgtypes library 33.9. Using Descriptor Areas 33.10. Informix compatibility mode 33.11. Error Handling 33.12. Preprocessor directives 33.13. Processing Embedded SQL Programs 33.14. Library Functions 33.15. Internals 章34. 信息模式 34.1. 關(guān)于這個模式 34.2. 數(shù)據(jù)類型 34.3. information_schema_catalog_name 34.4. administrable_role_authorizations 34.5. applicable_roles 34.6. attributes 34.7. check_constraint_routine_usage 34.8. check_constraints 34.9. column_domain_usage 34.10. column_privileges 34.11. column_udt_usage 34.12. 字段 34.13. constraint_column_usage 34.14. constraint_table_usage 34.15. data_type_privileges 34.16. domain_constraints 34.18. domains 34.17. domain_udt_usage 34.19. element_types 34.20. enabled_roles 34.21. foreign_data_wrapper_options 34.22. foreign_data_wrappers 34.23. foreign_server_options 34.24. foreign_servers 34.25. key_column_usage 34.26. parameters 34.27. referential_constraints 34.28. role_column_grants 34.29. role_routine_grants 34.30. role_table_grants 34.31. role_usage_grants 34.32. routine_privileges 34.33. routines 34.34. schemata 34.35. sequences 34.36. sql_features 34.37. sql_implementation_info 34.38. sql_languages 34.39. sql_packages 34.40. sql_parts 34.41. sql_sizing 34.42. sql_sizing_profiles 34.43. table_constraints 34.44. table_privileges 34.45. tables 34.46. triggered_update_columns 34.47. 觸發(fā)器 34.48. usage_privileges 34.49. user_mapping_options 34.50. user_mappings 34.51. view_column_usage 34.52. view_routine_usage 34.53. view_table_usage 34.54. 視圖 V. 服務(wù)器端編程 章35. 擴展SQL 35.1. 擴展性是如何實現(xiàn)的 35.2. PostgreSQL類型系統(tǒng) 35.3. User-Defined Functions 35.4. Query Language (SQL) Functions 35.5. Function Overloading 35.6. Function Volatility Categories 35.7. Procedural Language Functions 35.8. Internal Functions 35.9. C-Language Functions 35.10. User-Defined Aggregates 35.11. User-Defined Types 35.12. User-Defined Operators 35.13. Operator Optimization Information 35.14. Interfacing Extensions To Indexes 35.15. 用C++擴展 章36. 觸發(fā)器 36.1. 觸發(fā)器行為概述 36.3. 用 C 寫觸發(fā)器 36.2. 數(shù)據(jù)改變的可視性 36.4. 一個完整的例子 章37. 規(guī)則系統(tǒng) 37.1. The Query Tree 37.2. 視圖和規(guī)則系統(tǒng) 37.3. 在INSERT,UPDATE和DELETE上的規(guī)則 37.4. 規(guī)則和權(quán)限 37.5. 規(guī)則和命令狀態(tài) 37.6. 規(guī)則與觸發(fā)器得比較 章38. Procedural Languages 38.1. Installing Procedural Languages 章39. PL/pgSQL - SQL過程語言 39.1. 概述 39.2. PL/pgSQL的結(jié)構(gòu) 39.3. 聲明 39.4. 表達式 39.5. 基本語句 39.6. 控制結(jié)構(gòu) 39.7. 游標(biāo) 39.8. 錯誤和消息 39.9. 觸發(fā)器過程 39.10. PL/pgSQL Under the Hood 39.11. 開發(fā)PL/pgSQL的一些提示 39.12. 從OraclePL/SQL 進行移植 章40. PL/Tcl - Tcl Procedural Language 40.1. Overview 40.2. PL/Tcl Functions and Arguments 40.3. Data Values in PL/Tcl 40.4. Global Data in PL/Tcl 40.5. Database Access from PL/Tcl 40.6. Trigger Procedures in PL/Tcl 40.7. Modules and the unknown command 40.8. Tcl Procedure Names 章41. PL/Perl - Perl Procedural Language 41.1. PL/Perl Functions and Arguments 41.2. Data Values in PL/Perl 41.3. Built-in Functions 41.4. Global Values in PL/Perl 41.6. PL/Perl Triggers 41.5. Trusted and Untrusted PL/Perl 41.7. PL/Perl Under the Hood 章42. PL/Python - Python Procedural Language 42.1. Python 2 vs. Python 3 42.2. PL/Python Functions 42.3. Data Values 42.4. Sharing Data 42.5. Anonymous Code Blocks 42.6. Trigger Functions 42.7. Database Access 42.8. Utility Functions 42.9. Environment Variables 章43. Server Programming Interface 43.1. Interface Functions Spi-spi-connect Spi-spi-finish Spi-spi-push Spi-spi-pop Spi-spi-execute Spi-spi-exec Spi-spi-execute-with-args Spi-spi-prepare Spi-spi-prepare-cursor Spi-spi-prepare-params Spi-spi-getargcount Spi-spi-getargtypeid Spi-spi-is-cursor-plan Spi-spi-execute-plan Spi-spi-execute-plan-with-paramlist Spi-spi-execp Spi-spi-cursor-open Spi-spi-cursor-open-with-args Spi-spi-cursor-open-with-paramlist Spi-spi-cursor-find Spi-spi-cursor-fetch Spi-spi-cursor-move Spi-spi-scroll-cursor-fetch Spi-spi-scroll-cursor-move Spi-spi-cursor-close Spi-spi-saveplan 43.2. Interface Support Functions Spi-spi-fname Spi-spi-fnumber Spi-spi-getvalue Spi-spi-getbinval Spi-spi-gettype Spi-spi-gettypeid Spi-spi-getrelname Spi-spi-getnspname 43.3. Memory Management Spi-spi-palloc Spi-realloc Spi-spi-pfree Spi-spi-copytuple Spi-spi-returntuple Spi-spi-modifytuple Spi-spi-freetuple Spi-spi-freetupletable Spi-spi-freeplan 43.4. Visibility of Data Changes 43.5. Examples VI. 參考手冊 I. SQL命令 Sql-abort Sql-alteraggregate Sql-alterconversion Sql-alterdatabase Sql-alterdefaultprivileges Sql-alterdomain Sql-alterforeigndatawrapper Sql-alterfunction Sql-altergroup Sql-alterindex Sql-alterlanguage Sql-alterlargeobject Sql-alteroperator Sql-alteropclass Sql-alteropfamily Sql-alterrole Sql-alterschema Sql-altersequence Sql-alterserver Sql-altertable Sql-altertablespace Sql-altertsconfig Sql-altertsdictionary Sql-altertsparser Sql-altertstemplate Sql-altertrigger Sql-altertype Sql-alteruser Sql-alterusermapping Sql-alterview Sql-analyze Sql-begin Sql-checkpoint Sql-close Sql-cluster Sql-comment Sql-commit Sql-commit-prepared Sql-copy Sql-createaggregate Sql-createcast Sql-createconstraint Sql-createconversion Sql-createdatabase Sql-createdomain Sql-createforeigndatawrapper Sql-createfunction Sql-creategroup Sql-createindex Sql-createlanguage Sql-createoperator Sql-createopclass Sql-createopfamily Sql-createrole Sql-createrule Sql-createschema Sql-createsequence Sql-createserver Sql-createtable Sql-createtableas Sql-createtablespace Sql-createtsconfig Sql-createtsdictionary Sql-createtsparser Sql-createtstemplate Sql-createtrigger Sql-createtype Sql-createuser Sql-createusermapping Sql-createview Sql-deallocate Sql-declare Sql-delete Sql-discard Sql-do Sql-dropaggregate Sql-dropcast Sql-dropconversion Sql-dropdatabase Sql-dropdomain Sql-dropforeigndatawrapper Sql-dropfunction Sql-dropgroup Sql-dropindex Sql-droplanguage Sql-dropoperator Sql-dropopclass Sql-dropopfamily Sql-drop-owned Sql-droprole Sql-droprule Sql-dropschema Sql-dropsequence Sql-dropserver Sql-droptable Sql-droptablespace Sql-droptsconfig Sql-droptsdictionary Sql-droptsparser Sql-droptstemplate Sql-droptrigger Sql-droptype Sql-dropuser Sql-dropusermapping Sql-dropview Sql-end Sql-execute Sql-explain Sql-fetch Sql-grant Sql-insert Sql-listen Sql-load Sql-lock Sql-move Sql-notify Sql-prepare Sql-prepare-transaction Sql-reassign-owned Sql-reindex Sql-release-savepoint Sql-reset Sql-revoke Sql-rollback Sql-rollback-prepared Sql-rollback-to Sql-savepoint Sql-select Sql-selectinto Sql-set Sql-set-constraints Sql-set-role Sql-set-session-authorization Sql-set-transaction Sql-show Sql-start-transaction Sql-truncate Sql-unlisten Sql-update Sql-vacuum Sql-values II. 客戶端應(yīng)用程序 App-clusterdb App-createdb App-createlang App-createuser App-dropdb App-droplang App-dropuser App-ecpg App-pgconfig App-pgdump App-pg-dumpall App-pgrestore App-psql App-reindexdb App-vacuumdb III. PostgreSQL服務(wù)器應(yīng)用程序 App-initdb App-pgcontroldata App-pg-ctl App-pgresetxlog App-postgres App-postmaster VII. 內(nèi)部 章44. PostgreSQL內(nèi)部概覽 44.1. 查詢路徑 44.2. 連接是如何建立起來的 44.3. 分析器階段 44.4. ThePostgreSQL規(guī)則系統(tǒng) 44.5. 規(guī)劃器/優(yōu)化器 44.6. 執(zhí)行器 章45. 系統(tǒng)表 45.1. 概述 45.2. pg_aggregate 45.3. pg_am 45.4. pg_amop 45.5. pg_amproc 45.6. pg_attrdef 45.7. pg_attribute 45.8. pg_authid 45.9. pg_auth_members 45.10. pg_cast 45.11. pg_class 45.12. pg_constraint 45.13. pg_conversion 45.14. pg_database 45.15. pg_db_role_setting 45.16. pg_default_acl 45.17. pg_depend 45.18. pg_description 45.19. pg_enum 45.20. pg_foreign_data_wrapper 45.21. pg_foreign_server 45.22. pg_index 45.23. pg_inherits 45.24. pg_language 45.25. pg_largeobject 45.26. pg_largeobject_metadata 45.27. pg_namespace 45.28. pg_opclass 45.29. pg_operator 45.30. pg_opfamily 45.31. pg_pltemplate 45.32. pg_proc 45.33. pg_rewrite 45.34. pg_shdepend 45.35. pg_shdescription 45.36. pg_statistic 45.37. pg_tablespace 45.38. pg_trigger 45.39. pg_ts_config 45.40. pg_ts_config_map 45.41. pg_ts_dict 45.42. pg_ts_parser 45.43. pg_ts_template 45.44. pg_type 45.45. pg_user_mapping 45.46. System Views 45.47. pg_cursors 45.48. pg_group 45.49. pg_indexes 45.50. pg_locks 45.51. pg_prepared_statements 45.52. pg_prepared_xacts 45.53. pg_roles 45.54. pg_rules 45.55. pg_settings 45.56. pg_shadow 45.57. pg_stats 45.58. pg_tables 45.59. pg_timezone_abbrevs 45.60. pg_timezone_names 45.61. pg_user 45.62. pg_user_mappings 45.63. pg_views 章46. Frontend/Backend Protocol 46.1. Overview 46.2. Message Flow 46.3. Streaming Replication Protocol 46.4. Message Data Types 46.5. Message Formats 46.6. Error and Notice Message Fields 46.7. Summary of Changes since Protocol 2.0 47. PostgreSQL Coding Conventions 47.1. Formatting 47.2. Reporting Errors Within the Server 47.3. Error Message Style Guide 章48. Native Language Support 48.1. For the Translator 48.2. For the Programmer 章49. Writing A Procedural Language Handler 章50. Genetic Query Optimizer 50.1. Query Handling as a Complex Optimization Problem 50.2. Genetic Algorithms 50.3. Genetic Query Optimization (GEQO) in PostgreSQL 50.4. Further Reading 章51. 索引訪問方法接口定義 51.1. 索引的系統(tǒng)表記錄 51.2. 索引訪問方法函數(shù) 51.3. 索引掃描 51.4. 索引鎖的考量 51.5. 索引唯一性檢查 51.6. 索引開銷估計函數(shù) 章52. GiST Indexes 52.1. Introduction 52.2. Extensibility 52.3. Implementation 52.4. Examples 52.5. Crash Recovery 章53. GIN Indexes 53.1. Introduction 53.2. Extensibility 53.3. Implementation 53.4. GIN tips and tricks 53.5. Limitations 53.6. Examples 章54. 數(shù)據(jù)庫物理存儲 54.1. 數(shù)據(jù)庫文件布局 54.2. TOAST 54.3. 自由空間映射 54.4. 可見映射 54.5. 數(shù)據(jù)庫分頁文件 章55. BKI后端接口 55.1. BKI 文件格式 55.2. BKI命令 55.3. 系統(tǒng)初始化的BKI文件的結(jié)構(gòu) 55.4. 例子 章56. 規(guī)劃器如何使用統(tǒng)計信息 56.1. 行預(yù)期的例子 VIII. 附錄 A. PostgreSQL錯誤代碼 B. 日期/時間支持 B.1. 日期/時間輸入解析 B.2. 日期/時間關(guān)鍵字 B.3. 日期/時間配置文件 B.4. 日期單位的歷史 C. SQL關(guān)鍵字 D. SQL Conformance D.1. Supported Features D.2. Unsupported Features E. Release Notes Release-0-01 Release-0-02 Release-0-03 Release-1-0 Release-1-01 Release-1-02 Release-1-09 Release-6-0 Release-6-1 Release-6-1-1 Release-6-2 Release-6-2-1 Release-6-3 Release-6-3-1 Release-6-3-2 Release-6-4 Release-6-4-1 Release-6-4-2 Release-6-5 Release-6-5-1 Release-6-5-2 Release-6-5-3 Release-7-0 Release-7-0-1 Release-7-0-2 Release-7-0-3 Release-7-1 Release-7-1-1 Release-7-1-2 Release-7-1-3 Release-7-2 Release-7-2-1 Release-7-2-2 Release-7-2-3 Release-7-2-4 Release-7-2-5 Release-7-2-6 Release-7-2-7 Release-7-2-8 Release-7-3 Release-7-3-1 Release-7-3-10 Release-7-3-11 Release-7-3-12 Release-7-3-13 Release-7-3-14 Release-7-3-15 Release-7-3-16 Release-7-3-17 Release-7-3-18 Release-7-3-19 Release-7-3-2 Release-7-3-20 Release-7-3-21 Release-7-3-3 Release-7-3-4 Release-7-3-5 Release-7-3-6 Release-7-3-7 Release-7-3-8 Release-7-3-9 Release-7-4 Release-7-4-1 Release-7-4-10 Release-7-4-11 Release-7-4-12 Release-7-4-13 Release-7-4-14 Release-7-4-15 Release-7-4-16 Release-7-4-17 Release-7-4-18 Release-7-4-19 Release-7-4-2 Release-7-4-20 Release-7-4-21 Release-7-4-22 Release-7-4-23 Release-7-4-24 Release-7-4-25 Release-7-4-26 Release-7-4-27 Release-7-4-28 Release-7-4-29 Release-7-4-3 Release-7-4-30 Release-7-4-4 Release-7-4-5 Release-7-4-6 Release-7-4-7 Release-7-4-8 Release-7-4-9 Release-8-0 Release-8-0-1 Release-8-0-10 Release-8-0-11 Release-8-0-12 Release-8-0-13 Release-8-0-14 Release-8-0-15 Release-8-0-16 Release-8-0-17 Release-8-0-18 Release-8-0-19 Release-8-0-2 Release-8-0-20 Release-8-0-21 Release-8-0-22 Release-8-0-23 Release-8-0-24 Release-8-0-25 Release-8-0-26 Release-8-0-3 Release-8-0-4 Release-8-0-5 Release-8-0-6 Release-8-0-7 Release-8-0-8 Release-8-0-9 Release-8-1 Release-8-1-1 Release-8-1-10 Release-8-1-11 Release-8-1-12 Release-8-1-13 Release-8-1-14 Release-8-1-15 Release-8-1-16 Release-8-1-17 Release-8-1-18 Release-8-1-19 Release-8-1-2 Release-8-1-20 Release-8-1-21 Release-8-1-22 Release-8-1-23 Release-8-1-3 Release-8-1-4 Release-8-1-5 Release-8-1-6 Release-8-1-7 Release-8-1-8 Release-8-1-9 Release-8-2 Release-8-2-1 Release-8-2-10 Release-8-2-11 Release-8-2-12 Release-8-2-13 Release-8-2-14 Release-8-2-15 Release-8-2-16 Release-8-2-17 Release-8-2-18 Release-8-2-19 Release-8-2-2 Release-8-2-20 Release-8-2-21 Release-8-2-3 Release-8-2-4 Release-8-2-5 Release-8-2-6 Release-8-2-7 Release-8-2-8 Release-8-2-9 Release-8-3 Release-8-3-1 Release-8-3-10 Release-8-3-11 Release-8-3-12 Release-8-3-13 Release-8-3-14 Release-8-3-15 Release-8-3-2 Release-8-3-3 Release-8-3-4 Release-8-3-5 Release-8-3-6 Release-8-3-7 Release-8-3-8 Release-8-3-9 Release-8-4 Release-8-4-1 Release-8-4-2 Release-8-4-3 Release-8-4-4 Release-8-4-5 Release-8-4-6 Release-8-4-7 Release-8-4-8 Release-9-0 Release-9-0-1 Release-9-0-2 Release-9-0-3 Release-9-0-4 F. 額外提供的模塊 F.1. adminpack F.2. auto_explain F.3. btree_gin F.4. btree_gist F.5. chkpass F.6. citext F.7. cube F.8. dblink Contrib-dblink-connect Contrib-dblink-connect-u Contrib-dblink-disconnect Contrib-dblink Contrib-dblink-exec Contrib-dblink-open Contrib-dblink-fetch Contrib-dblink-close Contrib-dblink-get-connections Contrib-dblink-error-message Contrib-dblink-send-query Contrib-dblink-is-busy Contrib-dblink-get-notify Contrib-dblink-get-result Contrib-dblink-cancel-query Contrib-dblink-get-pkey Contrib-dblink-build-sql-insert Contrib-dblink-build-sql-delete Contrib-dblink-build-sql-update F.9. dict_int F.10. dict_xsyn F.11. earthdistance F.12. fuzzystrmatch F.13. hstore F.14. intagg F.15. intarray F.16. isn F.17. lo F.18. ltree F.19. oid2name F.20. pageinspect F.21. passwordcheck F.22. pg_archivecleanup F.23. pgbench F.24. pg_buffercache F.25. pgcrypto F.26. pg_freespacemap F.27. pgrowlocks F.28. pg_standby F.29. pg_stat_statements F.30. pgstattuple F.31. pg_trgm F.32. pg_upgrade F.33. seg F.34. spi F.35. sslinfo F.36. tablefunc F.37. test_parser F.38. tsearch2 F.39. unaccent F.40. uuid-ossp F.41. vacuumlo F.42. xml2 G. 外部項目 G.1. 客戶端接口 G.2. 過程語言 G.3. 擴展 H. The Source Code Repository H.1. Getting The Source Via Git I. 文檔 I.1. DocBook I.2. 工具集 I.3. 制作文檔 I.4. 文檔寫作 I.5. 風(fēng)格指導(dǎo) J. 首字母縮略詞 參考書目 Bookindex Index
characters

31.20. 例子程序

這些例子和其他的可以在字典src/test/examples的源代碼分布中。

Example 31-1. libpq例子程序 1

/*
 * testlibpq.c
 *
 *      Test the C version of libpq,the PostgreSQL frontend library.
 */
#include<stdio.h>
#include<stdlib.h>
#include<libpq-fe.h>

static void
exit_nicely(PGconn *conn)
{
    PQfinish(conn);
    exit(1);
}

int
main(int argc,char **argv)
{
    const char *conninfo;
    PGconn     *conn;
    PGresult   *res;
    int         nFields;
    int         i,
                j;

    /*
	 * 如果用戶在命令行上提供了一個參數(shù),則拿它當(dāng)作 conninfo 字串使用;
     * 否則缺省為 dbname=postgres 并且使用環(huán)境變量或者所有其它連接參數(shù)
     * 都使用缺省值。

	 
     */
    if (argc >1)
        conninfo = argv[1];
    else
        conninfo = "dbname = postgres";

    /*連接數(shù)據(jù)庫*/
    conn = PQconnectdb(conninfo);

    /* 檢查后端連接成功建立*/
    if (PQstatus(conn) != CONNECTION_OK)
    {
        fprintf(stderr,"Connection to database failed: %s",
                PQerrorMessage(conn));
        exit_nicely(conn);
    }

    /*
	 * 我們的測試實例涉及游標(biāo)的使用,這個時候我們必須使用事務(wù)塊
     * 我們可以把全部事情放在一個  "select * from pg_database"
     * PQexec() 里,不過那樣太簡單了,不是個好例子。
     */

    /* 開始一個事務(wù)塊*/
    res = PQexec(conn,"BEGIN");
    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        fprintf(stderr,"BEGIN command failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }

    /*
     * leaks    應(yīng)該在結(jié)果不需要的時候 PQclear PGresult,以避免內(nèi)存泄漏

     */
    PQclear(res);

    /*
	 * 從系統(tǒng)表 pg_database 里抓取數(shù)據(jù)

     */
    res = PQexec(conn,"DECLARE myportal CURSOR FOR select * from pg_database");
    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        fprintf(stderr,"DECLARE CURSOR failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }
    PQclear(res);

    res = PQexec(conn,"FETCH ALL in myportal");
    if (PQresultStatus(res) != PGRES_TUPLES_OK)
    {
        fprintf(stderr,"FETCH ALL failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }

    /* 首先,打印屬性名稱*/
	

    nFields = PQnfields(res);
    for (i = 0; i< nFields; i++)
        printf("%-15s",PQfname(res,i));
    printf("\n\n");

    /* 然后打印行*/
    for (i = 0; i< PQntuples(res); i++)
    {
        for (j = 0; j< nFields; j++)
            printf("%-15s",PQgetvalue(res,i,j));
        printf("\n");
    }

    PQclear(res);

    /* 關(guān)閉游標(biāo) ... 我們不用檢查錯誤 ... */
    res = PQexec(conn,"CLOSE myportal");
    PQclear(res);

    /*結(jié)束事務(wù)*/
    res = PQexec(conn,"END");
    PQclear(res);

    /* 關(guān)閉數(shù)據(jù)庫連接并清理 */
    PQfinish(conn);

    return 0;
}

Example 31-2. libpq例子程序 2

/*
 * testlibpq2.c
 *
 *
 *
 *  測試異步通知接口
 *
 * 運行此程序,然后從另外一個窗口的 psql 里運行
 *  NOTIFY TBL2;
 * 重復(fù)四次,直到程序退出
 *
 * 或者,如果你想好玩一點,用下面命令填充數(shù)據(jù)庫∶
 * (在 src/test/examples/testlibpq2.sql 里提供)
 *
 *   CREATE TABLE TBL1 (i int4);
 *
 *   CREATE TABLE TBL2 (i int4);
 *
 *   CREATE RULE r1 AS ON INSERT TO TBL1 DO
 *     (INSERT INTO TBL2 values (new.i); NOTIFY TBL2);
 *
 * 然后做四次∶
 *
 *   INSERT INTO TBL1 values (10);

 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<sys/time.h>
#include<libpq-fe.h>

static void
exit_nicely(PGconn *conn)
{
    PQfinish(conn);
    exit(1);
}

int
main(int argc,char **argv)
{
    const char *conninfo;
    PGconn     *conn;
    PGresult   *res;
    PGnotify   *notify;
    int         nnotifies;


	 /*
     * 如果用戶在命令行上提供了參數(shù),
     * 那么拿它當(dāng)作 conninfo 字串;否則缺省設(shè)置是 dbname=postgres
     * 并且對其它連接使用環(huán)境變量或者缺省值。
     * 
     */

    if (argc >1)
        conninfo = argv[1];
    else
        conninfo = "dbname = postgres";

	 /* 和數(shù)據(jù)庫建立鏈接 */

    conn = PQconnectdb(conninfo);

    /* 檢查一下與服務(wù)器的連接是否成功建立*/
	
    if (PQstatus(conn) != CONNECTION_OK)
    {
        fprintf(stderr,"Connection to database failed: %s",
                PQerrorMessage(conn));
        exit_nicely(conn);
    }

    /*
	 * 發(fā)出 LISTEN 命令打開來自規(guī)則 NOTIFY 的通知
     */
    res = PQexec(conn,"LISTEN TBL2");
    if (PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        fprintf(stderr,"LISTEN command failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }

 
	 /*
     * 如果不再需要 PGresult 了,我們應(yīng)該 PQclear,以避免內(nèi)存泄漏
     */

    PQclear(res);

    /* 收到四次通知之后退出。*/
    nnotifies = 0;
    while (nnotifies< 4)
    {
        
		 
		  /*
         * 睡眠,直到某些事件發(fā)生。我們使用 select(2) 等待輸入,
         * 但是也可以用 poll() 或者類似的設(shè)施
         */

        int         sock;
        fd_set      input_mask;

        sock = PQsocket(conn);

        if (sock< 0)
            break;              /* 不應(yīng)該發(fā)生*/

        FD_ZERO(&input_mask);
        FD_SET(sock,&input_mask);

        if (select(sock + 1,&input_mask,NULL,NULL,NULL)< 0)
        {
            fprintf(stderr,"select() failed: %s\n",strerror(errno));
            exit_nicely(conn);
        }

        /* 現(xiàn)在檢查輸入 */
        PQconsumeInput(conn);
        while ((notify = PQnotifies(conn)) != NULL)
        {
            fprintf(stderr,
                    "ASYNC NOTIFY of '%s' received from backend pid %d\n",
                    notify->relname,notify->be_pid);
            PQfreemem(notify);
            nnotifies++;
        }
    }

    fprintf(stderr,"Done.\n");

    /* 關(guān)閉數(shù)據(jù)連接并清理*/
    PQfinish(conn);

    return 0;
}

Example 31-3. libpq例子程序3

/*
 * testlibpq3.c
 *      Test out-of-line parameters and binary I/O.
 *
 * Before running this,populate a database with the following commands
 * (provided in src/test/examples/testlibpq3.sql):
 *
 * CREATE TABLE test1 (i int4,t text,b bytea);
 *
 * INSERT INTO test1 values (1,'joe''s place','\\000\\001\\002\\003\\004');
 * INSERT INTO test1 values (2,'ho there','\\004\\003\\002\\001\\000');
 *
 * The expected output is:
 *
 * tuple 0: got
 *  i = (4 bytes) 1
 *  t = (11 bytes) 'joe's place'
 *  b = (5 bytes) \000\001\002\003\004
 *
 * tuple 0: got
 *  i = (4 bytes) 2
 *  t = (8 bytes) 'ho there'
 *  b = (5 bytes) \004\003\002\001\000
 */
 
 /*
 * testlibpq3.c
 *              測試線外參數(shù)和二進制I/O。
 *
 * 在運行這個例子之前,用下面的命令填充一個數(shù)據(jù)庫
 * (在 src/test/examples/testlibpq3.sql 里提供):
 *
 * CREATE TABLE test1 (i int4,t text,b bytea);
 *
 * INSERT INTO test1 values (1,'joe''s place','\\000\\001\\002\\003\\004');
 * INSERT INTO test1 values (2,'ho there','\\004\\003\\002\\001\\000');
 *
 * 期望的輸出是:
 *
 * tuple 0: got
 *  i = (4 bytes) 1
 *  t = (11 bytes) 'joe's place'
 *  b = (5 bytes) \000\001\002\003\004
 *
 * tuple 0: got
 *  i = (4 bytes) 2
 *  t = (8 bytes) 'ho there'
 *  b = (5 bytes) \004\003\002\001\000
 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<libpq-fe.h>

/* for ntohl/htonl */
#include<netinet/in.h>
#include<arpa/inet.h>


static void
exit_nicely(PGconn *conn)
{
    PQfinish(conn);
    exit(1);
}

 
 /*
 * 這個函數(shù)打印查詢結(jié)果,這些結(jié)果是二進制格式,從上面的
 * 注釋里面創(chuàng)建的表中抓取出來的。我們把這個函數(shù)單獨拆出來
 * 是因為 main() 函數(shù)用了它兩次。
 */

static void
show_binary_results(PGresult *res)
{
    int         i,
                j;
    int         i_fnum,
                t_fnum,
                b_fnum;

	
	 /* 使用 PQfnumber 來避免對結(jié)果中的字段順序進行假設(shè) */

    i_fnum = PQfnumber(res,"i");
    t_fnum = PQfnumber(res,"t");
    b_fnum = PQfnumber(res,"b");

    for (i = 0; i< PQntuples(res); i++)
    {
        char       *iptr;
        char       *tptr;
        char       *bptr;
        int         blen;
        int         ival;

		/* 獲取字段值(我們忽略了它們可能為空的這個可能?。?/

        iptr = PQgetvalue(res,i,i_fnum);
        tptr = PQgetvalue(res,i,t_fnum);
        bptr = PQgetvalue(res,i,b_fnum);


		 
		  /*
         * INT4 的二進制表現(xiàn)形式是網(wǎng)絡(luò)字節(jié)序,
         * 我們最好轉(zhuǎn)換成本地字節(jié)序。
         */

        ival = ntohl(*((uint32_t *) iptr));

		 
		 /*
         * TEXT 的二進制表現(xiàn)形式是,嗯,文本,因為 libpq 好的會給它附加一個字節(jié)零,
         * 因此把它看做 C 字串就挺好。
         *
         * BYTEA 的二進制表現(xiàn)形式是一堆字節(jié),里面可能包含嵌入的空值,
         * 因此我們必須注意字段長度。
         */

        blen = PQgetlength(res,i,b_fnum);

        printf("tuple %d: got\n",i);
        printf(" i = (%d bytes) %d\n",
               PQgetlength(res,i,i_fnum),ival);
        printf(" t = (%d bytes) '%s'\n",
               PQgetlength(res,i,t_fnum),tptr);
        printf(" b = (%d bytes) ",blen);
        for (j = 0; j< blen; j++)
            printf("\\%03o",bptr[j]);
        printf("\n\n");
    }
}

int
main(int argc,char **argv)
{
    const char *conninfo;
    PGconn     *conn;
    PGresult   *res;
    const char *paramValues[1];
    int         paramLengths[1];
    int         paramFormats[1];
    uint32_t    binaryIntVal;


	 /*
     * 如果用戶在命令行上提供了參數(shù),
     * 那么拿它當(dāng)作 conninfo 字串;否則缺省設(shè)置是 dbname=postgres
     * 并且對其它連接使用環(huán)境變量或者缺省值。
     *
     */

    if (argc >1)
        conninfo = argv[1];
    else
        conninfo = "dbname = postgres";

	 /* 和數(shù)據(jù)庫建立鏈接 */

    conn = PQconnectdb(conninfo);

	/*
     * 檢查一下與服務(wù)器的連接是否成功建立
     */

    if (PQstatus(conn) != CONNECTION_OK)
    {
        fprintf(stderr,"Connection to database failed: %s",
                PQerrorMessage(conn));
        exit_nicely(conn);
    }

	 
	  /*
     * 這個程序是用來演示使用線外參數(shù)的 PQexecParams(),
     * 以及結(jié)果集的二進制傳輸。第一個例子使用文本傳輸參數(shù),
     * 但是用二進制格式檢索結(jié)果。通過使用線外參數(shù),我們可以避免大量
     * 枯燥的字串的引起和逃逸。請注意我們這里不需要對參數(shù)值里的引號
     * 做任何特殊的處理
     */


	 /* 這里是我們的線外數(shù)據(jù)*/

    paramValues[0] = "joe's place";

    res = PQexecParams(conn,
                       "SELECT * FROM test1 WHERE t = $1",
                       1,/* 一個參數(shù)*/
                       NULL,/* 讓后端推出參數(shù)類型*/
                       paramValues,
                       NULL,/* 因為是文本,所以必須要參數(shù)長度 */
                       NULL,/* 缺省是全部文本參數(shù) */
                       1);      /* 要求二進制結(jié)果*/

    if (PQresultStatus(res) != PGRES_TUPLES_OK)
    {
        fprintf(stderr,"SELECT failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }

    show_binary_results(res);

    PQclear(res);


	 
	 /*
     * 在這個第二個例子里,我們以二進制格式傳輸一個整數(shù)參數(shù),
     * 然后還是以二進制格式檢索結(jié)果。
     *
     * 盡管我們告訴 PQexecParams,我們讓后端推導(dǎo)參數(shù)類型,
     * 實際上我們通過在查詢字串里轉(zhuǎn)換參數(shù)符號的方法強制了決定的做出。
     * 在發(fā)送二進制參數(shù)的時候,這是一個很好的安全檢查。
     */

	/* 把整數(shù)值 "2" 轉(zhuǎn)換成網(wǎng)絡(luò)字節(jié)序 */

    binaryIntVal = htonl((uint32_t) 2);

	 /* 為 PQexecParams 設(shè)置參數(shù)數(shù)組 */

    paramValues[0] = (char *) &binaryIntVal;
    paramLengths[0] = sizeof(binaryIntVal);
    paramFormats[0] = 1;        /*二進制 */

    res = PQexecParams(conn,
                       "SELECT * FROM test1 WHERE i = $1::int4",
                       1,/*一個參數(shù)*/
                       NULL,/* 讓后端推導(dǎo)參數(shù)類型*/
                       paramValues,
                       paramLengths,
                       paramFormats,
                       1);      /* 要求二進制結(jié)果 */

    if (PQresultStatus(res) != PGRES_TUPLES_OK)
    {
        fprintf(stderr,"SELECT failed: %s",PQerrorMessage(conn));
        PQclear(res);
        exit_nicely(conn);
    }

    show_binary_results(res);

    PQclear(res);

    /* 關(guān)閉與數(shù)據(jù)庫的連接并清理 */

    PQfinish(conn);

    return 0;
}
Previous article: Next article: