Hex Artifact Content
Not logged in

Artifact 39b4d79fa8591c049cda6963300a1d507fe3d99b:

Wiki page [tutorial] by sandro 2018-07-16 11:18:01.
0000: 44 20 32 30 31 38 2d 30 37 2d 31 36 54 31 31 3a  D 2018-07-16T11:
0010: 31 38 3a 30 31 2e 35 38 37 0a 4c 20 74 75 74 6f  18:01.587.L tuto
0020: 72 69 61 6c 0a 50 20 37 30 31 65 65 61 38 65 34  rial.P 701eea8e4
0030: 38 66 36 33 30 64 38 66 63 33 39 38 66 64 34 34  8f630d8fc398fd44
0040: 64 36 37 33 36 65 38 33 63 33 63 37 62 62 32 0a  d6736e83c3c7bb2.
0050: 55 20 73 61 6e 64 72 6f 0a 57 20 32 31 30 34 36  U sandro.W 21046
0060: 0a 42 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 74  .Back to <b>Virt
0070: 75 61 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 65  ualPG</b> <a hre
0080: 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67  f="https://www.g
0090: 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69  aia-gis.it/fossi
00a0: 6c 2f 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 65  l/virtualpg/inde
00b0: 78 22 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 3e  x">home page</a>
00c0: 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 32 3e  ..<br><br>..<h2>
00d0: 55 70 64 61 74 65 64 20 64 6f 63 75 6d 65 6e 74  Updated document
00e0: 61 74 69 6f 6e 20 73 75 70 70 6f 72 74 69 6e 67  ation supporting
00f0: 20 56 69 72 74 75 61 6c 50 47 20 76 32 3c 2f 68   VirtualPG v2</h
0100: 32 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73  2>..<table cells
0110: 70 61 63 69 6e 67 3d 22 36 22 20 63 65 6c 6c 70  pacing="6" cellp
0120: 61 64 64 69 6e 67 3d 22 36 22 20 62 67 63 6f 6c  adding="6" bgcol
0130: 6f 72 3d 22 23 66 66 64 30 38 30 22 3e 3c 74 72  or="#ffd080"><tr
0140: 3e 3c 74 64 3e 0d 0a 3c 68 33 3e 57 61 72 6e 69  ><td>..<h3>Warni
0150: 6e 67 3c 2f 68 33 3e 0d 0a 54 68 65 20 66 6f 6c  ng</h3>..The fol
0160: 6c 6f 77 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69  lowing informati
0170: 6f 6e 73 20 63 6f 72 72 65 73 70 6f 6e 64 20 74  ons correspond t
0180: 6f 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e  o the most recen
0190: 74 20 3c 62 3e 56 65 72 73 69 6f 6e 20 32 3c 2f  t <b>Version 2</
01a0: 62 3e 20 6f 66 20 56 69 72 74 75 61 6c 50 47 2c  b> of VirtualPG,
01b0: 20 61 6e 64 20 63 6f 75 6c 64 20 6e 6f 74 20 61   and could not a
01c0: 6c 77 61 79 73 20 61 64 65 71 75 61 74 65 6c 79  lways adequately
01d0: 20 63 6f 76 65 72 20 74 68 65 20 70 72 65 76 69   cover the previ
01e0: 6f 75 73 20 76 65 72 73 69 6f 6e 73 2c 20 74 68  ous versions, th
01f0: 61 74 20 61 72 65 20 6e 6f 77 20 64 65 63 6c 61  at are now decla
0200: 72 65 64 20 6f 62 73 6f 6c 65 74 65 2e 3c 62 72  red obsolete.<br
0210: 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20 73 74  >..If you are st
0220: 69 6c 6c 20 75 73 69 6e 67 20 61 6e 79 20 70 72  ill using any pr
0230: 65 76 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 79  evious version y
0240: 6f 75 20 61 72 65 20 77 61 72 6d 6c 79 20 72 65  ou are warmly re
0250: 63 63 6f 6d 6d 65 6e 64 65 64 20 74 6f 20 71 75  ccommended to qu
0260: 69 63 6b 6c 79 20 75 70 64 61 74 65 20 79 6f 75  ickly update you
0270: 72 20 73 6f 66 74 77 61 72 65 2e 0d 0a 3c 2f 74  r software...</t
0280: 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d  d></tr></table>.
0290: 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c  .<br><br>..<tabl
02a0: 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 36  e cellspacing="6
02b0: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36  " cellpadding="6
02c0: 22 20 62 67 63 6f 6c 6f 72 3d 22 23 64 30 66 66  " bgcolor="#d0ff
02d0: 38 30 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 68  80"><tr><td>..<h
02e0: 33 3e 53 68 6f 72 74 20 73 75 6d 6d 61 72 79 20  3>Short summary 
02f0: 6f 66 20 64 69 66 66 65 72 65 6e 63 65 73 20 62  of differences b
0300: 65 74 77 65 65 6e 20 65 61 72 6c 69 65 72 20 76  etween earlier v
0310: 65 72 73 69 6f 6e 73 20 61 6e 64 20 76 32 3c 2f  ersions and v2</
0320: 68 33 3e 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 6e  h3>..<ol>..<li>n
0330: 6f 77 20 56 69 72 74 75 61 6c 50 47 20 69 73 20  ow VirtualPG is 
0340: 61 76 61 69 6c 61 62 6c 65 20 61 73 20 20 62 6f  available as  bo
0350: 74 68 20 61 20 73 74 61 6e 64 61 72 64 20 43 2f  th a standard C/
0360: 43 2b 2b 20 6c 69 62 72 61 72 79 20 28 3c 62 3e  C++ library (<b>
0370: 6c 69 62 76 69 72 74 75 61 6c 70 67 3c 2f 62 3e  libvirtualpg</b>
0380: 29 20 61 6e 64 20 61 20 64 79 6e 61 6d 69 63 20  ) and a dynamic 
0390: 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65  extension module
03a0: 20 74 6f 20 53 51 4c 69 74 65 20 28 3c 62 3e 6d   to SQLite (<b>m
03b0: 6f 64 5f 76 69 72 74 75 61 6c 70 67 3c 2f 62 3e  od_virtualpg</b>
03c0: 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 6e 6f 77  ).</li>..<li>now
03d0: 20 74 68 65 20 75 73 65 72 20 63 61 6e 20 66 72   the user can fr
03e0: 65 65 6c 79 20 63 68 6f 6f 73 65 20 68 69 73 2f  eely choose his/
03f0: 68 65 72 20 70 72 65 66 65 72 72 65 64 20 66 6f  her preferred fo
0400: 72 6d 61 74 20 66 6f 72 20 44 41 54 45 20 2f 20  rmat for DATE / 
0410: 54 49 4d 45 20 2f 20 54 49 4d 45 53 54 41 4d 50  TIME / TIMESTAMP
0420: 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c   values.</li>..<
0430: 6c 69 3e 54 72 61 6e 73 61 63 74 69 6f 6e 73 20  li>Transactions 
0440: 28 42 45 47 49 4e 20 2f 20 43 4f 4d 4d 49 54 20  (BEGIN / COMMIT 
0450: 2f 20 52 4f 4c 4c 42 41 43 4b 29 20 61 72 65 20  / ROLLBACK) are 
0460: 6e 6f 77 20 66 75 6c 6c 79 20 68 6f 6e 6f 75 72  now fully honour
0470: 65 64 20 61 6c 73 6f 20 6f 6e 20 74 68 65 20 50  ed also on the P
0480: 6f 73 74 67 72 65 53 51 4c 20 73 69 64 65 2e 3c  ostgreSQL side.<
0490: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 57 72 69 74 65 20  /li>..<li>Write 
04a0: 6f 70 65 72 61 74 69 6f 6e 73 20 28 49 4e 53 45  operations (INSE
04b0: 52 20 2f 20 55 50 44 41 54 45 20 2f 20 44 45 4c  R / UPDATE / DEL
04c0: 45 54 45 29 20 61 72 65 20 6e 6f 77 20 61 6c 6c  ETE) are now all
04d0: 6f 77 65 64 20 6f 6e 6c 79 20 69 66 20 74 68 65  owed only if the
04e0: 20 50 6f 73 74 67 72 65 53 51 4c 20 75 73 65 72   PostgreSQL user
04f0: 20 68 61 73 20 74 68 65 20 63 6f 72 72 65 73 70   has the corresp
0500: 6f 6e 64 69 6e 67 20 47 52 41 4e 54 20 70 65 72  onding GRANT per
0510: 6d 69 73 73 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d 0a  missions.</li>..
0520: 3c 6c 69 3e 57 72 69 74 65 20 6f 70 65 72 61 74  <li>Write operat
0530: 69 6f 6e 73 20 63 61 6e 20 62 65 20 65 6e 61 62  ions can be enab
0540: 6c 65 64 20 6f 6e 6c 79 20 66 6f 72 20 50 6f 73  led only for Pos
0550: 74 67 72 65 53 51 4c 20 54 61 62 6c 65 73 20 65  tgreSQL Tables e
0560: 78 70 6c 69 63 69 74 6c 79 20 64 65 63 6c 61 72  xplicitly declar
0570: 69 6e 67 20 61 20 50 52 49 4d 41 52 59 20 4b 45  ing a PRIMARY KE
0580: 59 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a  Y.</li>..</ol>..
0590: 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c  </td></tr></tabl
05a0: 65 3e 0d 0a 3c 68 32 3e 61 62 6f 75 74 20 56 69  e>..<h2>about Vi
05b0: 72 74 75 61 6c 50 47 3c 2f 68 32 3e 0d 0a 3c 62  rtualPG</h2>..<b
05c0: 3e 56 69 72 74 75 61 6c 50 47 20 32 3c 2f 62 3e  >VirtualPG 2</b>
05d0: 20 69 73 20 61 76 61 69 6c 61 62 6c 65 20 62 6f   is available bo
05e0: 74 68 20 61 73 20 61 20 3c 69 3e 63 6c 61 73 73  th as a <i>class
05f0: 69 63 20 3c 62 3e 43 2f 43 2b 2b 3c 2f 62 3e 20  ic <b>C/C++</b> 
0600: 6c 69 62 72 61 72 79 3c 2f 69 3e 20 61 6e 64 20  library</i> and 
0610: 61 73 20 61 20 3c 69 3e 6c 6f 61 64 61 62 6c 65  as a <i>loadable
0620: 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69   dynamic extensi
0630: 6f 6e 20 6d 6f 64 75 6c 65 3c 2f 69 3e 20 66 6f  on module</i> fo
0640: 72 20 62 6f 74 68 20 3c 62 3e 53 51 4c 69 74 65  r both <b>SQLite
0650: 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 53 70 61 74  </b> and <b>Spat
0660: 69 61 4c 69 74 65 3c 2f 62 3e 2e 3c 62 72 3e 0d  iaLite</b>.<br>.
0670: 0a 54 68 65 20 69 6e 74 65 6e 64 65 64 20 73 63  .The intended sc
0680: 6f 70 65 20 6f 66 20 56 69 72 74 75 61 6c 50 47  ope of VirtualPG
0690: 20 69 73 20 73 75 70 70 6f 72 74 69 6e 67 20 64   is supporting d
06a0: 69 72 65 63 74 20 64 61 74 61 20 65 78 63 68 61  irect data excha
06b0: 6e 67 65 20 66 6f 72 6d 2f 74 6f 20 3c 62 3e 50  nge form/to <b>P
06c0: 6f 73 74 67 72 65 53 51 4c 3c 2f 62 3e 20 2f 20  ostgreSQL</b> / 
06d0: 3c 62 3e 50 6f 73 74 47 49 53 3c 2f 62 3e 20 74  <b>PostGIS</b> t
06e0: 61 72 67 65 74 73 20 61 6e 64 20 3c 62 3e 53 51  argets and <b>SQ
06f0: 4c 69 74 65 3c 2f 62 3e 20 73 69 6d 70 6c 79 20  Lite</b> simply 
0700: 75 73 69 6e 67 20 62 61 73 69 63 2c 20 70 6c 61  using basic, pla
0710: 69 6e 20 3c 69 3e 53 51 4c 20 73 74 61 74 65 6d  in <i>SQL statem
0720: 65 6e 74 73 3c 2f 69 3e 2e 3c 62 72 3e 3c 62 72  ents</i>.<br><br
0730: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 56 69 72  >..<hr>..<h3>Vir
0740: 74 75 61 6c 50 47 20 61 73 20 61 20 73 74 61 6e  tualPG as a stan
0750: 64 61 72 64 20 43 2f 43 2b 2b 20 6c 69 62 72 61  dard C/C++ libra
0760: 72 79 3c 2f 68 33 3e 0d 0a 54 68 65 72 65 20 69  ry</h3>..There i
0770: 73 20 76 65 72 79 20 6c 69 74 74 6c 65 20 74 6f  s very little to
0780: 20 73 61 79 20 61 62 6f 75 74 20 56 69 72 74 75   say about Virtu
0790: 61 6c 50 47 20 61 73 20 61 20 6c 69 62 72 61 72  alPG as a librar
07a0: 79 2c 20 62 65 63 61 75 73 65 20 69 74 20 69 6d  y, because it im
07b0: 70 6c 65 6d 65 6e 74 73 20 6a 75 73 74 20 74 77  plements just tw
07c0: 6f 20 43 20 66 75 6e 63 74 69 6f 6e 73 3a 0d 0a  o C functions:..
07d0: 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52  <ol>..<li><b>VIR
07e0: 54 55 41 4c 50 47 5f 44 45 43 4c 41 52 45 20 63  TUALPG_DECLARE c
07f0: 6f 6e 73 74 20 63 68 61 72 20 2a 76 69 72 74 75  onst char *virtu
0800: 61 6c 70 67 5f 76 65 72 73 69 6f 6e 20 28 76 6f  alpg_version (vo
0810: 69 64 29 3b 3c 2f 62 3e 0d 0a 3c 75 6c 3e 0d 0a  id);</b>..<ul>..
0820: 3c 6c 69 3e 74 68 69 73 20 66 69 72 73 74 20 41  <li>this first A
0830: 50 49 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74  PI will return t
0840: 68 65 20 63 75 72 72 65 6e 74 20 76 65 72 73 69  he current versi
0850: 6f 6e 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72  on of the librar
0860: 79 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f  y.</li>..</ul></
0870: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 49 52 54  li>..<li><b>VIRT
0880: 55 41 4c 50 47 5f 44 45 43 4c 41 52 45 20 69 6e  UALPG_DECLARE in
0890: 74 20 76 69 72 74 75 61 6c 70 67 5f 65 78 74 65  t virtualpg_exte
08a0: 6e 73 69 6f 6e 5f 69 6e 69 74 20 28 73 71 6c 69  nsion_init (sqli
08b0: 74 65 33 20 2a 64 62 5f 68 61 6e 64 6c 65 29 3b  te3 *db_handle);
08c0: 3c 2f 62 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  </b>..<ul>..<li>
08d0: 74 68 69 73 20 73 65 63 6f 6e 64 20 41 50 49 20  this second API 
08e0: 69 73 20 69 6e 74 65 6e 65 64 20 74 6f 20 69 6e  is intened to in
08f0: 69 74 69 61 6c 69 7a 65 20 74 68 65 20 56 69 72  itialize the Vir
0900: 74 75 61 6c 50 47 20 65 78 74 65 6e 73 69 6f 6e  tualPG extension
0910: 20 6d 6f 64 75 6c 65 3a 0d 0a 3c 75 6c 3e 0d 0a   module:..<ul>..
0920: 3c 6c 69 3e 3c 62 3e 64 62 5f 68 61 6e 64 6c 65  <li><b>db_handle
0930: 3c 2f 62 3e 20 6d 75 73 74 20 62 65 20 61 20 76  </b> must be a v
0940: 61 6c 69 64 20 68 61 6e 64 6c 65 20 74 6f 20 73  alid handle to s
0950: 6f 6d 65 20 61 6c 72 65 61 64 79 20 65 73 74 61  ome already esta
0960: 62 6c 69 73 68 65 64 20 53 51 4c 69 74 65 20 63  blished SQLite c
0970: 6f 6e 6e 65 63 74 69 6f 6e 2e 3c 2f 6c 69 3e 0d  onnection.</li>.
0980: 0a 3c 6c 69 3e 74 68 65 20 72 65 74 75 72 6e 20  .<li>the return 
0990: 76 61 6c 75 65 20 77 69 6c 6c 20 62 65 20 3c 62  value will be <b
09a0: 3e 53 51 4c 49 54 45 5f 4f 4b 3c 2f 62 3e 20 69  >SQLITE_OK</b> i
09b0: 66 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e 20  f the extension 
09c0: 6d 6f 64 75 6c 65 20 68 61 73 20 62 65 65 6e 20  module has been 
09d0: 73 75 63 63 65 73 66 75 6c 6c 79 20 20 69 6e 69  succesfully  ini
09e0: 74 69 61 6c 69 7a 65 64 2e 3c 2f 6c 69 3e 0d 0a  tialized.</li>..
09f0: 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  </ul></li>..</ul
0a00: 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c  ></li>..</ol>..<
0a10: 62 3e 4e 6f 74 65 73 3c 2f 62 3e 3a 3c 62 72 3e  b>Notes</b>:<br>
0a20: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20  ..<ul>..<li>the 
0a30: 3c 62 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e  <b>VirtualPG</b>
0a40: 20 65 78 74 65 6e 73 69 6f 6e 20 64 6f 65 73 20   extension does 
0a50: 6e 6f 74 20 6e 65 63 65 73 73 61 72 69 6c 79 20  not necessarily 
0a60: 72 65 71 75 69 72 65 20 74 6f 20 62 65 20 73 75  require to be su
0a70: 70 70 6f 72 74 65 64 20 62 79 20 74 68 65 20 3c  pported by the <
0a80: 62 3e 53 70 61 74 69 61 4c 69 74 65 3c 2f 62 3e  b>SpatiaLite</b>
0a90: 20 65 78 74 65 6e 73 69 6f 6e 3b 20 74 68 65 79   extension; they
0aa0: 20 61 72 65 20 69 6e 64 65 70 65 6e 64 65 6e 74   are independent
0ab0: 20 74 68 65 20 6f 6e 65 20 66 72 6f 6d 20 74 68   the one from th
0ac0: 65 20 6f 74 68 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c  e other.</li>..<
0ad0: 6c 69 3e 74 68 65 20 72 65 6c 61 74 69 76 65 20  li>the relative 
0ae0: 6f 72 64 65 72 20 69 6e 20 77 68 69 63 68 20 74  order in which t
0af0: 68 65 20 74 77 6f 20 65 78 74 65 6e 73 69 6f 6e  he two extension
0b00: 73 20 61 72 65 20 65 76 65 6e 74 75 61 6c 6c 79  s are eventually
0b10: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 69 73 20   initialized is 
0b20: 61 62 73 6f 6c 75 74 65 6c 79 20 6e 6f 74 20 72  absolutely not r
0b30: 65 6c 65 76 61 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c  elevant.</li>..<
0b40: 6c 69 3e 68 6f 77 65 76 65 72 2c 20 77 68 65 6e  li>however, when
0b50: 20 56 69 72 74 75 61 6c 50 47 20 69 73 20 62 61   VirtualPG is ba
0b60: 63 6b 65 64 20 75 70 20 62 79 20 53 70 61 74 69  cked up by Spati
0b70: 61 4c 69 74 65 2c 20 79 6f 75 27 6c 6c 20 61 6c  aLite, you'll al
0b80: 77 61 79 73 20 62 65 20 61 62 6c 65 20 74 6f 20  ways be able to 
0b90: 65 6e 71 75 69 72 79 20 69 6e 20 66 75 6c 6c 20  enquiry in full 
0ba0: 64 65 74 61 69 6c 20 61 6e 79 20 65 72 72 6f 72  detail any error
0bb0: 20 6d 65 73 73 61 67 65 20 72 61 69 73 65 64 20   message raised 
0bc0: 62 79 20 50 6f 73 74 67 72 65 53 51 4c 20 62 79  by PostgreSQL by
0bd0: 20 63 61 6c 6c 69 6e 67 20 74 68 65 20 53 51 4c   calling the SQL
0be0: 20 66 75 6e 63 74 69 6f 6e 20 3c 62 3e 50 6f 73   function <b>Pos
0bf0: 74 67 72 65 53 71 6c 5f 47 65 74 4c 61 73 74 4d  tgreSql_GetLastM
0c00: 65 73 73 61 67 65 28 29 3c 2f 62 3e 2e 3c 62 72  essage()</b>.<br
0c10: 3e 0d 0a 74 68 69 73 20 69 73 20 61 20 72 65 61  >..this is a rea
0c20: 6c 6c 79 20 75 73 65 66 75 6c 20 64 69 61 67 6e  lly useful diagn
0c30: 6f 73 74 69 63 20 66 75 6e 63 74 69 6f 6e 2c 20  ostic function, 
0c40: 61 6e 64 20 77 69 6c 6c 20 67 72 65 61 74 6c 79  and will greatly
0c50: 20 69 6d 70 72 6f 76 65 20 74 68 65 20 75 73 61   improve the usa
0c60: 62 69 6c 69 74 79 20 6f 66 20 56 69 72 74 75 61  bility of Virtua
0c70: 6c 50 47 2c 20 61 6c 6c 6f 77 69 6e 67 20 66 6f  lPG, allowing fo
0c80: 72 20 61 20 73 69 6d 70 6c 69 66 69 65 64 20 61  r a simplified a
0c90: 6e 64 20 65 61 73 69 65 72 20 64 65 62 75 67 67  nd easier debugg
0ca0: 69 6e 67 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 77  ing.</li>..<li>w
0cb0: 68 65 6e 20 53 70 61 74 69 61 4c 69 74 65 27 73  hen SpatiaLite's
0cc0: 20 73 75 70 70 6f 72 74 20 69 73 20 75 6e 61 76   support is unav
0cd0: 61 69 6c 61 62 6c 65 2c 20 56 69 72 74 75 61 6c  ailable, Virtual
0ce0: 50 47 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 61  PG will simply a
0cf0: 74 74 65 6d 70 74 20 74 6f 20 6f 75 74 70 75 74  ttempt to output
0d00: 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73 61   the error messa
0d10: 67 65 20 63 6f 6d 69 6e 67 20 66 72 6f 6d 20 50  ge coming from P
0d20: 6f 73 74 67 72 65 53 51 4c 20 6f 6e 20 74 68 65  ostgreSQL on the
0d30: 20 73 74 61 6e 64 61 72 64 20 65 72 72 6f 72 20   standard error 
0d40: 28 69 66 20 61 76 61 69 6c 61 62 6c 65 29 2e 3c  (if available).<
0d50: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f 74  /li>..<li><b>Not
0d60: 65 3c 2f 62 3e 3a 20 74 68 65 20 64 69 61 67 6e  e</b>: the diagn
0d70: 6f 73 74 69 63 20 53 51 4c 20 66 75 6e 63 74 69  ostic SQL functi
0d80: 6f 6e 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c  on <b>PostgreSQL
0d90: 5f 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 20  _GetLastError() 
0da0: 3c 2f 62 3e 72 65 71 75 69 72 65 73 20 75 73 69  </b>requires usi
0db0: 6e 67 20 53 70 61 74 69 61 4c 69 74 65 20 76 65  ng SpatiaLite ve
0dc0: 72 73 69 6f 6e 20 35 2e 30 2e 30 20 6f 72 20 6c  rsion 5.0.0 or l
0dd0: 61 74 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  ater.</li>..</ul
0de0: 3e 3c 62 72 3e 0d 0a 3c 62 3e 61 20 76 65 72 79  ><br>..<b>a very
0df0: 20 73 6b 65 6c 65 74 61 6c 20 43 20 73 6f 75 72   skeletal C sour
0e00: 63 65 20 73 61 6d 70 6c 65 3c 2f 62 3e 0d 0a 3c  ce sample</b>..<
0e10: 76 65 72 62 61 74 69 6d 3e 0d 0a 23 69 6e 63 6c  verbatim>..#incl
0e20: 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0d 0a  ude <stdlib.h>..
0e30: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e  #include <stdio.
0e40: 68 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73 71  h>..#include <sq
0e50: 6c 69 74 65 33 2e 68 3e 0d 0a 23 69 6e 63 6c 75  lite3.h>..#inclu
0e60: 64 65 20 3c 76 69 72 74 75 61 6c 70 67 2e 68 3e  de <virtualpg.h>
0e70: 0d 0a 0d 0a 69 6e 74 0d 0a 6d 61 69 6e 20 28 69  ....int..main (i
0e80: 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a 61  nt argc, char *a
0e90: 72 67 76 5b 5d 29 0d 0a 7b 0d 0a 20 20 20 20 63  rgv[])..{..    c
0ea0: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 20  onst char *path 
0eb0: 3d 20 2e 2e 2e 20 73 6f 6d 65 20 76 61 6c 75 65  = ... some value
0ec0: 20 2e 2e 2e 2e 0d 0a 20 20 20 20 73 71 6c 69 74   ......    sqlit
0ed0: 65 33 20 2a 68 61 6e 64 6c 65 3b 0d 0a 20 20 20  e3 *handle;..   
0ee0: 20 69 6e 74 20 72 65 74 3b 0d 0a 0d 0a 2f 2a 20   int ret;..../* 
0ef0: 6f 70 65 6e 69 6e 67 20 74 68 65 20 53 51 4c 69  opening the SQLi
0f00: 74 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f  te connection */
0f10: 0d 0a 20 20 20 20 72 65 74 20 3d 20 73 71 6c 69  ..    ret = sqli
0f20: 74 65 33 5f 6f 70 65 6e 5f 76 32 20 28 70 61 74  te3_open_v2 (pat
0f30: 68 2c 20 26 68 61 6e 64 6c 65 2c 20 53 51 4c 49  h, &handle, SQLI
0f40: 54 45 5f 4f 50 45 4e 5f 52 45 41 44 57 52 49 54  TE_OPEN_READWRIT
0f50: 45 2c 20 4e 55 4c 4c 29 3b 0d 0a 20 20 20 20 69  E, NULL);..    i
0f60: 66 20 28 72 65 74 20 21 3d 20 53 51 4c 49 54 45  f (ret != SQLITE
0f70: 5f 4f 4b 29 0d 0a 20 20 20 20 7b 0d 0a 20 20 20  _OK)..    {..   
0f80: 20 20 20 20 20 2e 2e 2e 20 65 72 72 6f 72 20 68       ... error h
0f90: 61 6e 64 6c 69 6e 67 20 2e 2e 2e 0d 0a 20 20 20  andling .....   
0fa0: 20 7d 0d 0a 0d 0a 2f 2a 20 69 6e 69 74 69 61 6c   }..../* initial
0fb0: 69 7a 69 6e 67 20 56 69 72 74 75 61 6c 50 47 20  izing VirtualPG 
0fc0: 2a 2f 0d 0a 20 20 20 20 72 65 74 20 3d 20 76 69  */..    ret = vi
0fd0: 72 74 75 61 6c 70 67 5f 65 78 74 65 6e 73 69 6f  rtualpg_extensio
0fe0: 6e 5f 69 6e 69 74 20 28 68 61 6e 64 6c 65 29 3b  n_init (handle);
0ff0: 0d 0a 20 20 20 20 69 66 20 28 72 65 74 20 21 3d  ..    if (ret !=
1000: 20 53 51 4c 49 54 45 5f 4f 4b 29 0d 0a 20 20 20   SQLITE_OK)..   
1010: 20 7b 0d 0a 20 20 20 20 20 20 20 20 2e 2e 2e 20   {..        ... 
1020: 65 72 72 6f 72 20 68 61 6e 64 6c 69 6e 67 20 2e  error handling .
1030: 2e 2e 0d 0a 20 20 20 20 7d 0d 0a 20 20 20 20 65  ....    }..    e
1040: 6c 73 65 0d 0a 20 20 20 20 20 20 20 20 66 70 72  lse..        fpr
1050: 69 6e 74 66 20 28 73 74 64 65 72 72 2c 20 22 6f  intf (stderr, "o
1060: 6b 2c 20 56 69 72 74 75 61 6c 50 47 20 73 75 63  k, VirtualPG suc
1070: 63 65 73 66 75 6c 6c 79 20 69 6e 69 74 69 61 6c  cesfully initial
1080: 69 7a 65 64 5c 6e 22 29 3b 0d 0a 0d 0a 2f 2a 20  ized\n");..../* 
1090: 64 69 73 63 6f 6e 6e 65 63 74 69 6e 67 20 66 72  disconnecting fr
10a0: 6f 6d 20 53 51 4c 69 74 65 20 61 6e 64 20 65 78  om SQLite and ex
10b0: 69 74 69 6e 67 20 2a 2f 0d 0a 20 20 20 20 73 71  iting */..    sq
10c0: 6c 69 74 65 33 5f 63 6c 6f 73 65 20 28 68 61 6e  lite3_close (han
10d0: 64 6c 65 29 3b 0d 0a 20 20 20 20 72 65 74 75 72  dle);..    retur
10e0: 6e 20 30 3b 0d 0a 7d 0d 0a 3c 2f 76 65 72 62 61  n 0;..}..</verba
10f0: 74 69 6d 3e 3c 62 72 3e 0d 0a 3c 62 3e 4c 69 6e  tim><br>..<b>Lin
1100: 6b 20 64 69 72 65 63 74 69 76 65 73 3c 2f 62 3e  k directives</b>
1110: 3c 62 72 3e 0d 0a 74 68 65 20 61 62 6f 76 65 20  <br>..the above 
1120: 43 20 73 61 6d 70 6c 65 20 6f 62 76 69 6f 75 73  C sample obvious
1130: 6c 79 20 72 65 71 75 69 72 65 73 20 74 6f 20 6c  ly requires to l
1140: 69 6e 6b 20 62 6f 74 68 20 3c 62 3e 6c 69 62 73  ink both <b>libs
1150: 71 6c 69 74 65 33 3c 2f 62 3e 20 61 6e 64 20 3c  qlite3</b> and <
1160: 62 3e 6c 69 62 76 69 72 74 75 61 6c 70 67 3c 2f  b>libvirtualpg</
1170: 62 3e 20 62 75 74 20 74 68 69 73 20 6c 61 74 65  b> but this late
1180: 72 20 64 65 70 65 6e 64 73 20 6f 6e 20 3c 62 3e  r depends on <b>
1190: 6c 69 62 70 71 3c 2f 62 3e 2c 20 74 68 65 20 50  libpq</b>, the P
11a0: 6f 73 74 67 72 65 53 51 4c 20 63 6c 69 65 6e 74  ostgreSQL client
11b0: 20 6c 69 62 72 61 72 79 2e 3c 62 72 3e 0d 0a 73   library.<br>..s
11c0: 6f 20 74 68 65 73 65 20 61 72 65 20 74 68 65 20  o these are the 
11d0: 72 65 71 75 69 72 65 64 20 64 69 72 65 63 74 69  required directi
11e0: 76 65 73 20 66 6f 72 20 61 20 73 75 63 63 65 73  ves for a succes
11f0: 66 75 6c 20 6c 69 6e 6b 69 6e 67 3a 20 3c 62 3e  ful linking: <b>
1200: 2d 6c 76 69 72 74 75 61 6c 70 67 20 2d 6c 73 71  -lvirtualpg -lsq
1210: 6c 69 74 65 33 20 2d 6c 70 71 3c 2f 62 3e 0d 0a  lite3 -lpq</b>..
1220: 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a  <br><br>..<hr>..
1230: 3c 68 33 3e 56 69 72 74 75 61 6c 50 47 20 61 73  <h3>VirtualPG as
1240: 20 61 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e   a dynamic exten
1250: 73 69 6f 6e 20 6d 6f 64 75 6c 65 3c 2f 68 33 3e  sion module</h3>
1260: 0d 0a 54 68 65 20 65 78 74 65 6e 73 69 6f 6e 20  ..The extension 
1270: 6d 6f 64 75 6c 65 20 73 69 6d 70 6c 79 20 69 73  module simply is
1280: 20 61 6e 20 6f 72 64 69 6e 61 72 79 20 3c 69 3e   an ordinary <i>
1290: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 3c  dynamic library<
12a0: 2f 69 3e 20 28 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e  /i> (<b>.dll</b>
12b0: 20 6f 6e 20 57 69 6e 64 6f 77 73 2c 20 3c 62 3e   on Windows, <b>
12c0: 2e 73 6f 3c 2f 62 3e 20 6f 6e 20 55 6e 69 78 20  .so</b> on Unix 
12d0: 61 6e 64 20 4c 69 6e 75 78 2c 20 3c 62 3e 2e 64  and Linux, <b>.d
12e0: 79 6c 69 62 3c 2f 62 3e 20 6f 6e 20 4d 61 63 20  ylib</b> on Mac 
12f0: 4f 73 20 58 29 3b 20 73 6f 20 74 68 65 20 66 69  Os X); so the fi
1300: 72 73 74 20 74 68 69 6e 67 20 74 6f 20 62 65 20  rst thing to be 
1310: 64 6f 6e 65 20 69 6e 20 6f 72 64 65 72 20 74 6f  done in order to
1320: 20 61 63 74 69 76 61 74 65 20 74 68 69 73 20 65   activate this e
1330: 78 74 65 6e 73 69 6f 6e 20 69 73 20 6c 6f 61 64  xtension is load
1340: 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 70 6f  ing the correspo
1350: 6e 64 69 6e 67 20 6c 69 62 72 61 72 79 20 66 72  nding library fr
1360: 6f 6d 20 61 20 76 61 6c 69 64 20 53 51 4c 69 74  om a valid SQLit
1370: 65 2f 53 70 61 74 69 61 4c 69 74 65 20 63 6f 6e  e/SpatiaLite con
1380: 6e 65 63 74 69 6f 6e 2e 0d 0a 3c 76 65 72 62 61  nection...<verba
1390: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6c 6f 61  tim>..SELECT loa
13a0: 64 5f 65 78 74 65 6e 73 69 6f 6e 28 27 6d 6f 64  d_extension('mod
13b0: 5f 76 69 72 74 75 61 6c 70 67 27 29 3b 0d 0a 2d  _virtualpg');..-
13c0: 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76  -----..NULL..</v
13d0: 65 72 62 61 74 69 6d 3e 0d 0a 3c 62 3e 4e 6f 74  erbatim>..<b>Not
13e0: 65 3c 2f 62 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  e</b>:..<ul>..<l
13f0: 69 3e 74 68 69 73 20 6d 65 63 68 61 6e 69 73 6d  i>this mechanism
1400: 20 6a 75 73 74 20 72 65 6c 69 65 73 20 6f 6e 20   just relies on 
1410: 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 63 61 70  the internal cap
1420: 61 62 69 6c 69 74 69 65 73 20 6f 66 20 53 51 4c  abilities of SQL
1430: 69 74 65 2c 20 73 6f 20 69 74 27 73 20 65 78 70  ite, so it's exp
1440: 65 63 74 65 64 20 74 6f 20 77 6f 72 6b 20 6f 6e  ected to work on
1450: 20 61 6e 79 20 70 6f 73 73 69 62 6c 65 20 6c 61   any possible la
1460: 6e 67 75 61 67 65 3a 20 4a 61 76 61 2c 20 50 79  nguage: Java, Py
1470: 74 68 6f 6e 2c 20 50 48 50 2c 20 43 23 20 61 6e  thon, PHP, C# an
1480: 64 20 73 6f 20 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c  d so on.</li>..<
1490: 6c 69 3e 61 6c 6c 20 72 65 63 65 6e 74 20 76 65  li>all recent ve
14a0: 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65  rsions of SQLite
14b0: 20 61 72 65 20 73 6d 61 72 74 20 65 6e 6f 75 67   are smart enoug
14c0: 68 20 74 6f 20 6e 6f 74 20 72 65 71 75 69 72 65  h to not require
14d0: 20 73 70 65 63 69 66 79 69 6e 67 20 61 6e 79 20   specifying any 
14e0: 70 6c 61 74 66 6f 72 6d 2d 64 65 70 65 6e 64 65  platform-depende
14f0: 6e 74 20 73 75 66 66 69 78 2e 3c 62 72 3e 0d 0a  nt suffix.<br>..
1500: 6a 75 73 74 20 70 61 73 73 69 6e 67 20 3c 62 3e  just passing <b>
1510: 6d 6f 64 5f 73 70 61 74 69 61 6c 69 74 65 3c 2f  mod_spatialite</
1520: 62 3e 20 61 73 20 74 68 65 20 65 78 74 65 6e 73  b> as the extens
1530: 69 6f 6e 20 6e 61 6d 65 20 73 68 6f 75 6c 64 20  ion name should 
1540: 62 65 20 65 6e 6f 75 67 68 20 6f 6e 20 61 6e 79  be enough on any
1550: 20 63 6f 72 72 65 63 74 6c 79 20 63 6f 6e 66 69   correctly confi
1560: 67 75 72 65 64 20 70 6c 61 74 66 6f 72 6d 2e 3c  gured platform.<
1570: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62  /li>..<li>the <b
1580: 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e 20 65  >VirtualPG</b> e
1590: 78 74 65 6e 73 69 6f 6e 20 64 6f 65 73 20 6e 6f  xtension does no
15a0: 74 20 6e 65 63 65 73 73 61 72 69 6c 79 20 72 65  t necessarily re
15b0: 71 75 69 72 65 20 74 6f 20 62 65 20 73 75 70 70  quire to be supp
15c0: 6f 72 74 65 64 20 62 79 20 74 68 65 20 3c 62 3e  orted by the <b>
15d0: 53 70 61 74 69 61 4c 69 74 65 3c 2f 62 3e 20 65  SpatiaLite</b> e
15e0: 78 74 65 6e 73 69 6f 6e 3b 20 74 68 65 79 20 61  xtension; they a
15f0: 72 65 20 69 6e 64 65 70 65 6e 64 65 6e 74 20 74  re independent t
1600: 68 65 20 6f 6e 65 20 66 72 6f 6d 20 74 68 65 20  he one from the 
1610: 6f 74 68 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  other.</li>..<li
1620: 3e 74 68 65 20 72 65 6c 61 74 69 76 65 20 6f 72  >the relative or
1630: 64 65 72 20 69 6e 20 77 68 69 63 68 20 74 68 65  der in which the
1640: 20 74 77 6f 20 65 78 74 65 6e 73 69 6f 6e 73 20   two extensions 
1650: 61 72 65 20 65 76 65 6e 74 75 61 6c 6c 79 20 6c  are eventually l
1660: 6f 61 64 65 65 64 20 69 73 20 61 62 73 6f 6c 75  oadeed is absolu
1670: 74 65 6c 79 20 6e 6f 74 20 72 65 6c 65 76 61 6e  tely not relevan
1680: 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 68 6f 77  t.</li>..<li>how
1690: 65 76 65 72 2c 20 77 68 65 6e 20 56 69 72 74 75  ever, when Virtu
16a0: 61 6c 50 47 20 69 73 20 62 61 63 6b 65 64 20 75  alPG is backed u
16b0: 70 20 62 79 20 53 70 61 74 69 61 4c 69 74 65 2c  p by SpatiaLite,
16c0: 20 79 6f 75 27 6c 6c 20 61 6c 77 61 79 73 20 62   you'll always b
16d0: 65 20 61 62 6c 65 20 74 6f 20 65 6e 71 75 69 72  e able to enquir
16e0: 79 20 69 6e 20 66 75 6c 6c 20 64 65 74 61 69 6c  y in full detail
16f0: 20 61 6e 79 20 65 72 72 6f 72 20 6d 65 73 73 61   any error messa
1700: 67 65 20 72 61 69 73 65 64 20 62 79 20 50 6f 73  ge raised by Pos
1710: 74 67 72 65 53 51 4c 20 62 79 20 63 61 6c 6c 69  tgreSQL by calli
1720: 6e 67 20 74 68 65 20 53 51 4c 20 66 75 6e 63 74  ng the SQL funct
1730: 69 6f 6e 20 3c 62 3e 50 6f 73 74 67 72 65 53 71  ion <b>PostgreSq
1740: 6c 5f 47 65 74 4c 61 73 74 4d 65 73 73 61 67 65  l_GetLastMessage
1750: 28 29 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 74 68 69  ()</b>.<br>..thi
1760: 73 20 69 73 20 61 20 72 65 61 6c 6c 79 20 75 73  s is a really us
1770: 65 66 75 6c 20 64 69 61 67 6e 6f 73 74 69 63 20  eful diagnostic 
1780: 66 75 6e 63 74 69 6f 6e 2c 20 61 6e 64 20 77 69  function, and wi
1790: 6c 6c 20 67 72 65 61 74 6c 79 20 69 6d 70 72 6f  ll greatly impro
17a0: 76 65 20 74 68 65 20 75 73 61 62 69 6c 69 74 79  ve the usability
17b0: 20 6f 66 20 56 69 72 74 75 61 6c 50 47 2c 20 61   of VirtualPG, a
17c0: 6c 6c 6f 77 69 6e 67 20 66 6f 72 20 61 20 73 69  llowing for a si
17d0: 6d 70 6c 69 66 69 65 64 20 61 6e 64 20 65 61 73  mplified and eas
17e0: 69 65 72 20 64 65 62 75 67 67 69 6e 67 2e 3c 2f  ier debugging.</
17f0: 6c 69 3e 0d 0a 3c 6c 69 3e 77 68 65 6e 20 53 70  li>..<li>when Sp
1800: 61 74 69 61 4c 69 74 65 27 73 20 73 75 70 70 6f  atiaLite's suppo
1810: 72 74 20 69 73 20 75 6e 61 76 61 69 6c 61 62 6c  rt is unavailabl
1820: 65 2c 20 56 69 72 74 75 61 6c 50 47 20 77 69 6c  e, VirtualPG wil
1830: 6c 20 73 69 6d 70 6c 79 20 61 74 74 65 6d 70 74  l simply attempt
1840: 20 74 6f 20 6f 75 74 70 75 74 20 74 68 65 20 65   to output the e
1850: 72 72 6f 72 20 6d 65 73 73 61 67 65 20 63 6f 6d  rror message com
1860: 69 6e 67 20 66 72 6f 6d 20 50 6f 73 74 67 72 65  ing from Postgre
1870: 53 51 4c 20 6f 6e 20 74 68 65 20 73 74 61 6e 64  SQL on the stand
1880: 61 72 64 20 65 72 72 6f 72 20 28 69 66 20 61 76  ard error (if av
1890: 61 69 6c 61 62 6c 65 29 2e 3c 2f 6c 69 3e 0d 0a  ailable).</li>..
18a0: 3c 6c 69 3e 3c 62 3e 4e 6f 74 65 3c 2f 62 3e 3a  <li><b>Note</b>:
18b0: 20 74 68 65 20 64 69 61 67 6e 6f 73 74 69 63 20   the diagnostic 
18c0: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 3c 62 3e  SQL function <b>
18d0: 50 6f 73 74 67 72 65 53 51 4c 5f 47 65 74 4c 61  PostgreSQL_GetLa
18e0: 73 74 45 72 72 6f 72 28 29 20 3c 2f 62 3e 72 65  stError() </b>re
18f0: 71 75 69 72 65 73 20 75 73 69 6e 67 20 53 70 61  quires using Spa
1900: 74 69 61 4c 69 74 65 20 76 65 72 73 69 6f 6e 20  tiaLite version 
1910: 35 2e 30 2e 30 20 6f 72 20 6c 61 74 65 72 2e 3c  5.0.0 or later.<
1920: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d  /li>..</ul><br>.
1930: 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73 70 61 63  .<table cellspac
1940: 69 6e 67 3d 22 36 22 20 63 65 6c 6c 70 61 64 64  ing="6" cellpadd
1950: 69 6e 67 3d 22 36 22 20 62 67 63 6f 6c 6f 72 3d  ing="6" bgcolor=
1960: 22 23 66 66 66 66 65 38 22 20 77 69 64 74 68 3d  "#ffffe8" width=
1970: 22 31 30 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64  "100%">..<tr><td
1980: 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e   align="center">
1990: 3c 62 3e 55 73 65 66 75 6c 20 68 69 6e 74 73 20  <b>Useful hints 
19a0: 61 6e 64 20 73 75 67 67 65 73 74 69 6f 6e 73 3a  and suggestions:
19b0: 20 74 72 6f 75 62 6c 65 73 68 6f 6f 74 69 6e 67   troubleshooting
19c0: 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a  </b></td></tr>..
19d0: 3c 74 72 3e 3c 74 64 3e 3c 68 72 3e 3c 2f 74 64  <tr><td><hr></td
19e0: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e  ></tr>..<tr><td>
19f0: 0d 0a 54 68 69 73 20 6f 70 65 72 61 74 69 6f 6e  ..This operation
1a00: 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c   could eventuall
1a10: 79 20 66 61 69 6c 20 66 6f 72 20 73 65 76 65 72  y fail for sever
1a20: 61 6c 20 64 69 66 66 65 72 65 6e 74 20 72 65 61  al different rea
1a30: 73 6f 6e 73 3a 20 68 65 72 65 20 61 72 65 20 74  sons: here are t
1a40: 68 65 20 6d 6f 73 74 20 66 72 65 71 75 65 6e 74  he most frequent
1a50: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 59 6f  s:..<ul>..<li>Yo
1a60: 75 20 61 72 65 20 75 73 69 6e 67 20 73 6f 6d 65  u are using some
1a70: 20 6f 64 64 20 76 65 72 73 69 6f 6e 20 6f 66 20   odd version of 
1a80: 53 51 4c 69 74 65 33 2f 6c 69 62 73 71 6c 69 74  SQLite3/libsqlit
1a90: 65 33 20 66 6f 72 62 69 64 64 69 6e 67 20 74 6f  e3 forbidding to
1aa0: 20 6c 6f 61 64 20 61 6e 79 20 64 79 6e 61 6d 69   load any dynami
1ab0: 63 20 65 78 74 65 6e 73 69 6f 6e 73 2e 3c 62 72  c extensions.<br
1ac0: 3e 0d 0a 54 68 69 73 20 66 65 61 74 75 72 65 20  >..This feature 
1ad0: 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c 79  could eventually
1ae0: 20 62 65 20 64 69 73 61 62 6c 65 64 20 61 74 20   be disabled at 
1af0: 62 75 69 6c 64 20 74 69 6d 65 3b 20 69 66 20 74  build time; if t
1b00: 68 69 73 20 69 73 20 79 6f 75 72 20 63 61 73 65  his is your case
1b10: 20 79 6f 75 20 73 69 6d 70 6c 65 20 68 61 76 65   you simple have
1b20: 20 74 6f 20 73 77 69 74 63 68 20 74 6f 20 73 6f   to switch to so
1b30: 6d 65 20 64 69 66 66 65 72 65 6e 74 20 53 51 4c  me different SQL
1b40: 69 74 65 20 74 6f 6f 6c 6b 69 74 20 73 75 70 70  ite toolkit supp
1b50: 6f 72 74 69 6e 67 20 64 79 6e 61 6d 69 63 20 65  orting dynamic e
1b60: 78 74 65 6e 73 69 6f 6e 73 20 6f 72 20 62 75 69  xtensions or bui
1b70: 6c 64 20 6f 6e 65 20 62 79 20 79 6f 75 72 73 65  ld one by yourse
1b80: 6c 66 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68  lf.</li>..<li>Th
1b90: 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74  e operating syst
1ba0: 65 6d 20 63 6f 75 6c 64 20 62 65 20 75 6e 61 62  em could be unab
1bb0: 6c 65 20 74 6f 20 63 6f 72 72 65 63 74 6c 79 20  le to correctly 
1bc0: 6c 6f 63 61 74 65 20 74 68 65 20 64 79 6e 61 6d  locate the dynam
1bd0: 69 63 20 6c 69 62 72 61 72 79 20 74 6f 20 62 65  ic library to be
1be0: 20 6c 6f 61 64 65 64 2e 3c 62 72 3e 0d 0a 54 68   loaded.<br>..Th
1bf0: 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 76 65  e most recent ve
1c00: 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65  rsions of SQLite
1c10: 20 61 72 65 20 73 6d 61 72 74 20 65 6e 6f 75 67   are smart enoug
1c20: 68 20 74 6f 20 61 75 74 6f 6d 61 74 69 63 61 6c  h to automatical
1c30: 6c 79 20 68 61 6e 64 6c 65 20 61 6e 79 20 70 6c  ly handle any pl
1c40: 61 74 66 6f 72 6d 20 73 70 65 63 69 66 69 63 20  atform specific 
1c50: 73 75 66 66 69 78 3a 20 73 6f 20 79 6f 75 20 61  suffix: so you a
1c60: 72 65 20 6e 6f 20 6c 6f 6e 67 65 72 20 72 65 71  re no longer req
1c70: 75 69 72 65 64 20 74 6f 20 73 70 65 63 69 66 79  uired to specify
1c80: 20 61 6e 79 20 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e   any <b>.dll</b>
1c90: 20 6f 72 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 73   or <b>.so</b> s
1ca0: 75 66 66 69 78 2e 3c 62 72 3e 0d 0a 49 66 20 79  uffix.<br>..If y
1cb0: 6f 75 20 77 69 73 68 20 74 6f 20 64 6f 20 73 6f  ou wish to do so
1cc0: 2c 20 79 6f 75 20 63 61 6e 20 65 76 65 6e 74 75  , you can eventu
1cd0: 61 6c 6c 79 20 73 70 65 63 69 66 79 20 74 68 65  ally specify the
1ce0: 20 66 75 6c 6c 20 70 61 74 68 20 6c 65 61 64 69   full path leadi
1cf0: 6e 67 20 74 6f 20 74 68 65 20 64 79 6e 61 6d 69  ng to the dynami
1d00: 63 20 6c 69 62 72 61 72 79 2c 20 74 68 69 73 20  c library, this 
1d10: 69 6e 63 6c 75 64 69 6e 67 20 61 6e 79 20 73 75  including any su
1d20: 66 66 69 78 2e 3c 62 72 3e 0d 0a 54 68 65 20 64  ffix.<br>..The d
1d30: 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f 75 72  efault behaviour
1d40: 20 6f 66 20 3c 62 3e 6c 6f 61 64 5f 65 78 74 65   of <b>load_exte
1d50: 6e 73 69 6f 6e 28 29 3c 2f 62 3e 20 69 73 20 74  nsion()</b> is t
1d60: 68 65 20 6f 6e 65 20 74 6f 20 73 65 61 72 63 68  he one to search
1d70: 20 74 68 65 20 72 65 71 75 69 72 65 64 20 64 79   the required dy
1d80: 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 20 66 6f  namic library fo
1d90: 6c 6c 6f 77 69 6e 67 20 74 68 65 20 73 74 61 6e  llowing the stan
1da0: 64 61 72 64 20 70 6c 61 74 66 6f 72 6d 20 73 70  dard platform sp
1db0: 65 63 69 66 69 63 20 72 75 6c 65 73 3b 20 70 6c  ecific rules; pl
1dc0: 65 61 73 65 20 63 6f 6e 73 75 6c 74 20 74 68 65  ease consult the
1dd0: 20 61 70 70 72 6f 70 72 69 61 74 65 20 64 6f 63   appropriate doc
1de0: 75 6d 65 6e 74 61 74 69 6f 6e 20 66 6f 72 20 6d  umentation for m
1df0: 6f 72 65 20 73 70 65 63 69 66 69 63 20 64 65 74  ore specific det
1e00: 61 69 6c 73 2e 0d 0a 3c 2f 6c 69 3e 0d 0a 3c 6c  ails...</li>..<l
1e10: 69 3e 54 68 65 20 64 79 6e 61 6d 69 63 20 6c 69  i>The dynamic li
1e20: 62 72 61 72 79 20 69 74 73 65 6c 66 20 63 6f 75  brary itself cou
1e30: 6c 64 20 62 65 20 63 6f 72 72 65 63 74 6c 79 20  ld be correctly 
1e40: 6c 6f 63 61 74 65 64 2c 20 62 75 74 20 73 6f 6d  located, but som
1e50: 65 20 66 75 72 74 68 65 72 20 64 65 70 65 6e 64  e further depend
1e60: 69 6e 67 20 6c 69 62 72 61 72 79 20 63 6f 75 6c  ing library coul
1e70: 64 20 6e 6f 74 2c 20 74 68 75 73 20 66 6f 72 62  d not, thus forb
1e80: 69 64 64 69 6e 67 20 74 6f 20 6c 6f 61 64 20 74  idding to load t
1e90: 68 65 20 6d 61 69 6e 20 6c 69 62 72 61 72 79 2e  he main library.
1ea0: 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20  <br>..<u>Please 
1eb0: 6e 6f 74 65 3c 2f 75 3e 3a 20 3c 62 3e 56 69 72  note</u>: <b>Vir
1ec0: 74 75 61 6c 50 47 3c 2f 62 3e 20 64 65 70 65 6e  tualPG</b> depen
1ed0: 64 73 20 6f 6e 20 74 68 65 20 50 6f 73 74 67 72  ds on the Postgr
1ee0: 65 53 51 4c 20 6f 77 6e 20 63 6c 69 65 6e 74 20  eSQL own client 
1ef0: 6c 69 62 72 61 72 79 20 28 3c 62 3e 6c 69 62 70  library (<b>libp
1f00: 71 3c 2f 62 3e 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  q</b>).</li>..<l
1f10: 69 3e 49 6e 20 61 6e 79 20 63 61 73 65 2c 20 69  i>In any case, i
1f20: 66 20 79 6f 75 20 61 72 65 20 75 73 69 6e 67 20  f you are using 
1f30: 73 6f 6d 65 20 69 6e 74 65 72 61 63 74 69 76 65  some interactive
1f40: 20 74 6f 6f 6c 20 73 75 63 68 20 61 73 20 3c 62   tool such as <b
1f50: 3e 73 71 6c 69 74 65 33 3c 2f 62 3e 20 6f 72 20  >sqlite3</b> or 
1f60: 3c 62 3e 73 70 61 74 69 61 6c 69 74 65 3c 2f 62  <b>spatialite</b
1f70: 3e 20 73 6f 6d 65 20 75 73 65 66 75 6c 20 61 6e  > some useful an
1f80: 64 20 6d 65 61 6e 69 6e 67 66 75 6c 20 65 72 72  d meaningful err
1f90: 6f 72 20 6d 65 73 73 61 67 65 20 77 69 6c 6c 20  or message will 
1fa0: 73 75 72 65 6c 79 20 62 65 20 64 69 73 70 6c 61  surely be displa
1fb0: 79 65 64 20 65 78 70 6c 61 69 6e 69 6e 67 20 74  yed explaining t
1fc0: 68 65 20 66 61 69 6c 75 72 65 20 63 61 75 73 65  he failure cause
1fd0: 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 63 6f 75 6c  .<br>..This coul
1fe0: 64 20 6e 6f 74 20 62 65 20 73 75 70 70 6f 72 74  d not be support
1ff0: 65 64 20 77 68 69 6c 65 20 61 74 74 65 6d 70 74  ed while attempt
2000: 69 6e 67 20 74 6f 20 6c 6f 61 64 20 61 6e 20 65  ing to load an e
2010: 78 74 65 6e 73 69 6f 6e 20 66 72 6f 6d 20 73 6f  xtension from so
2020: 6d 65 20 6c 61 6e 67 75 61 67 65 20 62 69 6e 64  me language bind
2030: 69 6e 67 20 28 65 2e 67 2e 20 3c 62 3e 2e 4e 45  ing (e.g. <b>.NE
2040: 54 3c 2f 62 3e 2c 20 3c 62 3e 50 79 74 68 6f 6e  T</b>, <b>Python
2050: 3c 2f 62 3e 20 6f 72 20 3c 62 3e 4a 61 76 61 3c  </b> or <b>Java<
2060: 2f 62 3e 29 2e 0d 0a 49 6e 20 74 68 69 73 20 63  /b>)...In this c
2070: 61 73 65 20 61 74 74 65 6d 70 74 69 6e 67 20 74  ase attempting t
2080: 6f 20 69 64 65 6e 74 69 66 79 20 74 68 65 20 72  o identify the r
2090: 65 61 6c 20 65 72 72 6f 72 20 63 61 75 73 65 20  eal error cause 
20a0: 63 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79 20  could be really 
20b0: 70 61 69 6e 66 75 6c 20 64 75 65 20 74 6f 20 70  painful due to p
20c0: 6f 6f 72 20 61 6e 64 20 73 6c 6f 70 70 79 20 64  oor and sloppy d
20d0: 69 61 67 6e 6f 73 74 69 63 20 73 75 70 70 6f 72  iagnostic suppor
20e0: 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65  t.</li>..<li>The
20f0: 72 65 20 61 72 65 20 6e 6f 20 75 6e 69 76 65 72  re are no univer
2100: 73 61 6c 20 72 75 6c 65 73 20 64 69 63 74 61 74  sal rules dictat
2110: 69 6e 67 20 77 68 65 72 65 20 74 6f 20 70 6c 61  ing where to pla
2120: 63 65 20 79 6f 75 72 20 65 78 74 65 6e 73 69 6f  ce your extensio
2130: 6e 20 6d 6f 64 75 6c 65 73 3b 20 61 20 67 6f 6f  n modules; a goo
2140: 64 20 73 75 67 67 65 73 74 69 6f 6e 20 69 73 20  d suggestion is 
2150: 74 6f 20 61 6c 77 61 79 73 20 70 6c 61 63 65 20  to always place 
2160: 61 6c 6c 20 74 68 65 6d 20 69 6e 20 74 68 65 20  all them in the 
2170: 6d 6f 73 74 20 61 70 70 72 6f 70 72 69 61 74 65  most appropriate
2180: 20 73 79 73 74 65 6d 20 64 69 72 65 63 74 6f 72   system director
2190: 79 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  y.</li>..</ul>..
21a0: 3c 62 3e 49 6d 70 6f 72 74 61 6e 74 20 6e 6f 74  <b>Important not
21b0: 69 63 65 3c 2f 62 3e 3a 20 73 74 61 72 74 69 6e  ice</b>: startin
21c0: 67 20 73 69 6e 63 65 20 76 65 72 73 69 6f 6e 20  g since version 
21d0: 3c 62 3e 33 2e 37 2e 31 37 3c 2f 62 3e 20 53 51  <b>3.7.17</b> SQ
21e0: 4c 69 74 65 20 69 6e 74 72 6f 64 75 63 65 64 20  Lite introduced 
21f0: 6d 61 6e 79 20 69 6e 74 65 72 65 73 74 69 6e 67  many interesting
2200: 20 61 64 76 61 6e 63 65 64 20 66 65 61 74 75 72   advanced featur
2210: 65 73 20 74 6f 20 3c 62 3e 6c 6f 61 64 5f 65 78  es to <b>load_ex
2220: 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e 3b 0d 0a  tension()</b>;..
2230: 65 61 72 6c 69 65 72 20 76 65 72 73 69 6f 6e 73  earlier versions
2240: 20 6f 66 20 53 51 4c 69 74 65 20 63 6f 75 6c 64   of SQLite could
2250: 20 70 72 6f 62 61 62 6c 79 20 62 65 20 73 6f 6d   probably be som
2260: 65 77 61 79 20 6c 69 6d 69 74 65 64 2e 0d 0a 49  eway limited...I
2270: 66 20 74 68 69 73 20 69 73 20 79 6f 75 72 20 63  f this is your c
2280: 61 73 65 2c 20 70 6c 65 61 73 65 20 63 6f 6e 73  ase, please cons
2290: 69 64 65 72 20 74 68 61 74 3a 0d 0a 3c 75 6c 3e  ider that:..<ul>
22a0: 0d 0a 3c 6c 69 3e 73 70 65 63 69 66 79 69 6e 67  ..<li>specifying
22b0: 20 61 6e 79 20 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e   any <b>.dll</b>
22c0: 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 6f 72 20  , <b>.so</b> or 
22d0: 3c 62 3e 2e 64 79 6c 69 62 3c 2f 62 3e 20 73 75  <b>.dylib</b> su
22e0: 66 66 69 78 20 63 6f 75 6c 64 20 62 65 20 73 74  ffix could be st
22f0: 72 69 63 74 6c 79 20 72 65 71 75 69 72 65 64 2e  rictly required.
2300: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 73 20 69 74  </li>..<li>as it
2310: 20 63 6f 75 6c 64 20 62 65 20 72 65 71 75 69 72   could be requir
2320: 65 64 20 74 6f 20 65 78 70 6c 69 63 69 74 6c 79  ed to explicitly
2330: 20 73 70 65 63 69 66 79 20 74 68 65 20 65 78 74   specify the ext
2340: 65 6e 73 69 6f 6e 20 65 6e 74 72 79 20 70 6f 69  ension entry poi
2350: 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 63  nt.</li>..<li>ac
2360: 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 61 6c 6c  cordingly to all
2370: 20 74 68 69 73 2c 20 79 6f 75 27 6c 6c 20 70 72   this, you'll pr
2380: 6f 62 61 62 6c 79 20 62 65 20 72 65 71 75 69 72  obably be requir
2390: 65 64 20 74 6f 20 70 61 73 73 20 61 72 67 75 6d  ed to pass argum
23a0: 65 6e 74 73 20 6c 69 6b 65 20 74 68 65 20 66 6f  ents like the fo
23b0: 6c 6c 6f 77 69 6e 67 20 6f 6e 65 73 20 74 6f 20  llowing ones to 
23c0: 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f  <b>load_extensio
23d0: 6e 28 29 3c 2f 62 3e 20 77 68 69 6c 65 20 75 73  n()</b> while us
23e0: 69 6e 67 20 73 6f 6d 65 20 6f 62 73 6f 6c 65 74  ing some obsolet
23f0: 65 20 53 51 4c 69 74 65 33 20 76 65 72 73 69 6f  e SQLite3 versio
2400: 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 76 65 72 62 61 74  n.</li>..<verbat
2410: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6c 6f 61 64  im>..SELECT load
2420: 5f 65 78 74 65 6e 73 69 6f 6e 28 27 2f 75 73 72  _extension('/usr
2430: 2f 6c 6f 63 61 6c 2f 6c 69 62 2f 6d 6f 64 5f 76  /local/lib/mod_v
2440: 69 72 74 75 61 6c 70 67 2e 73 6f 27 2c 20 27 73  irtualpg.so', 's
2450: 71 6c 69 74 65 33 5f 76 69 72 74 75 61 6c 70 67  qlite3_virtualpg
2460: 5f 69 6e 69 74 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  _init');..------
2470: 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74  ..NULL..</verbat
2480: 69 6d 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64  im>..</ul>..</td
2490: 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e  ></tr>..</table>
24a0: 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e  <br>..<hr>..<h2>
24b0: 55 73 69 6e 67 20 56 69 72 74 75 61 6c 50 47 3a  Using VirtualPG:
24c0: 20 61 6e 20 53 51 4c 20 70 65 72 73 70 65 63 74   an SQL perspect
24d0: 69 76 65 3c 2f 68 32 3e 0d 0a 3c 68 33 3e 43 72  ive</h2>..<h3>Cr
24e0: 65 61 74 69 6e 67 20 56 69 72 74 75 61 6c 50 6f  eating VirtualPo
24f0: 73 74 67 72 65 73 20 74 61 62 6c 65 73 3c 2f 68  stgres tables</h
2500: 33 3e 0d 0a 41 66 74 65 72 20 73 75 63 63 65 73  3>..After succes
2510: 73 66 75 6c 6c 79 20 6c 6f 61 64 69 6e 67 20 74  sfully loading t
2520: 68 65 20 3c 62 3e 76 69 72 74 75 61 6c 70 67 3c  he <b>virtualpg<
2530: 2f 62 3e 20 64 79 6e 61 6d 69 63 20 65 78 74 65  /b> dynamic exte
2540: 6e 73 69 6f 6e 20 79 6f 75 20 61 72 65 20 6e 6f  nsion you are no
2550: 77 20 72 65 61 64 79 20 74 6f 20 63 72 65 61 74  w ready to creat
2560: 65 20 3c 62 3e 56 69 72 74 75 61 6c 50 6f 73 74  e <b>VirtualPost
2570: 67 65 73 3c 2f 62 3e 20 74 61 62 6c 65 73 2e 3c  ges</b> tables.<
2580: 62 72 3e 0d 0a 54 68 65 73 65 20 61 72 65 20 3c  br>..These are <
2590: 69 3e 71 75 69 74 65 20 61 6c 6d 6f 73 74 3c 2f  i>quite almost</
25a0: 69 3e 20 6f 72 64 69 6e 61 72 79 20 44 42 20 74  i> ordinary DB t
25b0: 61 62 6c 65 73 20 61 73 20 61 6e 79 20 6f 74 68  ables as any oth
25c0: 65 72 3b 20 79 6f 75 20 63 61 6e 20 65 78 65 63  er; you can exec
25d0: 75 74 65 20 61 6e 79 20 72 65 67 75 6c 61 72 20  ute any regular 
25e0: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 20 28 3c  SQL statement (<
25f0: 69 3e 53 45 4c 45 43 54 3c 2f 69 3e 2c 20 3c 69  i>SELECT</i>, <i
2600: 3e 49 4e 53 45 52 54 3c 2f 69 3e 2c 20 3c 69 3e  >INSERT</i>, <i>
2610: 55 50 44 41 54 45 3c 2f 69 3e 20 6f 72 20 3c 69  UPDATE</i> or <i
2620: 3e 44 45 4c 45 54 45 3c 2f 69 3e 29 20 62 79 20  >DELETE</i>) by 
2630: 73 70 65 63 69 66 79 69 6e 67 20 74 68 65 73 65  specifying these
2640: 20 56 69 72 74 75 61 6c 20 54 61 62 6c 65 73 20   Virtual Tables 
2650: 61 73 20 74 68 65 20 73 65 6c 65 63 74 65 64 20  as the selected 
2660: 74 61 72 67 65 74 2e 3c 62 72 3e 0d 0a 54 68 65  target.<br>..The
2670: 72 65 20 69 73 20 6f 6e 6c 79 20 61 20 73 74 72  re is only a str
2680: 6f 6e 67 20 64 69 66 66 65 72 65 6e 63 65 20 64  ong difference d
2690: 69 73 74 69 6e 67 75 69 73 68 69 6e 67 20 61 20  istinguishing a 
26a0: 3c 62 3e 56 69 72 74 75 61 6c 50 6f 73 74 67 72  <b>VirtualPostgr
26b0: 65 73 3c 2f 62 3e 20 74 61 62 6c 65 3b 20 69 74  es</b> table; it
26c0: 27 73 20 70 68 79 73 69 63 61 6c 20 6c 6f 63 61  's physical loca
26d0: 74 69 6f 6e 20 69 73 6e 27 74 20 77 69 74 68 69  tion isn't withi
26e0: 6e 20 74 68 65 20 63 75 72 72 65 6e 74 6c 79 20  n the currently 
26f0: 63 6f 6e 6e 65 63 74 65 64 20 53 51 4c 69 74 65  connected SQLite
2700: 20 44 42 2c 20 62 75 74 20 69 73 20 69 6e 73 74   DB, but is inst
2710: 65 61 64 20 77 69 74 68 69 6e 20 73 6f 6d 65 20  ead within some 
2720: 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c 3c 2f 62  <b>PostgreSQL</b
2730: 3e 20 44 42 4d 53 2e 3c 62 72 3e 0d 0a 53 6f 20  > DBMS.<br>..So 
2740: 61 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65  a VirtualPostgre
2750: 73 20 74 61 62 6c 65 20 65 66 66 65 63 74 69 76  s table effectiv
2760: 65 6c 79 20 61 63 74 73 20 61 73 20 61 20 3c 69  ely acts as a <i
2770: 3e 62 72 69 64 67 65 3c 2f 69 3e 20 6a 6f 69 6e  >bridge</i> join
2780: 69 6e 67 20 53 51 4c 69 74 65 20 61 6e 64 20 50  ing SQLite and P
2790: 6f 73 74 67 72 65 73 2c 20 61 6e 64 20 61 6c 6c  ostgres, and all
27a0: 6f 77 69 6e 67 20 74 6f 20 70 65 72 66 6f 72 6d  owing to perform
27b0: 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 63 72 6f   any kind of cro
27c0: 73 73 20 64 61 74 61 20 65 78 63 68 61 6e 67 65  ss data exchange
27d0: 20 28 3c 69 3e 69 6e 20 62 6f 74 68 20 64 69 72   (<i>in both dir
27e0: 65 63 74 69 6f 6e 73 3c 2f 69 3e 29 20 69 6e 20  ections</i>) in 
27f0: 74 68 65 20 65 61 73 69 65 73 74 20 77 61 79 2e  the easiest way.
2800: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52  ..<verbatim>..CR
2810: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
2820: 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20 20 20 55  LE pg_in ..    U
2830: 53 49 4e 47 20 56 69 72 74 75 61 6c 50 6f 73 74  SING VirtualPost
2840: 67 72 65 73 20 28 27 68 6f 73 74 3d 6c 6f 63 61  gres ('host=loca
2850: 6c 68 6f 73 74 20 70 6f 72 74 3d 35 34 33 32 20  lhost port=5432 
2860: 64 62 6e 61 6d 65 3d 67 69 73 20 75 73 65 72 3d  dbname=gis user=
2870: 73 61 6e 64 72 6f 20 70 61 73 73 77 6f 72 64 3d  sandro password=
2880: 73 65 63 72 65 74 27 2c 20 6d 79 5f 73 63 68 65  secret', my_sche
2890: 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29 3b 0d 0a  ma, my_table);..
28a0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69  </verbatim>..Thi
28b0: 73 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 20  s SQL statement 
28c0: 77 69 6c 6c 20 63 72 65 61 74 65 20 69 6e 74 6f  will create into
28d0: 20 74 68 65 20 53 51 4c 69 74 65 20 44 42 20 61   the SQLite DB a
28e0: 20 74 61 62 6c 65 20 6e 61 6d 65 64 20 3c 62 3e   table named <b>
28f0: 70 67 5f 69 6e 3c 2f 62 3e 20 77 72 61 70 70 69  pg_in</b> wrappi
2900: 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 53 51  ng the PostgreSQ
2910: 4c 20 74 61 62 6c 65 20 6e 61 6d 65 64 20 3c 62  L table named <b
2920: 3e 6d 79 5f 73 63 68 65 6d 61 3c 2f 62 3e 2e 3c  >my_schema</b>.<
2930: 62 3e 6d 79 5f 74 61 62 6c 65 3c 2f 62 3e 2e 3c  b>my_table</b>.<
2940: 62 72 3e 0d 0a 44 61 74 61 20 66 6f 72 20 74 68  br>..Data for th
2950: 69 73 20 74 61 62 6c 65 20 77 69 6c 6c 20 63 6f  is table will co
2960: 6e 74 69 6e 75 65 20 74 6f 20 62 65 20 73 74 6f  ntinue to be sto
2970: 72 65 64 20 77 69 74 68 69 6e 20 74 68 65 20 50  red within the P
2980: 6f 73 74 67 72 65 73 20 6f 77 6e 20 64 61 74 61  ostgres own data
2990: 20 73 70 61 63 65 2c 20 62 75 74 20 77 69 6c 6c   space, but will
29a0: 20 62 65 20 6e 6f 77 20 61 63 63 65 73 73 69 62   be now accessib
29b0: 6c 65 20 66 6f 72 20 53 51 4c 69 74 65 3a 0d 0a  le for SQLite:..
29c0: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 66 69  <ul>..<li>the fi
29d0: 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20  rst argument to 
29e0: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20  VirtualPostgres 
29f0: 69 73 20 74 68 65 20 3c 69 3e 63 6f 6e 6e 65 63  is the <i>connec
2a00: 74 69 6f 6e 20 73 74 72 69 6e 67 3c 2f 69 3e 20  tion string</i> 
2a10: 72 65 71 75 69 72 65 64 20 69 6e 20 6f 72 64 65  required in orde
2a20: 72 20 74 6f 20 65 73 74 61 62 6c 69 73 68 20 61  r to establish a
2a30: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 74   connection to t
2a40: 68 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53  he Postgres DBMS
2a50: 20 73 65 72 76 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c   server.</li>..<
2a60: 6c 69 3e 73 65 63 6f 6e 64 20 61 6e 64 20 74 68  li>second and th
2a70: 69 72 64 20 61 72 67 75 6d 65 6e 74 73 20 72 65  ird arguments re
2a80: 73 70 65 63 74 69 76 65 6c 79 20 61 72 65 20 74  spectively are t
2a90: 68 65 20 3c 69 3e 73 63 68 65 6d 61 20 6e 61 6d  he <i>schema nam
2aa0: 65 3c 2f 69 3e 20 61 6e 64 20 74 68 65 20 3c 69  e</i> and the <i
2ab0: 3e 74 61 62 6c 65 20 6e 61 6d 65 3c 2f 69 3e 20  >table name</i> 
2ac0: 69 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20  identifying the 
2ad0: 50 6f 73 74 67 72 65 73 20 74 61 72 67 65 74 20  Postgres target 
2ae0: 74 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  table.</li>..</u
2af0: 6c 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  l>..<verbatim>..
2b00: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
2b10: 41 42 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20 20  ABLE pg_in ..   
2b20: 20 55 53 49 4e 47 20 56 69 72 74 75 61 6c 50 6f   USING VirtualPo
2b30: 73 74 67 72 65 73 20 28 27 68 6f 73 74 61 64 64  stgres ('hostadd
2b40: 72 3d 31 39 32 2e 31 36 38 2e 31 2e 39 31 20 70  r=192.168.1.91 p
2b50: 6f 72 74 3d 35 34 33 32 20 64 62 6e 61 6d 65 3d  ort=5432 dbname=
2b60: 67 69 73 20 75 73 65 72 3d 73 61 6e 64 72 6f 20  gis user=sandro 
2b70: 70 61 73 73 77 6f 72 64 3d 73 65 63 72 65 74 27  password=secret'
2b80: 2c 20 6d 79 5f 73 63 68 65 6d 61 2c 20 6d 79 5f  , my_schema, my_
2b90: 74 61 62 6c 65 29 3b 0d 0a 3c 2f 76 65 72 62 61  table);..</verba
2ba0: 74 69 6d 3e 0d 0a 53 61 6d 65 20 61 73 20 61 62  tim>..Same as ab
2bb0: 6f 76 65 2c 20 74 68 69 73 20 74 69 6d 65 20 65  ove, this time e
2bc0: 73 74 61 62 6c 69 73 68 69 6e 67 20 61 20 63 6f  stablishing a co
2bd0: 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 61 20 50 6f  nnection to a Po
2be0: 73 74 67 72 65 73 20 69 6e 73 74 61 6e 63 65 20  stgres instance 
2bf0: 72 75 6e 6e 69 6e 67 20 6f 6e 20 73 6f 6d 65 20  running on some 
2c00: 64 69 66 66 65 72 65 6e 74 20 63 6f 6d 70 75 74  different comput
2c10: 65 72 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 6c  er on the same l
2c20: 6f 63 61 6c 20 61 72 65 61 20 6e 65 74 77 6f 72  ocal area networ
2c30: 6b 2e 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69  k.<br>..<verbati
2c40: 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54 55  m>..CREATE VIRTU
2c50: 41 4c 20 54 41 42 4c 45 20 70 67 5f 69 6e 20 0d  AL TABLE pg_in .
2c60: 0a 20 20 20 20 55 53 49 4e 47 20 56 69 72 74 75  .    USING Virtu
2c70: 61 6c 50 6f 73 74 67 72 65 73 20 28 27 68 6f 73  alPostgres ('hos
2c80: 74 3d 77 77 77 2e 68 75 6d 70 74 79 64 75 6d 70  t=www.humptydump
2c90: 74 79 2e 63 6f 6d 20 70 6f 72 74 3d 35 34 33 32  ty.com port=5432
2ca0: 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 73 65 72   dbname=gis user
2cb0: 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 6f 72 64  =sandro password
2cc0: 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f 73 63 68  =secret', my_sch
2cd0: 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29 3b 0d  ema, my_table);.
2ce0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e  .</verbatim>..In
2cf0: 20 74 68 69 73 20 74 68 69 72 64 20 76 61 72 69   this third vari
2d00: 61 74 69 6f 6e 20 77 65 27 6c 6c 20 63 6f 6e 6e  ation we'll conn
2d10: 65 63 74 20 74 6f 20 61 20 50 6f 73 74 67 72 65  ect to a Postgre
2d20: 73 20 69 6e 73 74 61 6e 63 65 20 72 75 6e 6e 69  s instance runni
2d30: 6e 67 20 6f 6e 20 73 6f 6d 65 20 72 65 6d 6f 74  ng on some remot
2d40: 65 20 73 65 72 76 65 72 20 61 63 63 65 73 73 65  e server accesse
2d50: 64 20 74 68 6f 75 67 68 20 61 20 77 69 64 65 20  d though a wide 
2d60: 61 72 65 61 20 6e 65 74 77 6f 72 6b 2e 3c 62 72  area network.<br
2d70: 3e 0d 0a 50 6c 65 61 73 65 20 63 6f 6e 73 75 6c  >..Please consul
2d80: 74 20 74 68 65 20 50 6f 73 74 67 72 65 73 20 6f  t the Postgres o
2d90: 77 6e 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e  wn documentation
2da0: 20 66 6f 72 20 61 6e 79 20 6f 74 68 65 72 20 64   for any other d
2db0: 65 74 61 69 6c 20 61 62 6f 75 74 20 3c 69 3e 63  etail about <i>c
2dc0: 6f 6e 6e 65 63 74 69 6f 6e 20 73 74 72 69 6e 67  onnection string
2dd0: 73 3c 2f 69 3e 2e 0d 0a 3c 68 33 3e 43 72 65 61  s</i>...<h3>Crea
2de0: 74 69 6e 67 20 56 69 72 74 75 61 6c 50 6f 73 74  ting VirtualPost
2df0: 67 72 65 73 20 74 61 62 6c 65 73 3a 20 66 75 6c  gres tables: ful
2e00: 6c 20 73 79 6e 74 61 78 20 65 78 70 6c 61 69 6e  l syntax explain
2e10: 65 64 3c 2f 68 33 3e 0d 0a 3c 76 65 72 62 61 74  ed</h3>..<verbat
2e20: 69 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54  im>..CREATE VIRT
2e30: 55 41 4c 20 54 41 42 4c 45 20 73 6f 6d 65 6e 61  UAL TABLE somena
2e40: 6d 65 20 55 53 49 4e 47 20 56 69 72 74 75 61 6c  me USING Virtual
2e50: 50 6f 73 74 67 72 65 73 20 7b 63 6f 6e 6e 5f 69  Postgres {conn_i
2e60: 6e 66 6f 2c 20 73 63 68 65 6d 61 2c 20 74 61 62  nfo, schema, tab
2e70: 6c 65 20 5b 20 2c 20 72 65 61 64 5f 77 72 69 74  le [ , read_writ
2e80: 65 5f 66 6c 61 67 20 5b 20 2c 20 6a 75 6c 69 61  e_flag [ , julia
2e90: 6e 5f 66 6c 61 67 20 5d 5d 20 7d 3b 0d 0a 3c 2f  n_flag ]] };..</
2ea0: 76 65 72 62 61 74 69 6d 3e 0d 0a 53 75 70 70 6f  verbatim>..Suppo
2eb0: 72 74 65 64 20 61 72 67 75 6d 65 6e 74 73 3a 0d  rted arguments:.
2ec0: 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 3c 69 3e 6d 61  .<ol>..<li><i>ma
2ed0: 6e 64 61 74 6f 72 79 3c 2f 69 3e 3a 20 3c 62 3e  ndatory</i>: <b>
2ee0: 63 6f 6e 6e 5f 69 6e 66 6f 3c 2f 62 3e 20 28 3c  conn_info</b> (<
2ef0: 69 3e 54 65 78 74 20 53 74 72 69 6e 67 3c 2f 69  i>Text String</i
2f00: 3e 29 3c 62 72 3e 0d 0a 61 6e 79 20 76 61 6c 69  >)<br>..any vali
2f10: 64 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 74 72  d connection str
2f20: 69 6e 67 20 61 63 63 65 70 74 65 64 20 62 79 20  ing accepted by 
2f30: 50 6f 73 74 67 72 65 53 51 4c 2e 20 46 6f 72 20  PostgreSQL. For 
2f40: 66 75 72 74 68 65 72 20 64 65 74 61 69 6c 73 20  further details 
2f50: 70 6c 65 61 73 65 20 63 6f 6e 73 75 6c 74 20 74  please consult t
2f60: 68 65 20 3c 61 20 68 72 65 66 3d 22 22 3e 50 6f  he <a href="">Po
2f70: 73 74 67 72 65 53 51 4c 20 6f 77 6e 3c 2f 61 3e  stgreSQL own</a>
2f80: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 2e 3c   documentation.<
2f90: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 69 3e 6d 61 6e  /li>..<li><i>man
2fa0: 64 61 74 6f 72 79 3c 2f 69 3e 3a 20 3c 62 3e 73  datory</i>: <b>s
2fb0: 63 68 65 6d 61 3c 2f 62 3e 20 28 3c 69 3e 54 65  chema</b> (<i>Te
2fc0: 78 74 20 53 74 72 69 6e 67 3c 2f 69 3e 29 3c 62  xt String</i>)<b
2fd0: 72 3e 0d 0a 6e 61 6d 65 20 6f 66 20 74 68 65 20  r>..name of the 
2fe0: 50 6f 73 67 72 65 53 51 4c 20 53 63 68 65 6d 61  PosgreSQL Schema
2ff0: 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20   containing the 
3000: 54 61 62 6c 65 20 74 6f 20 62 65 20 77 72 61 70  Table to be wrap
3010: 70 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c  ped.</li>..<li><
3020: 69 3e 6d 61 6e 64 61 74 6f 72 79 3c 2f 69 3e 3a  i>mandatory</i>:
3030: 20 3c 62 3e 74 61 62 6c 65 3c 2f 62 3e 20 28 3c   <b>table</b> (<
3040: 69 3e 54 65 78 74 20 53 74 72 69 6e 67 3c 2f 69  i>Text String</i
3050: 3e 29 3c 62 72 3e 0d 0a 6e 61 6d 65 20 6f 66 20  >)<br>..name of 
3060: 74 68 65 20 50 6f 73 67 72 65 53 51 4c 20 54 61  the PosgreSQL Ta
3070: 62 6c 65 20 28 6f 72 20 56 69 65 77 29 20 74 6f  ble (or View) to
3080: 20 62 65 20 77 72 61 70 70 65 64 2e 3c 2f 6c 69   be wrapped.</li
3090: 3e 0d 0a 3c 6c 69 3e 3c 69 3e 6f 70 74 69 6f 6e  >..<li><i>option
30a0: 61 6c 3c 2f 69 3e 3a 20 3c 62 3e 72 65 61 64 5f  al</i>: <b>read_
30b0: 77 72 69 74 65 5f 66 6c 61 67 3c 2f 62 3e 20 28  write_flag</b> (
30c0: 3c 69 3e 54 65 78 74 20 53 74 72 69 6e 67 3c 2f  <i>Text String</
30d0: 69 3e 29 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  i>):..<ul>..<li>
30e0: 3c 62 3e 57 3c 2f 62 3e 3a 20 74 68 65 20 54 61  <b>W</b>: the Ta
30f0: 62 6c 65 20 77 69 6c 6c 20 73 75 70 70 6f 72 74  ble will support
3100: 20 62 6f 74 68 20 72 65 61 64 20 61 6e 64 20 77   both read and w
3110: 72 69 74 65 20 6f 70 65 72 61 74 69 6f 6e 73 2c  rite operations,
3120: 20 65 6e 61 62 6c 69 6e 67 20 53 45 4c 45 43 54   enabling SELECT
3130: 20 2f 20 49 4e 53 45 52 54 20 2f 20 55 50 44 41   / INSERT / UPDA
3140: 54 45 20 2f 20 44 45 4c 45 54 45 20 73 74 61 74  TE / DELETE stat
3150: 65 6d 65 6e 74 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  ements.</li>..<l
3160: 69 3e 3c 62 3e 2d 3c 2f 62 3e 3a 20 74 68 65 20  i><b>-</b>: the 
3170: 54 61 62 6c 65 20 77 69 6c 6c 20 6a 75 73 74 20  Table will just 
3180: 73 75 70 70 6f 72 74 20 72 65 61 64 20 6f 70 65  support read ope
3190: 72 61 74 69 6f 6e 73 3a 20 53 45 4c 45 43 54 20  rations: SELECT 
31a0: 73 74 61 74 65 6d 65 6e 74 73 20 77 69 6c 6c 20  statements will 
31b0: 62 65 20 65 6e 61 62 6c 65 64 2c 20 62 75 74 20  be enabled, but 
31c0: 49 4e 53 45 52 54 20 2f 20 55 50 44 41 54 45 20  INSERT / UPDATE 
31d0: 2f 20 44 45 4c 45 54 45 20 77 69 6c 6c 20 62 65  / DELETE will be
31e0: 20 64 69 73 61 62 6c 65 64 2e 3c 62 72 3e 0d 0a   disabled.<br>..
31f0: 3c 62 3e 4e 6f 74 65 3c 2f 62 3e 3a 20 74 68 69  <b>Note</b>: thi
3200: 73 20 69 73 20 74 68 65 20 64 65 66 61 75 6c 74  s is the default
3210: 20 73 65 74 74 69 6e 67 2e 20 56 69 72 74 75 61   setting. Virtua
3220: 6c 50 47 20 61 6c 77 61 79 73 20 72 65 71 75 69  lPG always requi
3230: 72 65 73 20 61 6e 20 65 78 70 6c 69 63 69 74 20  res an explicit 
3240: 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 69 6e  authorization in
3250: 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c 65   order to enable
3260: 20 77 72 69 74 65 20 6f 70 65 72 61 74 69 6f 6e   write operation
3270: 73 2e 3c 2f 6c 69 3e 20 0d 0a 3c 2f 75 6c 3e 3c  s.</li> ..</ul><
3280: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 69 3e 6f 70 74  /li>..<li><i>opt
3290: 69 6f 6e 61 6c 3c 2f 69 3e 3a 20 3c 62 3e 6a 75  ional</i>: <b>ju
32a0: 6c 69 61 6e 5f 66 6c 61 67 3c 2f 62 3e 20 28 3c  lian_flag</b> (<
32b0: 69 3e 54 65 78 74 20 53 74 72 69 6e 67 3c 2f 69  i>Text String</i
32c0: 3e 29 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c  >):..<ul>..<li><
32d0: 62 3e 4a 3c 2f 62 3e 3a 20 44 41 54 45 20 2f 20  b>J</b>: DATE / 
32e0: 54 49 4d 45 20 2f 20 54 49 4d 45 53 54 41 4d 50  TIME / TIMESTAMP
32f0: 20 76 61 6c 75 65 73 20 77 69 6c 6c 20 62 65 20   values will be 
3300: 74 72 61 6e 73 6c 61 74 65 64 20 69 6e 74 6f 20  translated into 
3310: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e  the correspondin
3320: 67 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73  g <a href="https
3330: 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e  ://en.wikipedia.
3340: 6f 72 67 2f 77 69 6b 69 2f 4a 75 6c 69 61 6e 5f  org/wiki/Julian_
3350: 64 61 79 22 3e 4a 75 6c 69 61 6e 20 44 61 79 20  day">Julian Day 
3360: 4e 75 6d 62 65 72 73 3c 2f 61 3e 20 28 46 4c 4f  Numbers</a> (FLO
3370: 41 54 20 76 61 6c 75 65 73 29 2e 3c 2f 6c 69 3e  AT values).</li>
3380: 0d 0a 3c 6c 69 3e 3c 62 3e 2d 3c 2f 62 3e 3a 20  ..<li><b>-</b>: 
3390: 44 41 54 45 20 2f 20 54 49 4d 45 20 2f 20 54 49  DATE / TIME / TI
33a0: 4d 45 53 54 41 4d 50 20 76 61 6c 75 65 73 20 77  MESTAMP values w
33b0: 69 6c 6c 20 62 65 20 74 72 61 6e 73 6c 61 74 65  ill be translate
33c0: 64 20 69 6e 74 6f 20 74 68 65 20 63 6f 72 72 65  d into the corre
33d0: 73 70 6f 6e 64 69 6e 67 20 73 74 61 6e 64 61 72  sponding standar
33e0: 64 20 53 51 4c 20 54 65 78 74 20 53 74 72 69 6e  d SQL Text Strin
33f0: 67 73 2e 2e 3c 62 72 3e 0d 0a 3c 62 3e 4e 6f 74  gs..<br>..<b>Not
3400: 65 3c 2f 62 3e 3a 20 74 68 69 73 20 69 73 20 74  e</b>: this is t
3410: 68 65 20 64 65 66 61 75 6c 74 20 73 65 74 74 69  he default setti
3420: 6e 67 2e 20 56 69 72 74 75 61 6c 50 47 20 61 6c  ng. VirtualPG al
3430: 77 61 79 73 20 72 65 71 75 69 72 65 73 20 61 6e  ways requires an
3440: 20 65 78 70 6c 69 63 69 74 20 61 75 74 68 6f 72   explicit author
3450: 69 7a 61 74 69 6f 6e 20 69 6e 20 6f 72 64 65 72  ization in order
3460: 20 74 6f 20 65 6e 61 62 6c 65 20 4a 75 6c 69 61   to enable Julia
3470: 6e 20 44 61 79 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f  n Days.</li>..</
3480: 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 3c  ul></li>..</ol><
3490: 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20  br><br>..<table 
34a0: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 36 22 20  cellspacing="6" 
34b0: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 20  cellpadding="6" 
34c0: 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66 65 38  bgcolor="#ffffe8
34d0: 22 20 77 69 64 74 68 3d 22 31 30 30 25 22 3e 0d  " width="100%">.
34e0: 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  .<tr><td align="
34f0: 63 65 6e 74 65 72 22 3e 3c 62 3e 55 73 65 66 75  center"><b>Usefu
3500: 6c 20 68 69 6e 74 73 3a 20 63 6f 6e 6e 65 63 74  l hints: connect
3510: 69 6e 67 20 74 6f 20 72 65 6d 6f 74 65 20 50 6f  ing to remote Po
3520: 73 74 67 72 65 53 51 4c 20 69 73 74 61 6e 63 65  stgreSQL istance
3530: 73 20 76 69 61 20 50 6f 72 74 20 46 6f 72 77 61  s via Port Forwa
3540: 72 64 69 6e 67 20 2f 20 53 53 48 20 54 75 6e 6e  rding / SSH Tunn
3550: 65 6c 69 6e 67 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f  eling</b></td></
3560: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 68 72  tr>..<tr><td><hr
3570: 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72  ></td></tr>..<tr
3580: 3e 3c 74 64 3e 0d 0a 57 68 65 6e 65 76 65 72 20  ><td>..Whenever 
3590: 79 6f 75 20 72 65 71 75 69 72 65 20 74 6f 20 63  you require to c
35a0: 6f 6e 6e 65 63 74 20 73 6f 6d 65 20 72 65 6d 6f  onnect some remo
35b0: 74 65 20 50 6f 73 74 67 72 65 53 51 4c 20 69 73  te PostgreSQL is
35c0: 74 61 6e 63 65 20 28 69 2e 65 2e 20 6f 6e 65 20  tance (i.e. one 
35d0: 61 63 74 75 61 6c 6c 79 20 72 75 6e 6e 69 6e 67  actually running
35e0: 20 6f 6e 20 73 6f 6d 65 20 72 65 6d 6f 74 65 20   on some remote 
35f0: 73 65 72 76 65 72 20 72 65 71 75 69 72 69 6e 67  server requiring
3600: 20 74 6f 20 65 73 74 61 62 6c 69 73 68 20 61 20   to establish a 
3610: 3c 62 3e 4c 41 4e 3c 2f 62 3e 20 6f 72 20 3c 62  <b>LAN</b> or <b
3620: 3e 57 41 4e 3c 2f 62 3e 20 63 6f 6e 6e 65 63 74  >WAN</b> connect
3630: 69 6f 6e 29 20 79 6f 75 20 73 68 6f 75 6c 64 20  ion) you should 
3640: 61 6c 77 61 79 73 20 73 65 72 69 6f 75 73 6c 79  always seriously
3650: 20 63 6f 6e 73 69 64 65 72 20 75 73 69 6e 67 20   consider using 
3660: 3c 62 3e 53 53 48 20 54 75 6e 6e 65 6c 69 6e 67  <b>SSH Tunneling
3670: 3c 2f 62 3e 20 2f 20 3c 62 3e 50 6f 72 74 20 46  </b> / <b>Port F
3680: 6f 72 77 61 72 64 69 6e 67 3c 2f 62 3e 2e 3c 62  orwarding</b>.<b
3690: 72 3e 0d 0a 54 68 69 73 20 63 6f 75 6c 64 20 67  r>..This could g
36a0: 72 65 61 74 6c 79 20 73 69 6d 70 6c 69 66 79 20  reatly simplify 
36b0: 79 6f 75 72 20 61 70 70 72 6f 61 63 68 2c 20 65  your approach, e
36c0: 6e 73 75 72 69 6e 67 20 61 74 20 74 68 65 20 73  nsuring at the s
36d0: 61 6d 65 20 74 69 6d 65 20 61 6e 20 75 6e 63 6f  ame time an unco
36e0: 6d 70 72 6f 6d 69 73 65 64 20 73 61 66 65 74 79  mpromised safety
36f0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 50 6c 65 61 73  .<br><br>..Pleas
3700: 65 20 72 65 61 64 20 3c 61 20 68 72 65 66 3d 22  e read <a href="
3710: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
3720: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 76  -gis.it/fossil/v
3730: 69 72 74 75 61 6c 70 67 2f 77 69 6b 69 3f 6e 61  irtualpg/wiki?na
3740: 6d 65 3d 70 6f 72 74 2d 66 6f 72 77 61 72 64 69  me=port-forwardi
3750: 6e 67 22 3e 74 68 69 73 20 57 69 6b 69 20 70 61  ng">this Wiki pa
3760: 67 65 3c 2f 61 3e 20 66 6f 72 20 6d 6f 72 65 20  ge</a> for more 
3770: 73 70 65 63 69 66 69 63 20 64 65 74 61 69 6c 73  specific details
3780: 20 61 62 6f 75 74 20 53 53 48 20 54 75 6e 6e 65   about SSH Tunne
3790: 6c 69 6e 67 20 61 6e 64 20 50 6f 72 74 20 46 6f  ling and Port Fo
37a0: 72 77 61 72 64 69 6e 67 2e 0d 0a 3c 2f 74 64 3e  rwarding...</td>
37b0: 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72  </tr></table><br
37c0: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 42 61 73  >..<hr>..<h3>Bas
37d0: 69 63 20 53 51 4c 20 6f 70 65 72 61 74 69 6f 6e  ic SQL operation
37e0: 73 3c 2f 68 33 3e 0d 0a 3c 76 65 72 62 61 74 69  s</h3>..<verbati
37f0: 6d 3e 0d 0a 50 52 41 47 4d 41 20 74 61 62 6c 65  m>..PRAGMA table
3800: 5f 69 6e 66 6f 28 70 67 5f 69 6e 29 3b 0d 0a 3c  _info(pg_in);..<
3810: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20  /verbatim>..You 
3820: 63 61 6e 20 65 78 65 63 75 74 65 20 74 68 65 20  can execute the 
3830: 61 62 6f 76 65 20 50 52 41 47 4d 41 20 64 69 72  above PRAGMA dir
3840: 65 63 74 69 76 65 20 69 6e 20 6f 72 64 65 72 20  ective in order 
3850: 74 6f 20 69 64 65 6e 74 69 66 79 20 61 6c 6c 20  to identify all 
3860: 63 6f 6c 75 6d 6e 73 20 64 65 63 6c 61 72 65 64  columns declared
3870: 20 62 79 20 74 68 65 20 50 6f 73 74 67 72 65 73   by the Postgres
3880: 20 74 61 62 6c 65 2c 20 61 6e 64 20 74 68 65 69   table, and thei
3890: 72 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20  r corresponding 
38a0: 64 61 74 61 2d 74 79 70 65 2e 0d 0a 3c 76 65 72  data-type...<ver
38b0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 61  batim>..SELECT a
38c0: 2c 20 62 2c 20 63 2c 20 43 6f 75 6e 74 28 2a 29  , b, c, Count(*)
38d0: 20 41 53 20 63 6e 74 0d 0a 46 52 4f 4d 20 70 67   AS cnt..FROM pg
38e0: 5f 69 6e 0d 0a 57 48 45 52 45 20 65 20 49 53 20  _in..WHERE e IS 
38f0: 4e 4f 54 20 4e 55 4c 4c 0d 0a 47 52 4f 55 50 20  NOT NULL..GROUP 
3900: 42 59 20 61 2c 20 62 2c 20 63 0d 0a 4f 52 44 45  BY a, b, c..ORDE
3910: 52 20 42 59 20 63 6e 74 20 44 45 53 43 3b 0d 0a  R BY cnt DESC;..
3920: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75  </verbatim>..You
3930: 20 63 61 6e 20 65 78 65 63 75 74 65 20 61 6e 79   can execute any
3940: 20 6b 69 6e 64 20 6f 66 20 3c 62 3e 53 45 4c 45   kind of <b>SELE
3950: 43 54 3c 2f 62 3e 20 71 75 65 72 79 20 75 73 69  CT</b> query usi
3960: 6e 67 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74  ng a VirtualPost
3970: 67 72 65 73 20 74 61 62 6c 65 2c 20 65 78 61 63  gres table, exac
3980: 74 6c 79 20 61 73 20 69 66 20 69 74 20 77 61 73  tly as if it was
3990: 20 61 20 67 65 6e 75 69 6e 65 20 6e 61 74 69 76   a genuine nativ
39a0: 65 20 74 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61  e table...<verba
39b0: 74 69 6d 3e 0d 0a 43 52 45 41 54 45 20 54 41 42  tim>..CREATE TAB
39c0: 4c 45 20 69 6d 70 6f 72 74 65 64 5f 66 72 6f 6d  LE imported_from
39d0: 5f 70 67 20 41 53 0d 0a 53 45 4c 45 43 54 20 2a  _pg AS..SELECT *
39e0: 20 46 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 3c 2f   FROM pg_in;..</
39f0: 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20 63  verbatim>..You c
3a00: 61 6e 20 6f 62 76 69 6f 75 73 6c 79 20 63 72 65  an obviously cre
3a10: 61 74 65 20 61 6e 64 20 70 6f 70 75 6c 61 74 65  ate and populate
3a20: 20 61 20 6c 6f 63 61 6c 20 63 6f 70 79 20 6f 66   a local copy of
3a30: 20 74 68 65 20 72 65 6d 6f 74 65 20 50 6f 73 74   the remote Post
3a40: 67 72 65 73 20 74 61 62 6c 65 3a 20 6e 6f 77 20  gres table: now 
3a50: 61 6c 6c 20 64 61 74 61 20 61 72 65 20 70 65 72  all data are per
3a60: 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72 65 64 20  manently stored 
3a70: 77 69 74 68 69 6e 20 79 6f 75 72 20 53 51 4c 69  within your SQLi
3a80: 74 65 20 44 42 2e 0d 0a 3c 76 65 72 62 61 74 69  te DB...<verbati
3a90: 6d 3e 0d 0a 42 45 47 49 4e 3b 0d 0a 43 4f 4d 4d  m>..BEGIN;..COMM
3aa0: 49 54 3b 0d 0a 52 4f 4c 4c 42 41 43 4b 3b 0d 0a  IT;..ROLLBACK;..
3ab0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 72 61  </verbatim>..Tra
3ac0: 6e 73 61 63 74 69 6f 6e 73 20 61 72 65 20 68 6f  nsactions are ho
3ad0: 6e 6f 75 72 65 64 20 6f 6e 20 74 68 65 20 50 6f  noured on the Po
3ae0: 73 74 67 72 65 53 51 4c 20 73 69 64 65 20 61 73  stgreSQL side as
3af0: 20 77 65 6c 6c 2c 20 77 68 65 6e 20 61 20 56 69   well, when a Vi
3b00: 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 54 61  rtualPostgres Ta
3b10: 62 6c 65 20 73 75 70 70 6f 72 74 73 20 49 4e 53  ble supports INS
3b20: 45 52 54 20 2f 20 55 50 44 41 54 45 20 2f 20 44  ERT / UPDATE / D
3b30: 45 4c 45 54 45 20 73 74 61 74 65 6d 65 6e 74 73  ELETE statements
3b40: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 44  ...<verbatim>..D
3b50: 52 4f 50 20 54 41 42 4c 45 20 70 67 5f 69 6e 3b  ROP TABLE pg_in;
3b60: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 46  ..</verbatim>..F
3b70: 69 6e 61 6c 6c 79 2c 20 79 6f 75 20 63 61 6e 20  inally, you can 
3b80: 64 72 6f 70 20 74 68 65 20 56 69 72 74 75 61 6c  drop the Virtual
3b90: 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 2c 20  Postgres table, 
3ba0: 61 6e 64 20 74 68 69 73 20 77 69 6c 6c 20 69 6d  and this will im
3bb0: 6d 65 64 69 61 74 65 6c 79 20 74 65 72 6d 69 6e  mediately termin
3bc0: 61 74 65 20 74 68 65 20 63 6f 6e 6e 65 63 74 69  ate the connecti
3bd0: 6f 6e 20 74 6f 20 74 68 65 20 50 6f 73 74 67 72  on to the Postgr
3be0: 65 73 20 44 42 4d 53 2e 3c 62 72 3e 3c 62 72 3e  es DBMS.<br><br>
3bf0: 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 64 61 74 61  ..<hr>..<h3>data
3c00: 2d 74 79 70 65 20 6d 61 70 70 69 6e 67 20 61 6e  -type mapping an
3c10: 64 20 72 65 6c 61 74 65 64 20 63 6f 6e 76 65 72  d related conver
3c20: 73 69 6f 6e 73 3c 2f 68 33 3e 0d 0a 52 61 74 68  sions</h3>..Rath
3c30: 65 72 20 6f 62 76 69 6f 75 73 6c 79 20 53 51 4c  er obviously SQL
3c40: 69 74 65 20 61 6e 64 20 50 6f 73 74 67 72 65 73  ite and Postgres
3c50: 20 73 75 70 70 6f 72 74 73 20 76 65 72 79 20 64   supports very d
3c60: 69 66 66 65 72 65 6e 74 20 6b 69 6e 64 20 6f 66  ifferent kind of
3c70: 20 64 61 74 61 2d 74 79 70 65 73 2e 20 54 68 65   data-types. The
3c80: 20 66 65 77 20 66 6f 6c 6c 6f 77 69 6e 67 20 72   few following r
3c90: 75 6c 65 73 20 61 70 70 6c 79 3a 0d 0a 3c 75 6c  ules apply:..<ul
3ca0: 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 6b 69 6e 64 20  >..<li>any kind 
3cb0: 6f 66 20 3c 62 3e 49 4e 54 45 47 45 52 3c 2f 62  of <b>INTEGER</b
3cc0: 3e 20 76 61 6c 75 65 20 69 73 20 70 72 65 73 65  > value is prese
3cd0: 72 76 65 64 20 61 73 20 73 75 63 68 20 28 74 68  rved as such (th
3ce0: 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 3c 62 3e  is including <b>
3cf0: 42 49 47 49 4e 54 3c 2f 62 3e 29 2e 3c 2f 6c 69  BIGINT</b>).</li
3d00: 3e 0d 0a 3c 6c 69 3e 74 68 65 20 73 61 6d 65 20  >..<li>the same 
3d10: 69 73 20 66 6f 72 20 3c 62 3e 46 4c 4f 41 54 3c  is for <b>FLOAT<
3d20: 2f 62 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e  /b> values.</li>
3d30: 0d 0a 3c 6c 69 3e 3c 62 3e 4d 4f 4e 45 59 3c 2f  ..<li><b>MONEY</
3d40: 62 3e 20 61 6e 64 20 3c 62 3e 4e 55 4d 45 52 49  b> and <b>NUMERI
3d50: 43 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 72 65  C</b> values are
3d60: 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20   converted into 
3d70: 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76 61 6c  <b>FLOAT</b> val
3d80: 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c  ues.</li>..<li><
3d90: 62 3e 43 48 41 52 3c 2f 62 3e 20 61 6e 64 20 3c  b>CHAR</b> and <
3da0: 62 3e 56 41 52 43 48 41 52 3c 2f 62 3e 20 76 61  b>VARCHAR</b> va
3db0: 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 73 20  lues are always 
3dc0: 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 3c  converted into <
3dd0: 62 3e 54 45 58 54 3c 2f 62 3e 20 76 61 6c 75 65  b>TEXT</b> value
3de0: 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 48 61 6e  s.</li>..<li>Han
3df0: 64 6c 69 6e 67 20 6f 66 20 3c 62 3e 44 41 54 45  dling of <b>DATE
3e00: 3c 2f 62 3e 2c 20 3c 62 3e 54 49 4d 45 3c 2f 62  </b>, <b>TIME</b
3e10: 3e 20 61 6e 64 20 3c 62 3e 54 49 4d 45 53 54 41  > and <b>TIMESTA
3e20: 4d 50 3c 2f 62 3e 20 76 61 6c 75 65 73 20 64 65  MP</b> values de
3e30: 70 65 6e 64 73 20 6f 6e 20 74 68 65 20 73 70 65  pends on the spe
3e40: 63 69 66 63 20 66 6c 61 67 20 28 3c 62 3e 4a 3c  cifc flag (<b>J<
3e50: 2f 62 3e 29 20 64 65 63 6c 61 72 65 64 20 69 6e  /b>) declared in
3e60: 20 74 68 65 20 3c 62 3e 43 52 45 41 54 45 20 56   the <b>CREATE V
3e70: 49 52 54 55 41 4c 20 54 41 42 4c 45 3c 2f 62 3e  IRTUAL TABLE</b>
3e80: 20 73 74 61 74 65 6d 65 6e 74 3a 0d 0a 3c 75 6c   statement:..<ul
3e90: 3e 0d 0a 3c 6c 69 3e 61 73 20 3c 62 3e 54 65 78  >..<li>as <b>Tex
3ea0: 74 20 76 61 6c 75 65 73 3c 2f 62 3e 3c 62 72 3e  t values</b><br>
3eb0: 0d 0a 44 41 54 45 2c 20 54 49 4d 45 20 61 6e 64  ..DATE, TIME and
3ec0: 20 54 49 4d 45 53 54 41 4d 50 20 76 61 6c 75 65   TIMESTAMP value
3ed0: 73 20 61 72 65 20 61 6c 77 61 79 73 20 63 6f 6e  s are always con
3ee0: 76 65 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e 54  verted into <b>T
3ef0: 45 58 54 20 73 74 72 69 6e 67 3c 2f 62 3e 20 61  EXT string</b> a
3f00: 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 74 68  ccordingly to th
3f10: 65 20 73 74 61 6e 64 61 72 64 20 53 51 4c 20 72  e standard SQL r
3f20: 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 73 3a 0d  epresentations:.
3f30: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 20 65 78  .<ul>..<li>an ex
3f40: 61 6d 70 6c 65 20 6f 66 20 44 41 54 45 20 76 61  ample of DATE va
3f50: 6c 75 65 3a 20 3c 62 3e 32 30 31 38 2d 30 38 2d  lue: <b>2018-08-
3f60: 31 36 3c 2f 62 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  16</b></li>..<li
3f70: 3e 61 6e 20 65 78 61 6d 70 6c 65 20 6f 66 20 54  >an example of T
3f80: 49 4d 45 20 76 61 6c 75 65 3a 20 3c 62 3e 31 32  IME value: <b>12
3f90: 3a 33 30 3a 34 35 3c 2f 62 3e 3c 2f 6c 69 3e 0d  :30:45</b></li>.
3fa0: 0a 3c 6c 69 3e 61 6e 20 65 78 61 6d 70 6c 65 20  .<li>an example 
3fb0: 6f 66 20 54 49 4d 45 53 54 41 4d 50 20 76 61 6c  of TIMESTAMP val
3fc0: 75 65 3a 20 3c 62 3e 32 30 31 38 2d 30 38 2d 31  ue: <b>2018-08-1
3fd0: 36 20 31 32 3a 33 30 3a 34 35 3c 2f 62 3e 3c 2f  6 12:30:45</b></
3fe0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d  li>..</ul></li>.
3ff0: 0a 3c 6c 69 3e 61 73 20 3c 62 3e 4a 75 6c 69 61  .<li>as <b>Julia
4000: 6e 20 4e 75 6d 62 65 72 73 3c 2f 62 3e 3c 62 72  n Numbers</b><br
4010: 3e 0d 0a 44 41 54 45 2c 20 54 49 4d 45 20 61 6e  >..DATE, TIME an
4020: 64 20 54 49 4d 45 53 54 41 4d 50 20 76 61 6c 75  d TIMESTAMP valu
4030: 65 73 20 61 72 65 20 61 6c 77 61 79 73 20 63 6f  es are always co
4040: 6e 76 65 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e  nverted into <b>
4050: 46 4c 4f 41 54 3c 2f 62 3e 20 76 61 6c 75 65 73  FLOAT</b> values
4060: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74   corresponding t
4070: 6f 20 74 68 65 20 3c 61 20 68 72 65 66 3d 22 68  o the <a href="h
4080: 74 74 70 3a 2f 2f 77 77 77 2e 73 71 6c 69 74 65  ttp://www.sqlite
4090: 2e 6f 72 67 2f 6c 61 6e 67 5f 64 61 74 65 66 75  .org/lang_datefu
40a0: 6e 63 2e 68 74 6d 6c 22 3e 4a 75 6c 69 61 6e 44  nc.html">JulianD
40b0: 61 79 3c 2f 61 3e 20 6e 6f 74 61 74 69 6f 6e 20  ay</a> notation 
40c0: 73 75 70 70 6f 72 74 65 64 20 62 79 20 53 51 4c  supported by SQL
40d0: 69 74 65 2e 3c 62 72 3e 0d 0a 59 6f 75 20 63 61  ite.<br>..You ca
40e0: 6e 20 74 68 65 6e 20 69 6e 76 6f 6b 65 20 74 68  n then invoke th
40f0: 65 20 61 70 70 72 6f 70 72 69 61 74 65 20 66 75  e appropriate fu
4100: 6e 63 74 69 6f 6e 20 62 65 74 77 65 65 6e 20 3c  nction between <
4110: 62 3e 44 61 74 65 28 29 3c 2f 62 3e 2c 20 3c 62  b>Date()</b>, <b
4120: 3e 54 69 6d 65 28 29 3c 2f 62 3e 20 6f 72 20 3c  >Time()</b> or <
4130: 62 3e 44 61 74 65 54 69 6d 65 28 29 3c 2f 62 3e  b>DateTime()</b>
4140: 20 73 6f 20 74 6f 20 67 65 74 20 62 61 63 6b 20   so to get back 
4150: 74 68 65 20 73 74 61 6e 64 61 72 64 20 53 51 4c  the standard SQL
4160: 20 6e 6f 74 61 74 69 6f 6e 20 66 6f 72 20 64 61   notation for da
4170: 74 65 73 20 61 6e 64 20 74 69 6d 65 73 2e 3c 2f  tes and times.</
4180: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 48 69 6e 74  li>..<li><b>Hint
4190: 3c 2f 62 3e 3a 20 75 73 69 6e 67 20 54 45 58 54  </b>: using TEXT
41a0: 20 73 74 72 69 6e 67 73 20 69 73 20 6d 6f 72 65   strings is more
41b0: 20 6e 61 74 75 72 61 6c 20 61 6e 64 20 6d 61 6b   natural and mak
41c0: 65 20 65 61 73 69 65 72 20 72 65 61 64 69 6e 67  e easier reading
41d0: 20 74 68 65 20 64 61 74 65 2d 74 69 6d 65 20 72   the date-time r
41e0: 65 6c 61 74 65 64 20 76 61 6c 75 65 73 2e 3c 62  elated values.<b
41f0: 72 3e 0d 0a 75 73 69 6e 67 20 4a 55 4c 49 41 4e  r>..using JULIAN
4200: 20 4e 55 4d 42 45 52 53 20 6d 61 6b 65 20 73 69   NUMBERS make si
4210: 6d 70 6c 65 72 20 70 65 72 66 6f 72 6d 69 6e 67  mpler performing
4220: 20 64 61 74 65 2d 74 69 6d 65 20 72 65 6c 61 74   date-time relat
4230: 65 64 20 63 6f 6d 70 75 74 61 74 69 6f 6e 73 2c  ed computations,
4240: 20 61 73 20 65 2e 67 2e 20 63 6f 6d 70 75 74 69   as e.g. computi
4250: 6e 67 20 74 68 65 20 65 6c 61 70 73 65 64 20 69  ng the elapsed i
4260: 6e 74 65 72 76 61 6c 20 28 69 6e 20 64 61 79 73  nterval (in days
4270: 29 20 62 65 74 77 65 65 6e 20 74 77 6f 20 64 61  ) between two da
4280: 74 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  tes.</li>..</ul>
4290: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 42 4f  </li>..<li><b>BO
42a0: 4f 4c 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 72  OL</b> values ar
42b0: 65 20 61 6c 77 61 79 73 20 63 6f 6e 76 65 72 74  e always convert
42c0: 65 64 20 69 6e 74 6f 20 3c 62 3e 49 4e 54 45 47  ed into <b>INTEG
42d0: 45 52 3c 2f 62 3e 20 76 61 6c 75 65 73 3a 20 3c  ER</b> values: <
42e0: 62 3e 30 3c 2f 62 3e 20 63 6f 72 72 65 73 70 6f  b>0</b> correspo
42f0: 6e 64 69 6e 67 20 74 6f 20 3c 62 3e 46 41 4c 53  nding to <b>FALS
4300: 45 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  E</b>.</li>..<li
4310: 3e 50 6f 73 74 67 72 65 73 20 73 75 70 70 6f 72  >Postgres suppor
4320: 74 73 20 6d 75 6c 74 69 70 6c 65 20 76 61 6c 75  ts multiple valu
4330: 65 73 20 74 6f 20 62 65 20 73 74 6f 72 65 64 20  es to be stored 
4340: 69 6e 74 6f 20 74 68 65 20 73 61 6d 65 20 63 6f  into the same co
4350: 6c 75 6d 6e 20 28 3c 62 3e 41 52 52 41 59 3c 2f  lumn (<b>ARRAY</
4360: 62 3e 29 3a 20 53 51 4c 69 74 65 20 68 61 73 20  b>): SQLite has 
4370: 6e 6f 20 73 69 6d 69 6c 61 72 20 63 61 70 61 62  no similar capab
4380: 69 6c 69 74 79 2c 20 73 6f 20 61 6e 79 20 41 52  ility, so any AR
4390: 52 41 59 20 76 61 6c 75 65 20 77 69 6c 6c 20 73  RAY value will s
43a0: 69 6d 70 6c 79 20 62 65 20 63 6f 6e 76 65 72 74  imply be convert
43b0: 65 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 45 58  ed into a <b>TEX
43c0: 54 3c 2f 62 3e 20 73 74 72 69 6e 67 2c 20 65 2e  T</b> string, e.
43d0: 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 7b 31 2c  g. as in <b>'{1,
43e0: 32 2c 33 7d 27 3c 2f 62 3e 20 6f 72 20 3c 62 3e  2,3}'</b> or <b>
43f0: 27 7b 61 6c 70 68 61 2c 62 65 74 61 2c 67 61 6d  '{alpha,beta,gam
4400: 6d 61 2c 64 65 6c 74 61 7d 27 3c 2f 62 3e 2e 3c  ma,delta}'</b>.<
4410: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 62 69  /li>..<li>any bi
4420: 6e 61 72 79 20 76 61 6c 75 65 20 28 61 73 20 65  nary value (as e
4430: 2e 67 2e 20 3c 62 3e 42 59 54 45 41 3c 2f 62 3e  .g. <b>BYTEA</b>
4440: 29 20 77 69 6c 6c 20 62 65 20 73 69 6d 70 6c 79  ) will be simply
4450: 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20   converted into 
4460: 61 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 76 61  a <b>TEXT</b> va
4470: 6c 75 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74  lue containing t
4480: 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67  he corresponding
4490: 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e 6f 74   hexadecimal not
44a0: 61 74 69 6f 6e 2c 20 65 2e 67 2e 20 61 73 20 69  ation, e.g. as i
44b0: 6e 20 3c 62 3e 27 30 31 30 31 30 30 30 30 32 30  n <b>'0101000020
44c0: 45 38 36 34 30 30 30 30 43 34 46 43 33 34 42 41  E8640000C4FC34BA
44d0: 38 34 34 38 32 34 34 31 35 30 43 31 42 35 44 35  8448244150C1B5D5
44e0: 34 31 42 38 35 33 34 31 27 3c 2f 62 3e 2e 3c 2f  41B85341'</b>.</
44f0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a  li>..</ul><br>..
4500: 3c 68 72 3e 0d 0a 3c 68 33 3e 68 61 6e 64 6c 69  <hr>..<h3>handli
4510: 6e 67 20 50 6f 73 74 47 49 53 20 67 65 6f 6d 65  ng PostGIS geome
4520: 74 72 69 65 73 3c 2f 68 33 3e 0d 0a 50 6f 73 74  tries</h3>..Post
4530: 47 49 53 20 6f 77 6e 20 67 65 6f 6d 65 74 72 69  GIS own geometri
4540: 65 73 20 73 69 6d 70 6c 79 20 61 72 65 20 72 65  es simply are re
4550: 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 20 3c  presented by a <
4560: 62 3e 42 59 54 45 41 3c 2f 62 3e 20 76 61 6c 75  b>BYTEA</b> valu
4570: 65 20 74 6f 20 62 65 20 69 6e 74 65 72 70 72 65  e to be interpre
4580: 74 65 64 20 61 63 63 6f 72 64 69 6e 67 6c 79 20  ted accordingly 
4590: 74 6f 20 3c 62 3e 45 57 4b 42 3c 2f 62 3e 20 66  to <b>EWKB</b> f
45a0: 6f 72 6d 61 74 20 73 70 65 63 69 66 69 63 61 74  ormat specificat
45b0: 69 6f 6e 73 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  ions...<verbatim
45c0: 3e 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20  >..CREATE TABLE 
45d0: 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 41 53 0d  from_postgis AS.
45e0: 0a 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 70  .SELECT * FROM p
45f0: 67 5f 69 6e 3b 0d 0a 0d 0a 55 50 44 41 54 45 20  g_in;....UPDATE 
4600: 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 53 45 54  from_postgis SET
4610: 20 67 65 6f 6d 65 74 72 79 20 3d 20 47 65 6f 6d   geometry = Geom
4620: 46 72 6f 6d 45 57 4b 42 28 67 65 6f 6d 65 74 72  FromEWKB(geometr
4630: 79 29 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 49  y);....SELECT DI
4640: 53 54 49 4e 43 54 20 53 54 5f 47 65 6f 6d 65 74  STINCT ST_Geomet
4650: 72 79 54 79 70 65 28 67 65 6f 6d 65 74 72 79 29  ryType(geometry)
4660: 2c 20 53 54 5f 53 72 69 64 28 67 65 6f 6d 65 74  , ST_Srid(geomet
4670: 72 79 29 2c 20 43 6f 6f 72 64 44 69 6d 65 6e 73  ry), CoordDimens
4680: 69 6f 6e 28 67 65 6f 6d 65 74 72 79 29 0d 0a 46  ion(geometry)..F
4690: 52 4f 4d 20 66 72 6f 6d 5f 70 6f 73 74 67 69 73  ROM from_postgis
46a0: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d  ;..------------.
46b0: 0a 4c 49 4e 45 53 54 52 49 4e 47 7c 32 35 38 33  .LINESTRING|2583
46c0: 32 7c 58 59 0d 0a 0d 0a 53 45 4c 45 43 54 20 52  2|XY....SELECT R
46d0: 65 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 6f  ecoverGeometryCo
46e0: 6c 75 6d 6e 28 27 66 72 6f 6d 5f 70 6f 73 74 67  lumn('from_postg
46f0: 69 73 27 2c 20 27 67 65 6f 6d 65 74 72 79 27 2c  is', 'geometry',
4700: 20 32 35 38 33 32 2c 20 27 4c 49 4e 45 53 54 52   25832, 'LINESTR
4710: 49 4e 47 27 2c 20 27 58 59 27 29 3b 0d 0a 2d 2d  ING', 'XY');..--
4720: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 3c  ----------..1..<
4730: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 73  /verbatim>..This
4740: 20 73 65 71 75 65 6e 63 65 20 6f 66 20 53 51 4c   sequence of SQL
4750: 20 73 74 61 74 65 6d 65 6e 74 73 20 28 53 70 61   statements (Spa
4760: 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 74 20  tiaLite support 
4770: 69 73 20 73 74 72 69 63 74 6c 79 20 72 65 71 75  is strictly requ
4780: 69 72 65 64 29 20 77 69 6c 6c 20 74 72 61 6e 73  ired) will trans
4790: 66 65 72 20 61 20 66 75 6c 6c 79 20 71 75 61 6c  fer a fully qual
47a0: 69 66 69 65 64 20 47 65 6f 6d 65 74 72 79 20 74  ified Geometry t
47b0: 61 62 6c 65 20 66 72 6f 6d 20 50 6f 73 74 47 49  able from PostGI
47c0: 53 20 74 6f 20 53 70 61 74 69 61 4c 69 74 65 3a  S to SpatiaLite:
47d0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73  ..<ul>..<li><b>s
47e0: 74 65 70 20 31 3c 2f 62 3e 3a 20 66 69 72 73 74  tep 1</b>: first
47f0: 20 77 65 27 6c 6c 20 74 72 61 6e 73 66 65 72 20   we'll transfer 
4800: 74 68 65 20 77 68 6f 6c 65 20 50 6f 73 74 47 49  the whole PostGI
4810: 53 20 74 61 62 6c 65 20 69 6e 74 6f 20 53 51 4c  S table into SQL
4820: 69 74 65 3b 20 67 65 6f 6d 65 74 72 69 65 73 20  ite; geometries 
4830: 61 72 65 20 73 74 69 6c 6c 20 72 65 70 72 65 73  are still repres
4840: 65 6e 74 65 64 20 62 79 20 74 68 65 69 72 20 3c  ented by their <
4850: 62 3e 45 57 4b 42 3c 2f 62 3e 20 68 65 78 61 64  b>EWKB</b> hexad
4860: 65 63 69 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e 73  ecimal notations
4870: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73  .</li>..<li><b>s
4880: 74 65 70 20 32 3c 2f 62 3e 3a 20 74 68 65 6e 20  tep 2</b>: then 
4890: 77 65 27 6c 6c 20 75 73 65 20 74 68 65 20 3c 62  we'll use the <b
48a0: 3e 47 65 6f 6d 46 72 6f 6d 45 57 4b 42 28 29 3c  >GeomFromEWKB()<
48b0: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  /b> SQL function
48c0: 20 73 6f 20 74 6f 20 67 65 74 20 74 68 65 20 63   so to get the c
48d0: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c 62 3e  orresponding <b>
48e0: 53 70 61 74 69 61 4c 69 74 65 27 73 20 42 4c 4f  SpatiaLite's BLO
48f0: 42 3c 2f 62 3e 20 66 6f 72 20 65 61 63 68 20 67  B</b> for each g
4900: 65 6f 6d 65 74 72 79 2e 3c 2f 6c 69 3e 0d 0a 3c  eometry.</li>..<
4910: 6c 69 3e 3c 62 3e 73 74 65 70 20 33 3c 2f 62 3e  li><b>step 3</b>
4920: 3a 20 6e 6f 77 20 77 65 20 73 69 6d 70 6c 79 20  : now we simply 
4930: 68 61 76 65 20 74 6f 20 64 69 73 63 6f 76 65 72  have to discover
4940: 20 74 68 65 20 54 79 70 65 2c 20 53 52 49 44 20   the Type, SRID 
4950: 61 6e 64 20 44 69 6d 65 6e 73 69 6f 6e 73 20 64  and Dimensions d
4960: 65 63 6c 61 72 65 64 20 62 79 20 74 68 65 73 65  eclared by these
4970: 20 67 65 6f 6d 65 74 72 69 65 73 2e 3c 2f 6c 69   geometries.</li
4980: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 34  >..<li><b>step 4
4990: 3c 2f 62 3e 3a 20 61 6e 64 20 66 69 6e 61 6c 6c  </b>: and finall
49a0: 79 20 77 65 20 63 61 6e 20 6e 6f 77 20 72 65 63  y we can now rec
49b0: 6f 76 65 72 20 61 20 66 75 6c 6c 20 71 75 61 6c  over a full qual
49c0: 69 66 69 65 64 20 53 70 61 74 69 61 4c 69 74 65  ified SpatiaLite
49d0: 27 73 20 6f 77 6e 20 28 3c 69 3e 6e 61 74 69 76  's own (<i>nativ
49e0: 65 3c 2f 69 3e 29 20 47 65 6f 6d 65 74 72 79 20  e</i>) Geometry 
49f0: 63 6f 6c 75 6d 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f  column.</li>..</
4a00: 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c  ul><br>..<hr>..<
4a10: 68 33 3e 65 78 70 6f 72 74 69 6e 67 20 64 61 74  h3>exporting dat
4a20: 61 20 66 72 6f 6d 20 53 51 4c 69 74 65 20 74 6f  a from SQLite to
4a30: 20 50 6f 73 74 67 72 65 73 2f 50 6f 73 74 47 49   Postgres/PostGI
4a40: 53 3c 2f 68 33 3e 0d 0a 46 6f 72 20 72 61 74 68  S</h3>..For rath
4a50: 65 72 20 6f 62 76 69 6f 75 73 20 73 65 63 75 72  er obvious secur
4a60: 69 74 79 20 72 65 61 73 6f 6e 73 2c 20 61 6c 6c  ity reasons, all
4a70: 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73   VirtualPostgres
4a80: 20 74 61 62 6c 65 73 20 61 72 65 20 64 65 63 6c   tables are decl
4a90: 61 72 65 64 20 74 6f 20 62 65 20 3c 69 3e 72 65  ared to be <i>re
4aa0: 61 64 2d 6f 6e 6c 79 3c 2f 69 3e 20 62 79 20 64  ad-only</i> by d
4ab0: 65 66 61 75 6c 74 2e 3c 62 72 3e 0d 0a 54 68 69  efault.<br>..Thi
4ac0: 73 20 61 63 74 75 61 6c 6c 79 20 6d 65 61 6e 73  s actually means
4ad0: 20 74 68 61 74 20 79 6f 75 20 61 72 65 20 65 6e   that you are en
4ae0: 61 62 6c 65 64 20 74 6f 20 65 78 65 63 75 74 65  abled to execute
4af0: 20 61 6e 79 20 70 6f 73 73 69 62 6c 65 20 3c 62   any possible <b
4b00: 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 71 75 65 72  >SELECT</b> quer
4b10: 79 2c 20 62 75 74 20 61 6e 79 20 3c 62 3e 49 4e  y, but any <b>IN
4b20: 53 45 52 54 3c 2f 62 3e 2c 20 3c 62 3e 55 50 44  SERT</b>, <b>UPD
4b30: 41 54 45 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 45  ATE</b> or <b>DE
4b40: 4c 45 54 45 3c 2f 62 3e 20 6f 70 65 72 61 74 69  LETE</b> operati
4b50: 6f 6e 20 61 66 66 65 63 74 69 6e 67 20 74 68 65  on affecting the
4b60: 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 20 69   Postgres DBMS i
4b70: 73 20 73 74 72 69 63 74 6c 79 20 66 6f 72 62 69  s strictly forbi
4b80: 64 64 65 6e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d  dden...<verbatim
4b90: 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54 55 41  >..CREATE VIRTUA
4ba0: 4c 20 54 41 42 4c 45 20 70 67 5f 6f 75 74 20 0d  L TABLE pg_out .
4bb0: 0a 20 20 20 20 55 53 49 4e 47 20 56 69 72 74 75  .    USING Virtu
4bc0: 61 6c 50 6f 73 74 67 72 65 73 20 28 27 68 6f 73  alPostgres ('hos
4bd0: 74 61 64 64 72 3d 31 39 32 2e 31 36 38 2e 31 2e  taddr=192.168.1.
4be0: 39 31 20 70 6f 72 74 3d 35 34 33 32 20 64 62 6e  91 port=5432 dbn
4bf0: 61 6d 65 3d 67 69 73 20 75 73 65 72 3d 73 61 6e  ame=gis user=san
4c00: 64 72 6f 20 70 61 73 73 77 6f 72 64 3d 73 65 63  dro password=sec
4c10: 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 6d 61 2c  ret', my_schema,
4c20: 20 6d 79 5f 74 61 62 6c 65 2c 20 57 29 3b 0d 0a   my_table, W);..
4c30: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 20 73  </verbatim>..A s
4c40: 70 65 63 69 61 6c 20 3c 62 3e 57 3c 2f 62 3e 20  pecial <b>W</b> 
4c50: 66 6c 61 67 20 6d 75 73 74 20 62 65 20 73 70 65  flag must be spe
4c60: 63 69 66 69 65 64 20 77 68 65 6e 20 63 72 65 61  cified when crea
4c70: 74 69 6e 67 20 61 20 56 69 72 74 75 61 6c 50 6f  ting a VirtualPo
4c80: 73 74 67 72 65 73 20 54 61 62 6c 65 20 69 6e 20  stgres Table in 
4c90: 6f 72 64 65 72 20 74 6f 20 61 6c 6c 6f 77 20 66  order to allow f
4ca0: 6f 72 20 75 6e 63 6f 6e 73 74 72 61 69 6e 65 64  or unconstrained
4cb0: 20 3c 69 3e 72 65 61 64 2d 77 72 69 74 65 3c 2f   <i>read-write</
4cc0: 69 3e 20 6f 70 65 72 61 74 69 6f 6e 73 2c 20 74  i> operations, t
4cd0: 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 61 6e  his including an
4ce0: 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e 2c  y <b>INSERT</b>,
4cf0: 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20 6f   <b>UPDATE</b> o
4d00: 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e 20  r <b>DELETE</b> 
4d10: 73 74 61 74 65 6d 65 6e 74 20 61 66 66 65 63 74  statement affect
4d20: 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 73  ing the Postgres
4d30: 20 44 42 4d 53 2e 0d 0a 3c 76 65 72 62 61 74 69   DBMS...<verbati
4d40: 6d 3e 0d 0a 42 45 47 49 4e 3b 0d 0a 0d 0a 44 45  m>..BEGIN;....DE
4d50: 4c 45 54 45 20 46 52 4f 4d 20 70 67 5f 6f 75 74  LETE FROM pg_out
4d60: 3b 0d 0a 0d 0a 49 4e 53 45 52 54 20 49 4e 54 4f  ;....INSERT INTO
4d70: 20 70 67 5f 6f 75 74 20 28 66 6c 64 5f 61 2c 20   pg_out (fld_a, 
4d80: 66 6c 64 5f 62 2c 20 66 6c 64 5f 63 2c 20 67 65  fld_b, fld_c, ge
4d90: 6f 6d 65 74 72 79 29 0d 0a 53 45 4c 45 43 54 20  ometry)..SELECT 
4da0: 66 6c 64 5f 61 2c 20 66 6c 64 5f 62 2c 20 66 6c  fld_a, fld_b, fl
4db0: 64 5f 63 2c 20 41 73 45 57 4b 42 28 67 65 6f 6d  d_c, AsEWKB(geom
4dc0: 65 74 72 79 29 0d 0a 46 52 4f 4d 20 73 6f 6d 65  etry)..FROM some
4dd0: 5f 74 61 62 6c 65 3b 0d 0a 0d 0a 43 4f 4d 4d 49  _table;....COMMI
4de0: 54 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  T;..</verbatim>.
4df0: 0a 49 6e 20 74 68 65 20 61 62 6f 76 65 20 65 78  .In the above ex
4e00: 61 6d 70 6c 65 20 77 65 27 6c 6c 20 64 65 6c 65  ample we'll dele
4e10: 74 65 20 66 69 72 73 74 20 61 6e 79 20 61 6c 72  te first any alr
4e20: 65 61 64 79 20 65 78 69 73 74 69 6e 67 20 72 6f  eady existing ro
4e30: 77 20 66 72 6f 6d 20 74 68 65 20 50 6f 73 74 47  w from the PostG
4e40: 49 53 20 74 61 62 6c 65 3b 20 74 68 65 6e 20 77  IS table; then w
4e50: 65 27 6c 6c 20 73 69 6d 70 6c 79 20 74 72 61 6e  e'll simply tran
4e60: 73 66 65 72 20 74 68 65 20 77 68 6f 6c 65 20 74  sfer the whole t
4e70: 61 62 6c 65 20 66 72 6f 6d 20 53 70 61 74 69 61  able from Spatia
4e80: 4c 69 74 65 20 69 6e 74 6f 20 50 6f 73 74 47 49  Lite into PostGI
4e90: 53 2e 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 20 6e  S.<br>..Please n
4ea0: 6f 74 65 2c 20 77 65 27 6c 6c 20 69 6e 76 6f 6b  ote, we'll invok
4eb0: 65 20 74 68 65 20 3c 62 3e 41 73 45 57 4b 42 28  e the <b>AsEWKB(
4ec0: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69  )</b> SQL functi
4ed0: 6f 6e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 63  on in order to c
4ee0: 6f 6e 76 65 72 74 20 61 6e 79 20 53 70 61 74 69  onvert any Spati
4ef0: 61 4c 69 74 65 27 73 20 6f 77 6e 20 3c 62 3e 42  aLite's own <b>B
4f00: 4c 4f 42 3c 2f 62 3e 20 67 65 6f 6d 65 74 72 79  LOB</b> geometry
4f10: 20 69 6e 74 6f 20 74 68 65 20 65 71 75 69 76 61   into the equiva
4f20: 6c 65 6e 74 20 3c 62 3e 42 59 54 45 41 20 45 57  lent <b>BYTEA EW
4f30: 4b 42 3c 2f 62 3e 20 6e 6f 74 61 74 69 6f 6e 20  KB</b> notation 
4f40: 72 65 71 75 69 72 65 64 20 62 79 20 50 6f 73 74  required by Post
4f50: 47 49 53 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62  GIS.<br><br>..<b
4f60: 3e 4e 6f 74 65 3c 2f 62 3e 3a 20 73 74 61 72 74  >Note</b>: start
4f70: 69 6e 67 20 61 20 54 72 61 6e 73 61 63 74 69 6f  ing a Transactio
4f80: 6e 20 28 3c 62 3e 42 45 47 49 4e 2f 43 4f 4d 4d  n (<b>BEGIN/COMM
4f90: 49 54 3c 2f 62 3e 29 20 6f 6e 20 74 68 65 20 50  IT</b>) on the P
4fa0: 6f 73 67 72 65 53 51 4c 20 73 69 64 65 20 61 6c  osgreSQL side al
4fb0: 77 61 79 73 20 69 73 20 61 20 73 75 67 67 65 73  ways is a sugges
4fc0: 74 65 64 20 67 6f 6f 64 20 70 72 61 63 74 69 63  ted good practic
4fd0: 65 20 77 68 65 6e 20 77 72 69 74 69 6e 67 20 6d  e when writing m
4fe0: 61 6e 79 20 64 61 74 61 20 6f 6e 20 74 68 65 20  any data on the 
4ff0: 50 6f 73 74 67 72 65 53 51 4c 20 74 61 72 67 65  PostgreSQL targe
5000: 74 2c 20 61 6e 64 20 77 69 6c 6c 20 68 61 76 65  t, and will have
5010: 20 61 20 70 6f 73 69 74 69 76 65 20 69 6d 70 61   a positive impa
5020: 63 74 20 6f 6e 20 6f 76 65 72 61 6c 6c 20 70 65  ct on overall pe
5030: 72 66 6f 72 6d 61 6e 63 65 73 2e 3c 62 72 3e 3c  rformances.<br><
5040: 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c  br>..<table cell
5050: 73 70 61 63 69 6e 67 3d 22 36 22 20 63 65 6c 6c  spacing="6" cell
5060: 70 61 64 64 69 6e 67 3d 22 36 22 20 62 67 63 6f  padding="6" bgco
5070: 6c 6f 72 3d 22 23 66 66 66 66 65 38 22 20 77 69  lor="#ffffe8" wi
5080: 64 74 68 3d 22 31 30 30 25 22 3e 0d 0a 3c 74 72  dth="100%">..<tr
5090: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74  ><td align="cent
50a0: 65 72 22 3e 3c 62 3e 43 61 76 65 61 74 3a 20 41  er"><b>Caveat: A
50b0: 73 45 57 4b 42 28 29 3c 2f 62 3e 3c 2f 74 64 3e  sEWKB()</b></td>
50c0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c  </tr>..<tr><td><
50d0: 68 72 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c  hr></td></tr>..<
50e0: 74 72 3e 3c 74 64 3e 0d 0a 41 6c 6c 20 65 61 72  tr><td>..All ear
50f0: 6c 69 65 72 20 76 65 72 73 69 6f 6e 73 20 6f 66  lier versions of
5100: 20 53 70 61 74 69 61 4c 69 74 65 20 72 65 6c 65   SpatiaLite rele
5110: 61 73 65 64 20 62 65 66 6f 72 65 20 3c 62 3e 34  ased before <b>4
5120: 2e 32 2e 30 3c 2f 62 3e 20 73 75 70 70 6f 72 74  .2.0</b> support
5130: 65 64 20 61 20 62 75 67 67 69 73 68 20 41 73 45  ed a buggish AsE
5140: 57 4b 42 28 29 20 69 6d 70 6c 65 6d 65 6e 74 61  WKB() implementa
5150: 74 69 6f 6e 20 63 6f 6d 70 6c 65 74 65 6c 79 20  tion completely 
5160: 75 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65  unable to create
5170: 20 76 61 6c 69 64 20 45 57 4b 42 20 47 65 6f 6d   valid EWKB Geom
5180: 65 74 72 69 65 73 20 74 6f 20 62 65 20 70 61 73  etries to be pas
5190: 73 65 64 20 74 6f 20 50 6f 73 74 47 49 53 2e 3c  sed to PostGIS.<
51a0: 62 72 3e 0d 0a 55 73 69 6e 67 20 76 65 72 73 69  br>..Using versi
51b0: 6f 6e 20 3c 62 3e 34 2e 32 2e 30 3c 2f 62 3e 20  on <b>4.2.0</b> 
51c0: 28 6f 72 20 61 6e 79 20 6c 61 74 65 72 29 20 69  (or any later) i
51d0: 73 20 73 74 72 69 63 74 6c 79 20 72 65 71 75 69  s strictly requi
51e0: 72 65 64 20 73 6f 20 74 6f 20 72 65 61 6c 6c 79  red so to really
51f0: 20 67 65 74 20 61 20 77 6f 72 6b 69 6e 67 20 69   get a working i
5200: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66  mplementation of
5210: 20 41 73 45 57 4b 4b 28 29 2e 0d 0a 3c 2f 74 64   AsEWKK()...</td
5220: 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e  ></tr>..</table>
5230: 0d 0a 3c 62 72 3e 0d 0a 42 61 63 6b 20 74 6f 20  ..<br>..Back to 
5240: 3c 62 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e  <b>VirtualPG</b>
5250: 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a   <a href="https:
5260: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
5270: 74 2f 66 6f 73 73 69 6c 2f 76 69 72 74 75 61 6c  t/fossil/virtual
5280: 70 67 2f 69 6e 64 65 78 22 3e 68 6f 6d 65 20 70  pg/index">home p
5290: 61 67 65 3c 2f 61 3e 0a 5a 20 36 65 30 32 63 34  age</a>.Z 6e02c4
52a0: 39 36 66 30 66 34 39 34 31 37 38 61 37 61 31 34  96f0f494178a7a14
52b0: 36 36 39 63 30 62 66 31 64 66 0a                 669c0bf1df.