Hex Artifact Content
Not logged in

Artifact 77f46060351d496c3e6e4a4059319ff981117d76:

Wiki page [tutorial] by sandro 2013-08-13 15:37:35.
0000: 44 20 32 30 31 33 2d 30 38 2d 31 33 54 31 35 3a  D 2013-08-13T15:
0010: 33 37 3a 33 35 2e 34 38 32 0a 4c 20 74 75 74 6f  37:35.482.L tuto
0020: 72 69 61 6c 0a 50 20 61 37 62 35 39 39 65 61 30  rial.P a7b599ea0
0030: 61 37 32 30 66 61 61 61 63 31 38 65 61 64 39 39  a720faaac18ead99
0040: 31 64 34 30 37 30 66 61 35 64 36 62 38 38 31 0a  1d4070fa5d6b881.
0050: 55 20 73 61 6e 64 72 6f 0a 57 20 31 30 36 31 32  U sandro.W 10612
0060: 0a 3c 68 33 3e 61 62 6f 75 74 20 56 69 72 74 75  .<h3>about Virtu
0070: 61 6c 50 47 3c 2f 68 33 3e 0d 0a 3c 62 3e 56 69  alPG</h3>..<b>Vi
0080: 72 74 75 61 6c 50 47 3c 2f 62 3e 20 69 73 20 61  rtualPG</b> is a
0090: 20 3c 69 3e 6c 6f 61 64 61 62 6c 65 20 64 79 6e   <i>loadable dyn
00a0: 61 6d 69 63 20 65 78 74 65 6e 73 69 6f 6e 20 6d  amic extension m
00b0: 6f 64 75 6c 65 3c 2f 69 3e 20 66 6f 72 20 62 6f  odule</i> for bo
00c0: 74 68 20 3c 62 3e 53 51 4c 69 74 65 3c 2f 62 3e  th <b>SQLite</b>
00d0: 20 61 6e 64 20 3c 62 3e 53 70 61 74 69 61 4c 69   and <b>SpatiaLi
00e0: 74 65 3c 2f 62 3e 3b 20 69 74 73 20 69 6e 74 65  te</b>; its inte
00f0: 6e 64 65 64 20 73 63 6f 70 65 20 69 73 20 73 75  nded scope is su
0100: 70 70 6f 72 74 69 6e 67 20 64 69 72 65 63 74 20  pporting direct 
0110: 64 61 74 61 20 65 78 63 68 61 6e 67 65 20 66 6f  data exchange fo
0120: 72 6d 2f 74 6f 20 3c 62 3e 50 6f 73 74 67 72 65  rm/to <b>Postgre
0130: 53 51 4c 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 50  SQL</b> and <b>P
0140: 6f 73 74 47 49 53 3c 2f 62 3e 20 74 61 72 67 65  ostGIS</b> targe
0150: 74 73 20 73 69 6d 70 6c 79 20 75 73 69 6e 67 20  ts simply using 
0160: 62 61 73 69 63 2c 20 70 6c 61 69 6e 20 3c 69 3e  basic, plain <i>
0170: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 3c 2f  SQL statements</
0180: 69 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20 65 78 74  i>.<br>..The ext
0190: 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 20 73 69  ension module si
01a0: 6d 70 6c 79 20 69 73 20 61 6e 20 6f 72 64 69 6e  mply is an ordin
01b0: 61 72 79 20 3c 69 3e 64 79 6e 61 6d 69 63 20 6c  ary <i>dynamic l
01c0: 69 62 72 61 72 79 3c 2f 69 3e 20 28 3c 62 3e 2e  ibrary</i> (<b>.
01d0: 64 6c 6c 3c 2f 62 3e 20 6f 6e 20 57 69 6e 64 6f  dll</b> on Windo
01e0: 77 73 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 6f  ws, <b>.so</b> o
01f0: 6e 20 55 6e 69 78 20 61 6e 64 20 4c 69 6e 75 78  n Unix and Linux
0200: 2c 20 3c 62 3e 2e 64 79 6c 69 62 3c 2f 62 3e 20  , <b>.dylib</b> 
0210: 6f 6e 20 4d 61 63 20 4f 73 20 58 29 3b 20 73 6f  on Mac Os X); so
0220: 20 74 68 65 20 66 69 72 73 74 20 74 68 69 6e 67   the first thing
0230: 20 74 6f 20 62 65 20 64 6f 6e 65 20 69 6e 20 6f   to be done in o
0240: 72 64 65 72 20 74 6f 20 61 63 74 69 76 61 74 65  rder to activate
0250: 20 74 68 69 73 20 65 78 74 65 6e 73 69 6f 6e 20   this extension 
0260: 69 73 20 6c 6f 61 64 69 6e 67 20 74 68 65 20 63  is loading the c
0270: 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 6c 69 62  orresponding lib
0280: 72 61 72 79 20 66 72 6f 6d 20 61 20 76 61 6c 69  rary from a vali
0290: 64 20 53 51 4c 69 74 65 2f 53 70 61 74 69 61 4c  d SQLite/SpatiaL
02a0: 69 74 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0d  ite connection..
02b0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c  .<verbatim>..SEL
02c0: 45 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69  ECT load_extensi
02d0: 6f 6e 28 27 6c 69 62 76 69 72 74 75 61 6c 70 67  on('libvirtualpg
02e0: 2d 31 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e  -1');..------..N
02f0: 55 4c 4c 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  ULL..</verbatim>
0300: 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72  ..<table bgcolor
0310: 3d 22 23 66 66 66 66 65 38 22 20 77 69 64 74 68  ="#ffffe8" width
0320: 3d 22 31 30 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74  ="100%">..<tr><t
0330: 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22  d align="center"
0340: 3e 3c 62 3e 55 73 65 66 75 6c 20 68 69 6e 74 73  ><b>Useful hints
0350: 20 61 6e 64 20 73 75 67 67 65 73 74 69 6f 6e 73   and suggestions
0360: 3a 20 74 72 6f 75 62 6c 65 73 68 6f 6f 74 69 6e  : troubleshootin
0370: 67 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d  g</b></td></tr>.
0380: 0a 3c 74 72 3e 3c 74 64 3e 3c 68 72 3e 3c 2f 74  .<tr><td><hr></t
0390: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64  d></tr>..<tr><td
03a0: 3e 0d 0a 54 68 69 73 20 6f 70 65 72 61 74 69 6f  >..This operatio
03b0: 6e 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c  n could eventual
03c0: 6c 79 20 66 61 69 6c 20 66 6f 72 20 73 65 76 65  ly fail for seve
03d0: 72 61 6c 20 64 69 66 66 65 72 65 6e 74 20 72 65  ral different re
03e0: 61 73 6f 6e 73 3a 20 68 65 72 65 20 61 72 65 20  asons: here are 
03f0: 74 68 65 20 6d 6f 73 74 20 66 72 65 71 75 65 6e  the most frequen
0400: 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 59  ts:..<ul>..<li>Y
0410: 6f 75 20 61 72 65 20 75 73 69 6e 67 20 73 6f 6d  ou are using som
0420: 65 20 6f 64 64 20 76 65 72 73 69 6f 6e 20 6f 66  e odd version of
0430: 20 53 51 4c 69 74 65 33 2f 6c 69 62 73 71 6c 69   SQLite3/libsqli
0440: 74 65 33 20 66 6f 72 62 69 64 64 69 6e 67 20 74  te3 forbidding t
0450: 6f 20 6c 6f 61 64 20 61 6e 79 20 64 79 6e 61 6d  o load any dynam
0460: 69 63 20 65 78 74 65 6e 73 69 6f 6e 73 2e 3c 62  ic extensions.<b
0470: 72 3e 0d 0a 54 68 69 73 20 66 65 61 74 75 72 65  r>..This feature
0480: 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c   could eventuall
0490: 79 20 62 65 20 64 69 73 61 62 6c 65 64 20 61 74  y be disabled at
04a0: 20 62 75 69 6c 64 20 74 69 6d 65 3b 20 69 66 20   build time; if 
04b0: 74 68 69 73 20 69 73 20 79 6f 75 72 20 63 61 73  this is your cas
04c0: 65 20 79 6f 75 20 73 69 6d 70 6c 65 20 68 61 76  e you simple hav
04d0: 65 20 74 6f 20 73 77 69 74 63 68 20 74 6f 20 73  e to switch to s
04e0: 6f 6d 65 20 64 69 66 66 65 72 65 6e 74 20 53 51  ome different SQ
04f0: 4c 69 74 65 20 74 6f 6f 6c 6b 69 74 20 73 75 70  Lite toolkit sup
0500: 70 6f 72 74 69 6e 67 20 64 79 6e 61 6d 69 63 20  porting dynamic 
0510: 65 78 74 65 6e 73 69 6f 6e 20 6f 72 20 62 75 69  extension or bui
0520: 6c 64 20 6f 6e 65 20 62 79 20 79 6f 75 72 73 65  ld one by yourse
0530: 6c 66 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68  lf.</li>..<li>Th
0540: 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74  e operating syst
0550: 65 6d 20 63 6f 75 6c 64 20 62 65 20 75 6e 61 62  em could be unab
0560: 6c 65 20 74 6f 20 63 6f 72 72 65 63 74 6c 79 20  le to correctly 
0570: 6c 6f 63 61 74 65 20 74 68 65 20 64 79 6e 61 6d  locate the dynam
0580: 69 63 20 6c 69 62 72 61 72 79 20 74 6f 20 62 65  ic library to be
0590: 20 6c 6f 61 64 65 64 2e 3c 62 72 3e 0d 0a 54 68   loaded.<br>..Th
05a0: 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 76 65  e most recent ve
05b0: 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65  rsions of SQLite
05c0: 20 61 72 65 20 73 6d 61 72 74 20 65 6e 6f 75 67   are smart enoug
05d0: 68 20 74 6f 20 61 75 74 6f 6d 61 74 69 63 61 6c  h to automatical
05e0: 6c 79 20 68 61 6e 64 6c 65 20 61 6e 79 20 70 6c  ly handle any pl
05f0: 61 74 66 6f 72 6d 20 73 70 65 63 69 66 69 63 20  atform specific 
0600: 73 75 66 66 69 78 3a 20 73 6f 20 79 6f 75 20 61  suffix: so you a
0610: 72 65 20 6e 6f 20 6c 6f 6e 67 65 72 20 72 65 71  re no longer req
0620: 75 69 72 65 64 20 74 6f 20 73 70 65 63 69 66 79  uired to specify
0630: 20 61 6e 79 20 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e   any <b>.dll</b>
0640: 20 6f 72 20 3c 62 3e 2e 73 6f 3c 2f 62 3e 20 73   or <b>.so</b> s
0650: 75 66 66 69 78 2e 20 49 66 20 79 6f 75 20 77 69  uffix. If you wi
0660: 73 68 20 74 6f 20 64 6f 20 73 6f 2c 20 79 6f 75  sh to do so, you
0670: 20 63 61 6e 20 65 76 65 6e 74 75 61 6c 6c 79 20   can eventually 
0680: 73 70 65 63 69 66 79 20 74 68 65 20 66 75 6c 6c  specify the full
0690: 20 70 61 74 68 20 6c 65 61 64 69 6e 67 20 74 6f   path leading to
06a0: 20 74 68 65 20 64 79 6e 61 6d 69 63 20 6c 69 62   the dynamic lib
06b0: 72 61 72 79 2c 20 74 68 69 73 20 69 6e 63 6c 75  rary, this inclu
06c0: 64 69 6e 67 20 61 6e 79 20 73 75 66 66 69 78 2e  ding any suffix.
06d0: 3c 62 72 3e 0d 0a 41 6e 79 77 61 79 20 74 68 65  <br>..Anyway the
06e0: 20 64 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f   default behavio
06f0: 75 72 20 6f 66 20 3c 62 3e 6c 6f 61 64 5f 65 78  ur of <b>load_ex
0700: 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e 20 69 73  tension()</b> is
0710: 20 74 68 65 20 6f 6e 65 20 74 6f 20 73 65 61 72   the one to sear
0720: 63 68 20 74 68 65 20 72 65 71 75 69 72 65 64 20  ch the required 
0730: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 20  dynamic library 
0740: 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 73 74  following the st
0750: 61 6e 64 61 72 64 20 70 6c 61 74 66 6f 72 6d 20  andard platform 
0760: 73 70 65 63 69 66 69 63 20 72 75 6c 65 73 2e 0d  specific rules..
0770: 0a 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20  .</li>..<li>The 
0780: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 20  dynamic library 
0790: 69 74 73 65 6c 66 20 63 6f 75 6c 64 20 62 65 20  itself could be 
07a0: 63 6f 72 72 65 63 74 6c 79 20 6c 6f 63 61 74 65  correctly locate
07b0: 64 2c 20 62 75 74 20 73 6f 6d 65 20 66 75 72 74  d, but some furt
07c0: 68 65 72 20 64 65 70 65 6e 64 69 6e 67 20 6c 69  her depending li
07d0: 62 72 61 72 79 20 63 6f 75 6c 64 20 6e 6f 74 2c  brary could not,
07e0: 20 74 68 75 73 20 66 6f 72 62 69 64 64 69 6e 67   thus forbidding
07f0: 20 74 6f 20 6c 6f 61 64 20 74 68 65 20 6d 61 69   to load the mai
0800: 6e 20 6c 69 62 72 61 72 79 2e 3c 62 72 3e 0d 0a  n library.<br>..
0810: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f  <u>Please note</
0820: 75 3e 3a 20 3c 62 3e 56 69 72 74 75 61 6c 50 47  u>: <b>VirtualPG
0830: 3c 2f 62 3e 20 64 65 70 65 6e 64 73 20 6f 6e 20  </b> depends on 
0840: 74 68 65 20 50 6f 73 74 67 72 65 53 51 4c 20 6f  the PostgreSQL o
0850: 77 6e 20 63 6c 69 65 6e 74 20 6c 69 62 72 61 72  wn client librar
0860: 79 20 28 3c 62 3e 6c 69 62 70 71 3c 2f 62 3e 29  y (<b>libpq</b>)
0870: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 49 6e 20 61  .</li>..<li>In a
0880: 6e 79 20 63 61 73 65 2c 20 69 66 20 79 6f 75 20  ny case, if you 
0890: 61 72 65 20 75 73 69 6e 67 20 73 6f 6d 65 20 69  are using some i
08a0: 6e 74 65 72 61 63 74 69 76 65 20 74 6f 6f 6c 20  nteractive tool 
08b0: 73 75 63 68 20 61 73 20 3c 62 3e 73 71 6c 69 74  such as <b>sqlit
08c0: 65 33 3c 2f 62 3e 2c 20 3c 62 3e 73 70 61 74 69  e3</b>, <b>spati
08d0: 61 6c 69 74 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e  alite</b> or <b>
08e0: 73 70 61 74 69 61 6c 69 74 65 5f 67 75 69 3c 2f  spatialite_gui</
08f0: 62 3e 20 73 6f 6d 65 20 75 73 65 66 75 6c 20 61  b> some useful a
0900: 6e 64 20 6d 65 61 6e 69 6e 67 66 75 6c 20 65 72  nd meaningful er
0910: 72 6f 72 20 6d 65 73 73 61 67 65 20 77 69 6c 6c  ror message will
0920: 20 73 75 72 65 6c 79 20 62 65 20 64 69 73 70 6c   surely be displ
0930: 61 79 65 64 20 65 78 70 6c 61 69 6e 69 6e 67 20  ayed explaining 
0940: 74 68 65 20 66 61 69 6c 75 72 65 20 63 61 75 73  the failure caus
0950: 65 2e 3c 62 72 3e 0d 0a 54 68 69 73 20 63 6f 75  e.<br>..This cou
0960: 6c 64 20 6e 6f 74 20 62 65 20 73 75 70 70 6f 72  ld not be suppor
0970: 74 65 64 20 77 68 69 6c 65 20 61 74 74 65 6d 70  ted while attemp
0980: 74 69 6e 67 20 74 6f 20 6c 6f 61 64 20 61 6e 20  ting to load an 
0990: 65 78 74 65 6e 73 69 6f 6e 20 66 72 6f 6d 20 73  extension from s
09a0: 6f 6d 65 20 6c 61 6e 67 75 61 67 65 20 62 69 6e  ome language bin
09b0: 64 69 6e 67 20 28 65 2e 67 2e 20 3c 62 3e 2e 4e  ding (e.g. <b>.N
09c0: 45 54 3c 2f 62 3e 2c 20 3c 62 3e 50 79 74 68 6f  ET</b>, <b>Pytho
09d0: 6e 3c 2f 62 3e 20 6f 72 20 3c 62 3e 4a 61 76 61  n</b> or <b>Java
09e0: 3c 2f 62 3e 29 2e 0d 0a 49 6e 20 74 68 69 73 20  </b>)...In this 
09f0: 63 61 73 65 20 61 74 74 65 6d 70 74 69 6e 67 20  case attempting 
0a00: 74 6f 20 69 64 65 6e 74 69 66 79 20 74 68 65 20  to identify the 
0a10: 72 65 61 6c 20 65 72 72 6f 72 20 63 61 75 73 65  real error cause
0a20: 20 63 6f 75 6c 64 20 62 65 20 72 65 61 6c 6c 79   could be really
0a30: 20 70 61 69 6e 66 75 6c 20 64 75 65 20 74 6f 20   painful due to 
0a40: 70 6f 6f 72 20 61 6e 64 20 73 6c 6f 70 70 79 20  poor and sloppy 
0a50: 64 69 61 67 6e 6f 73 74 69 63 20 73 75 70 70 6f  diagnostic suppo
0a60: 72 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 68  rt.</li>..<li>Th
0a70: 65 72 65 20 61 72 65 20 6e 6f 20 75 6e 69 76 65  ere are no unive
0a80: 72 73 61 6c 20 72 75 6c 65 73 20 64 69 63 74 61  rsal rules dicta
0a90: 74 69 6e 67 20 77 68 65 72 65 20 74 6f 20 70 6c  ting where to pl
0aa0: 61 63 65 20 79 6f 75 72 20 65 78 74 65 6e 73 69  ace your extensi
0ab0: 6f 6e 20 6d 6f 64 75 6c 65 73 3b 20 61 20 67 6f  on modules; a go
0ac0: 6f 64 20 73 75 67 67 65 73 74 69 6f 6e 20 69 73  od suggestion is
0ad0: 20 74 6f 20 61 6c 77 61 79 73 20 70 6c 61 63 65   to always place
0ae0: 20 61 6c 6c 20 74 68 65 6d 20 69 6e 20 74 68 65   all them in the
0af0: 20 6d 6f 73 74 20 61 70 70 72 6f 70 72 69 61 74   most appropriat
0b00: 65 20 73 79 73 74 65 6d 20 64 69 72 65 63 74 6f  e system directo
0b10: 72 79 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d  ry.</li>..</ul>.
0b20: 0a 3c 62 3e 49 6d 70 6f 72 74 61 6e 74 20 6e 6f  .<b>Important no
0b30: 74 69 63 65 3c 2f 62 3e 3a 20 74 68 65 20 76 65  tice</b>: the ve
0b40: 72 79 20 72 65 63 65 6e 74 20 53 51 4c 69 74 65  ry recent SQLite
0b50: 20 3c 62 3e 33 2e 37 2e 31 37 3c 2f 62 3e 20 69   <b>3.7.17</b> i
0b60: 6e 74 72 6f 64 75 63 65 64 20 6d 61 6e 79 20 69  ntroduced many i
0b70: 6e 74 65 72 65 73 74 69 6e 67 20 61 64 76 61 6e  nteresting advan
0b80: 63 65 64 20 66 65 61 74 75 72 65 73 20 74 6f 20  ced features to 
0b90: 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f  <b>load_extensio
0ba0: 6e 28 29 3c 2f 62 3e 3b 0d 0a 65 61 72 6c 69 65  n()</b>;..earlie
0bb0: 72 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 53 51  r versions of SQ
0bc0: 4c 69 74 65 20 63 6f 75 6c 64 20 70 72 6f 62 61  Lite could proba
0bd0: 62 6c 79 20 62 65 20 73 6f 6d 65 77 61 79 20 6c  bly be someway l
0be0: 69 6d 69 74 65 64 2e 0d 0a 49 66 20 74 68 69 73  imited...If this
0bf0: 20 69 73 20 79 6f 75 72 20 63 61 73 65 2c 20 70   is your case, p
0c00: 6c 65 61 73 65 20 63 6f 6e 73 69 64 65 72 20 74  lease consider t
0c10: 68 61 74 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  hat:..<ul>..<li>
0c20: 73 70 65 63 69 66 79 69 6e 67 20 61 6e 79 20 3c  specifying any <
0c30: 62 3e 2e 64 6c 6c 3c 2f 62 3e 2c 20 3c 62 3e 2e  b>.dll</b>, <b>.
0c40: 73 6f 3c 2f 62 3e 20 6f 72 20 3c 62 3e 2e 64 79  so</b> or <b>.dy
0c50: 6c 69 62 3c 2f 62 3e 20 73 75 66 66 69 78 20 63  lib</b> suffix c
0c60: 6f 75 6c 64 20 62 65 20 73 74 72 69 63 74 6c 79  ould be strictly
0c70: 20 72 65 71 75 69 72 65 64 2e 3c 2f 6c 69 3e 0d   required.</li>.
0c80: 0a 3c 6c 69 3e 61 73 20 69 74 20 63 6f 75 6c 64  .<li>as it could
0c90: 20 62 65 20 72 65 71 75 69 72 65 64 20 74 6f 20   be required to 
0ca0: 65 78 70 6c 69 63 69 74 6c 79 20 73 70 65 63 69  explicitly speci
0cb0: 66 79 20 74 68 65 20 65 78 74 65 6e 73 69 6f 6e  fy the extension
0cc0: 20 65 6e 74 72 79 20 70 6f 69 6e 74 2e 3c 2f 6c   entry point.</l
0cd0: 69 3e 0d 0a 3c 6c 69 3e 61 63 63 6f 72 64 69 6e  i>..<li>accordin
0ce0: 67 6c 79 20 74 6f 20 61 6c 6c 20 74 68 69 73 2c  gly to all this,
0cf0: 20 79 6f 75 27 6c 6c 20 70 72 6f 62 61 62 6c 79   you'll probably
0d00: 20 62 65 20 72 65 71 75 69 72 65 64 20 74 6f 20   be required to 
0d10: 70 61 73 73 20 61 72 67 75 6d 65 6e 74 73 20 6c  pass arguments l
0d20: 69 6b 65 20 74 6f 20 66 6f 6c 6c 6f 77 69 6e 67  ike to following
0d30: 20 6f 6e 65 73 20 74 6f 20 3c 62 3e 6c 6f 61 64   ones to <b>load
0d40: 5f 65 78 74 65 6e 73 69 6f 6e 28 29 3c 2f 62 3e  _extension()</b>
0d50: 20 77 68 69 6c 65 20 75 73 69 6e 67 20 73 6f 6d   while using som
0d60: 65 20 6f 62 73 6f 6c 65 74 65 20 53 51 4c 69 74  e obsolete SQLit
0d70: 65 33 20 76 65 72 73 69 6f 6e 2e 3c 2f 6c 69 3e  e3 version.</li>
0d80: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
0d90: 4c 45 43 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73  LECT load_extens
0da0: 69 6f 6e 28 27 2f 75 73 72 2f 6c 6f 63 61 6c 2f  ion('/usr/local/
0db0: 6c 69 62 2f 6c 69 62 76 69 72 74 75 61 6c 70 67  lib/libvirtualpg
0dc0: 2e 73 6f 27 2c 20 27 73 71 6c 69 74 65 33 5f 76  .so', 'sqlite3_v
0dd0: 69 72 74 75 61 6c 70 67 5f 69 6e 69 74 27 29 3b  irtualpg_init');
0de0: 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a  ..------..NULL..
0df0: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 2f 75  </verbatim>..</u
0e00: 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a  l>..</td></tr>..
0e10: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 68  </table><br>..<h
0e20: 72 3e 0d 0a 3c 68 33 3e 63 72 6f 73 73 2d 44 42  r>..<h3>cross-DB
0e30: 4d 53 20 64 61 74 61 20 65 78 63 68 61 6e 67 65  MS data exchange
0e40: 3a 20 53 51 4c 20 61 6e 64 20 56 69 72 74 75 61  : SQL and Virtua
0e50: 6c 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 73  lPostgres tables
0e60: 3c 2f 68 33 3e 0d 0a 41 66 74 65 72 20 73 75 63  </h3>..After suc
0e70: 63 65 73 73 66 75 6c 6c 79 20 6c 6f 61 64 69 6e  cessfully loadin
0e80: 67 20 74 68 65 20 3c 62 3e 76 69 72 74 75 61 6c  g the <b>virtual
0e90: 70 67 3c 2f 62 3e 20 64 79 6e 61 6d 69 63 20 65  pg</b> dynamic e
0ea0: 78 74 65 6e 73 69 6f 6e 20 79 6f 75 20 61 72 65  xtension you are
0eb0: 20 6e 6f 77 20 72 65 61 64 79 20 74 6f 20 63 72   now ready to cr
0ec0: 65 61 74 65 20 3c 62 3e 56 69 72 74 75 61 6c 50  eate <b>VirtualP
0ed0: 6f 73 74 67 65 73 3c 2f 62 3e 20 74 61 62 6c 65  ostges</b> table
0ee0: 73 2e 3c 62 72 3e 0d 0a 54 68 65 73 65 20 61 72  s.<br>..These ar
0ef0: 65 20 3c 69 3e 71 75 69 74 65 20 61 6c 6d 6f 73  e <i>quite almos
0f00: 74 3c 2f 69 3e 20 6f 72 64 69 6e 61 72 79 20 44  t</i> ordinary D
0f10: 42 20 74 61 62 6c 65 73 20 61 73 20 61 6e 79 20  B tables as any 
0f20: 6f 74 68 65 72 3b 20 79 6f 75 20 63 61 6e 20 65  other; you can e
0f30: 78 65 63 75 74 65 20 61 6e 79 20 72 65 67 75 6c  xecute any regul
0f40: 61 72 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74  ar SQL statement
0f50: 20 28 3c 69 3e 53 45 4c 45 43 54 3c 2f 69 3e 2c   (<i>SELECT</i>,
0f60: 20 3c 69 3e 49 4e 53 45 52 54 3c 2f 69 3e 2c 20   <i>INSERT</i>, 
0f70: 3c 69 3e 55 50 44 41 54 45 3c 2f 69 3e 20 6f 72  <i>UPDATE</i> or
0f80: 20 3c 69 3e 44 45 4c 45 54 45 3c 2f 69 3e 29 20   <i>DELETE</i>) 
0f90: 62 79 20 73 70 65 63 69 66 79 69 6e 67 20 74 68  by specifying th
0fa0: 65 73 65 20 56 69 72 74 75 61 6c 20 54 61 62 6c  ese Virtual Tabl
0fb0: 65 73 20 61 73 20 74 68 65 20 73 65 6c 65 63 74  es as the select
0fc0: 65 64 20 74 61 72 67 65 74 2e 3c 62 72 3e 0d 0a  ed target.<br>..
0fd0: 54 68 65 72 65 20 69 73 20 6f 6e 6c 79 20 61 20  There is only a 
0fe0: 73 74 72 6f 6e 67 20 64 69 66 66 65 72 65 6e 63  strong differenc
0ff0: 65 20 64 69 73 74 69 6e 67 75 69 73 68 69 6e 67  e distinguishing
1000: 20 61 20 3c 62 3e 56 69 72 74 75 61 6c 50 6f 73   a <b>VirtualPos
1010: 74 67 72 65 73 3c 2f 62 3e 20 74 61 62 6c 65 3b  tgres</b> table;
1020: 20 69 74 27 73 20 70 68 79 73 69 63 61 6c 20 6c   it's physical l
1030: 6f 63 61 74 69 6f 6e 20 69 73 6e 27 74 20 77 69  ocation isn't wi
1040: 74 68 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74  thin the current
1050: 6c 79 20 63 6f 6e 6e 65 63 74 65 64 20 53 51 4c  ly connected SQL
1060: 69 74 65 20 44 42 2c 20 62 75 74 20 69 73 20 69  ite DB, but is i
1070: 6e 73 74 65 61 64 20 77 69 74 68 69 6e 20 73 6f  nstead within so
1080: 6d 65 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c  me <b>PostgreSQL
1090: 3c 2f 62 3e 20 44 42 4d 53 2e 3c 62 72 3e 0d 0a  </b> DBMS.<br>..
10a0: 53 6f 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74  So a VirtualPost
10b0: 67 72 65 73 20 74 61 62 6c 65 20 65 66 66 65 63  gres table effec
10c0: 74 69 76 65 6c 79 20 61 63 74 73 20 61 73 20 61  tively acts as a
10d0: 20 3c 69 3e 62 72 69 64 67 65 3c 2f 69 3e 20 6a   <i>bridge</i> j
10e0: 6f 69 6e 69 6e 67 20 53 51 4c 69 74 65 20 61 6e  oining SQLite an
10f0: 64 20 50 6f 73 74 67 72 65 73 2c 20 61 6e 64 20  d Postgres, and 
1100: 61 6c 6c 6f 77 69 6e 67 20 74 6f 20 70 65 72 66  allowing to perf
1110: 6f 72 6d 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20  orm any kind of 
1120: 63 72 6f 73 73 20 64 61 74 61 20 65 78 63 68 61  cross data excha
1130: 6e 67 65 20 28 3c 69 3e 69 6e 20 62 6f 74 68 20  nge (<i>in both 
1140: 64 69 72 65 63 74 69 6f 6e 73 3c 2f 69 3e 29 20  directions</i>) 
1150: 69 6e 20 74 68 65 20 65 61 73 69 65 73 74 20 77  in the easiest w
1160: 61 79 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  ay...<verbatim>.
1170: 0a 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20  .CREATE VIRTUAL 
1180: 54 41 42 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20  TABLE pg_in ..  
1190: 20 20 55 53 49 4e 47 20 56 69 72 74 75 61 6c 50    USING VirtualP
11a0: 6f 73 74 67 72 65 73 20 28 27 68 6f 73 74 3d 6c  ostgres ('host=l
11b0: 6f 63 61 6c 68 6f 73 74 20 70 6f 72 74 3d 35 34  ocalhost port=54
11c0: 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 73  32 dbname=gis us
11d0: 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 6f  er=sandro passwo
11e0: 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f 73  rd=secret', my_s
11f0: 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29  chema, my_table)
1200: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  ;..</verbatim>..
1210: 54 68 69 73 20 53 51 4c 20 73 74 61 74 65 6d 65  This SQL stateme
1220: 6e 74 20 77 69 6c 6c 20 63 72 65 61 74 65 20 69  nt will create i
1230: 6e 74 6f 20 74 68 65 20 53 51 4c 69 74 65 20 44  nto the SQLite D
1240: 42 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 64 20  B a table named 
1250: 3c 62 3e 70 67 5f 69 6e 3c 2f 62 3e 3b 20 61 6e  <b>pg_in</b>; an
1260: 79 77 61 79 20 74 68 65 20 64 61 74 61 20 70 68  yway the data ph
1270: 79 73 69 63 61 6c 20 73 74 6f 72 61 67 65 20 66  ysical storage f
1280: 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 77 69  or this table wi
1290: 6c 6c 20 62 65 20 69 6e 74 6f 20 74 68 65 20 50  ll be into the P
12a0: 6f 73 74 67 72 65 73 20 44 42 4d 53 3a 0d 0a 3c  ostgres DBMS:..<
12b0: 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 66 69 72  ul>..<li>the fir
12c0: 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 56  st argument to V
12d0: 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 69  irtualPostgres i
12e0: 73 20 74 68 65 20 3c 69 3e 63 6f 6e 6e 65 63 74  s the <i>connect
12f0: 69 6f 6e 20 73 74 72 69 6e 67 3c 2f 69 3e 20 72  ion string</i> r
1300: 65 71 75 69 72 65 64 20 69 6e 20 6f 72 64 65 72  equired in order
1310: 20 74 6f 20 65 73 74 61 62 6c 69 73 68 20 61 20   to establish a 
1320: 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 74 68  connection to th
1330: 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 20  e Postgres DBMS 
1340: 73 65 72 76 65 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  server.</li>..<l
1350: 69 3e 73 65 63 6f 6e 64 20 61 6e 64 20 74 68 69  i>second and thi
1360: 72 64 20 61 72 67 75 6d 65 6e 74 73 20 72 65 73  rd arguments res
1370: 70 65 63 74 69 76 65 6c 79 20 61 72 65 20 74 68  pectively are th
1380: 65 20 3c 69 3e 73 63 68 65 6d 61 20 6e 61 6d 65  e <i>schema name
1390: 3c 2f 69 3e 20 61 6e 64 20 74 68 65 20 3c 69 3e  </i> and the <i>
13a0: 74 61 62 6c 65 20 6e 61 6d 65 3c 2f 69 3e 20 69  table name</i> i
13b0: 64 65 6e 74 69 66 79 69 6e 67 20 74 68 65 20 50  dentifying the P
13c0: 6f 73 74 67 72 65 73 20 74 61 72 67 65 74 20 74  ostgres target t
13d0: 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c  able.</li>..</ul
13e0: 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43  >..<verbatim>..C
13f0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
1400: 42 4c 45 20 70 67 5f 69 6e 20 0d 0a 20 20 20 20  BLE pg_in ..    
1410: 55 53 49 4e 47 20 56 69 72 74 75 61 6c 50 6f 73  USING VirtualPos
1420: 74 67 72 65 73 20 28 27 68 6f 73 74 61 64 64 72  tgres ('hostaddr
1430: 3d 31 39 32 2e 31 36 38 2e 31 2e 39 31 20 70 6f  =192.168.1.91 po
1440: 72 74 3d 35 34 33 32 20 64 62 6e 61 6d 65 3d 67  rt=5432 dbname=g
1450: 69 73 20 75 73 65 72 3d 73 61 6e 64 72 6f 20 70  is user=sandro p
1460: 61 73 73 77 6f 72 64 3d 73 65 63 72 65 74 27 2c  assword=secret',
1470: 20 6d 79 5f 73 63 68 65 6d 61 2c 20 6d 79 5f 74   my_schema, my_t
1480: 61 62 6c 65 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  able);..</verbat
1490: 69 6d 3e 0d 0a 53 61 6d 65 20 61 73 20 61 62 6f  im>..Same as abo
14a0: 76 65 2c 20 74 68 65 20 74 69 6d 65 20 65 73 74  ve, the time est
14b0: 61 62 6c 69 73 68 69 6e 67 20 61 20 63 6f 6e 6e  ablishing a conn
14c0: 65 63 74 69 6f 6e 20 74 6f 20 61 20 50 6f 73 74  ection to a Post
14d0: 67 72 65 73 20 69 6e 73 74 61 6e 63 65 20 72 75  gres instance ru
14e0: 6e 6e 69 6e 67 20 6f 6e 20 73 6f 6d 65 20 64 69  nning on some di
14f0: 66 66 65 72 65 6e 63 74 20 63 6f 6d 70 75 74 65  fferenct compute
1500: 72 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 6c 6f  r on the same lo
1510: 63 61 6c 20 61 72 65 61 20 6e 65 74 77 6f 72 6b  cal area network
1520: 2e 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 20 63 6f  .<br>..Please co
1530: 6e 73 75 6c 74 20 74 68 65 20 50 6f 73 74 67 72  nsult the Postgr
1540: 65 73 20 6f 77 6e 20 64 6f 63 75 6d 65 6e 74 61  es own documenta
1550: 74 69 6f 6e 20 66 6f 72 20 61 6e 79 20 6f 74 68  tion for any oth
1560: 65 72 20 64 65 74 61 69 6c 20 61 62 6f 75 74 20  er detail about 
1570: 3c 69 3e 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 74  <i>connection st
1580: 72 69 6e 67 73 3c 2f 69 3e 2e 0d 0a 3c 76 65 72  rings</i>...<ver
1590: 62 61 74 69 6d 3e 0d 0a 50 52 41 47 4d 41 20 74  batim>..PRAGMA t
15a0: 61 62 6c 65 5f 69 6e 66 6f 28 70 67 5f 69 6e 29  able_info(pg_in)
15b0: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  ;..</verbatim>..
15c0: 59 6f 75 20 63 61 6e 20 65 78 65 63 75 74 65 20  You can execute 
15d0: 74 68 65 20 61 62 6f 76 65 20 50 52 41 47 4d 41  the above PRAGMA
15e0: 20 64 69 72 65 63 74 69 76 65 20 69 6e 20 6f 72   directive in or
15f0: 64 65 72 20 74 6f 20 69 64 65 6e 74 69 66 79 20  der to identify 
1600: 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 64 65 63 6c  all columns decl
1610: 61 72 65 64 20 62 79 20 74 68 65 20 50 6f 73 74  ared by the Post
1620: 67 72 65 73 20 74 61 62 6c 65 2c 20 61 6e 64 20  gres table, and 
1630: 74 68 65 69 72 20 63 6f 72 72 65 73 70 6f 6e 64  their correspond
1640: 69 6e 67 20 64 61 74 61 2d 74 79 70 65 2e 3c 62  ing data-type.<b
1650: 72 3e 0d 0a 49 66 20 79 6f 75 20 61 72 65 20 61  r>..If you are a
1660: 63 74 75 61 6c 6c 79 20 75 73 69 6e 67 20 3c 62  ctually using <b
1670: 3e 73 70 61 74 69 61 6c 69 74 65 5f 67 75 69 3c  >spatialite_gui<
1680: 2f 62 3e 20 79 6f 75 20 63 61 6e 20 63 68 65 63  /b> you can chec
1690: 6b 20 74 68 65 20 73 61 6d 65 20 69 6e 66 6f 73  k the same infos
16a0: 20 62 79 20 75 73 69 6e 67 20 74 68 65 20 61 70   by using the ap
16b0: 70 72 6f 70 72 69 61 74 65 20 67 72 61 70 68 69  propriate graphi
16c0: 63 73 20 74 6f 6f 6c 73 2e 0d 0a 3c 76 65 72 62  cs tools...<verb
16d0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2c  atim>..SELECT a,
16e0: 20 62 2c 20 63 2c 20 43 6f 75 6e 74 28 2a 29 20   b, c, Count(*) 
16f0: 41 53 20 63 6e 74 0d 0a 46 52 4f 4d 20 70 67 5f  AS cnt..FROM pg_
1700: 69 6e 0d 0a 57 48 45 52 45 20 65 20 49 53 20 4e  in..WHERE e IS N
1710: 4f 54 20 4e 55 4c 4c 0d 0a 47 52 4f 55 50 20 42  OT NULL..GROUP B
1720: 59 20 61 2c 20 62 2c 20 63 0d 0a 4f 52 44 45 52  Y a, b, c..ORDER
1730: 20 42 59 20 63 6e 74 20 44 45 53 43 3b 0d 0a 3c   BY cnt DESC;..<
1740: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20  /verbatim>..You 
1750: 63 61 6e 20 65 78 65 63 75 74 65 20 61 6e 79 20  can execute any 
1760: 6b 69 6e 64 20 6f 66 20 3c 62 3e 53 45 4c 45 43  kind of <b>SELEC
1770: 54 3c 2f 62 3e 20 71 75 65 72 79 20 75 73 69 6e  T</b> query usin
1780: 67 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74 67  g a VirtualPostg
1790: 72 65 73 20 74 61 62 6c 65 2c 20 65 78 61 63 74  res table, exact
17a0: 6c 79 20 61 73 20 69 66 20 69 74 20 77 61 73 20  ly as if it was 
17b0: 61 20 67 65 6e 75 69 6e 65 20 6e 61 74 69 76 65  a genuine native
17c0: 20 74 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 61 74   table...<verbat
17d0: 69 6d 3e 0d 0a 43 52 45 41 54 45 20 54 41 42 4c  im>..CREATE TABL
17e0: 45 20 69 6d 70 6f 72 74 65 64 5f 66 72 6f 6d 5f  E imported_from_
17f0: 70 67 20 41 53 0d 0a 53 45 4c 45 43 54 20 2a 20  pg AS..SELECT * 
1800: 46 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 3c 2f 76  FROM pg_in;..</v
1810: 65 72 62 61 74 69 6d 3e 0d 0a 41 6e 64 20 79 6f  erbatim>..And yo
1820: 75 20 63 61 6e 20 6f 62 76 69 6f 75 73 6c 79 20  u can obviously 
1830: 63 72 65 61 74 65 20 61 6e 64 20 70 6f 70 75 6c  create and popul
1840: 61 74 65 20 61 20 6c 6f 63 61 6c 20 63 6f 70 79  ate a local copy
1850: 20 6f 66 20 74 68 65 20 72 65 6d 6f 74 65 20 50   of the remote P
1860: 6f 73 74 67 72 65 73 20 74 61 62 6c 65 3a 20 6e  ostgres table: n
1870: 6f 77 20 61 6c 6c 20 64 61 74 61 20 61 72 65 20  ow all data are 
1880: 70 65 72 6d 61 6e 65 6e 74 6c 79 20 73 74 6f 72  permanently stor
1890: 65 64 20 77 69 74 68 69 6e 20 79 6f 75 72 20 53  ed within your S
18a0: 51 4c 69 74 65 20 44 42 2e 0d 0a 3c 76 65 72 62  QLite DB...<verb
18b0: 61 74 69 6d 3e 0d 0a 44 52 4f 50 20 54 41 42 4c  atim>..DROP TABL
18c0: 45 20 70 67 5f 69 6e 3b 0d 0a 3c 2f 76 65 72 62  E pg_in;..</verb
18d0: 61 74 69 6d 3e 0d 0a 53 6f 20 79 6f 75 20 63 61  atim>..So you ca
18e0: 6e 20 66 69 6e 61 6c 6c 79 20 64 72 6f 70 20 74  n finally drop t
18f0: 68 65 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72  he VirtualPostgr
1900: 65 73 20 74 61 62 6c 65 2c 20 61 6e 64 20 74 68  es table, and th
1910: 69 73 20 77 69 6c 6c 20 69 6d 6d 65 64 69 61 74  is will immediat
1920: 65 6c 79 20 74 65 72 6d 69 6e 61 74 65 20 74 68  ely terminate th
1930: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20  e connection to 
1940: 74 68 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d  the Postgres DBM
1950: 53 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e  S.<br><br>..<hr>
1960: 0d 0a 3c 68 33 3e 64 61 74 61 2d 74 79 70 65 20  ..<h3>data-type 
1970: 6d 61 70 70 69 6e 67 20 61 6e 64 20 72 65 6c 61  mapping and rela
1980: 74 65 64 20 63 6f 6e 76 65 72 73 69 6f 6e 73 3c  ted conversions<
1990: 2f 68 33 3e 0d 0a 52 61 74 68 65 72 20 6f 62 76  /h3>..Rather obv
19a0: 69 6f 75 73 6c 79 20 53 51 4c 69 74 65 20 61 6e  iously SQLite an
19b0: 64 20 50 6f 73 74 67 72 65 73 20 73 75 70 70 6f  d Postgres suppo
19c0: 72 74 73 20 76 65 72 79 20 64 69 66 66 65 72 65  rts very differe
19d0: 6e 74 20 6b 69 6e 64 20 6f 66 20 64 61 74 61 2d  nt kind of data-
19e0: 74 79 70 65 73 2e 20 54 68 65 20 66 65 77 20 66  types. The few f
19f0: 6f 6c 6c 6f 77 69 6e 67 20 72 75 6c 65 73 20 61  ollowing rules a
1a00: 70 70 6c 79 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  pply:..<ul>..<li
1a10: 3e 61 6e 79 20 6b 69 6e 64 20 6f 66 20 3c 62 3e  >any kind of <b>
1a20: 49 4e 54 45 47 45 52 3c 2f 62 3e 20 76 61 6c 75  INTEGER</b> valu
1a30: 65 20 69 73 20 70 72 65 73 65 72 76 65 64 20 61  e is preserved a
1a40: 73 20 73 75 63 68 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  s such.</li>..<l
1a50: 69 3e 74 68 65 20 73 61 6d 65 20 69 73 20 66 6f  i>the same is fo
1a60: 72 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76  r <b>FLOAT</b> v
1a70: 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  alues.</li>..<li
1a80: 3e 3c 62 3e 4d 4f 4e 45 59 3c 2f 62 3e 20 61 6e  ><b>MONEY</b> an
1a90: 64 20 3c 62 3e 4e 55 4d 45 52 49 43 3c 2f 62 3e  d <b>NUMERIC</b>
1aa0: 20 76 61 6c 75 65 73 20 61 72 65 20 63 6f 6e 76   values are conv
1ab0: 65 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e 46 4c  erted into <b>FL
1ac0: 4f 41 54 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c  OAT</b> values.<
1ad0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 43 48 41  /li>..<li><b>CHA
1ae0: 52 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 56 41 52  R</b> and <b>VAR
1af0: 43 48 41 52 3c 2f 62 3e 20 76 61 6c 75 65 73 20  CHAR</b> values 
1b00: 61 72 65 20 61 6c 77 61 79 73 20 63 6f 6e 76 65  are always conve
1b10: 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e 54 45 58  rted into <b>TEX
1b20: 54 3c 2f 62 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c  T</b> values.</l
1b30: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 44 41 54 45 3c  i>..<li><b>DATE<
1b40: 2f 62 3e 2c 20 3c 62 3e 54 49 4d 45 3c 2f 62 3e  /b>, <b>TIME</b>
1b50: 20 61 6e 64 20 3c 62 3e 54 49 4d 45 53 54 41 4d   and <b>TIMESTAM
1b60: 50 3c 2f 62 3e 20 76 61 6c 75 65 73 20 61 72 65  P</b> values are
1b70: 20 61 6c 77 61 79 73 20 63 6f 6e 76 65 72 74 65   always converte
1b80: 64 20 69 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c  d into <b>FLOAT<
1b90: 2f 62 3e 20 76 61 6c 75 65 73 20 63 6f 72 72 65  /b> values corre
1ba0: 73 70 6f 6e 64 69 6e 67 20 74 6f 20 74 68 65 20  sponding to the 
1bb0: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f  <a href="http://
1bc0: 77 77 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f 6c  www.sqlite.org/l
1bd0: 61 6e 67 5f 64 61 74 65 66 75 6e 63 2e 68 74 6d  ang_datefunc.htm
1be0: 6c 22 3e 4a 75 6c 69 61 6e 44 61 79 3c 2f 61 3e  l">JulianDay</a>
1bf0: 20 6e 6f 74 61 74 69 6f 6e 20 73 75 70 70 6f 72   notation suppor
1c00: 74 65 64 20 62 79 20 53 51 4c 69 74 65 2e 3c 62  ted by SQLite.<b
1c10: 72 3e 0d 0a 59 6f 75 20 63 61 6e 20 74 68 65 6e  r>..You can then
1c20: 20 69 6e 76 6f 6b 65 20 74 68 65 20 61 70 70 72   invoke the appr
1c30: 6f 70 72 69 61 74 65 20 66 75 6e 63 74 69 6f 6e  opriate function
1c40: 20 62 65 74 77 65 65 6e 20 3c 62 3e 44 61 74 65   between <b>Date
1c50: 28 29 3c 2f 62 3e 2c 20 3c 62 3e 54 69 6d 65 28  ()</b>, <b>Time(
1c60: 29 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 61 74 65  )</b> or <b>Date
1c70: 54 69 6d 65 28 29 3c 2f 62 3e 20 73 6f 20 74 6f  Time()</b> so to
1c80: 20 67 65 74 20 62 61 63 6b 20 74 68 65 20 73 74   get back the st
1c90: 61 6e 64 61 72 64 20 53 51 4c 20 6e 6f 74 61 74  andard SQL notat
1ca0: 69 6f 6e 20 66 6f 72 20 64 61 74 65 73 20 61 6e  ion for dates an
1cb0: 64 20 74 69 6d 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c  d times.</li>..<
1cc0: 6c 69 3e 3c 62 3e 42 4f 4f 4c 3c 2f 62 3e 20 76  li><b>BOOL</b> v
1cd0: 61 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 73  alues are always
1ce0: 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20   converted into 
1cf0: 3c 62 3e 49 4e 54 45 47 45 52 3c 2f 62 3e 20 76  <b>INTEGER</b> v
1d00: 61 6c 75 65 73 3a 20 3c 62 3e 30 3c 2f 62 3e 20  alues: <b>0</b> 
1d10: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f  corresponding to
1d20: 20 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 2e 3c 2f   <b>FALSE</b>.</
1d30: 6c 69 3e 0d 0a 3c 6c 69 3e 50 6f 73 74 67 72 65  li>..<li>Postgre
1d40: 73 20 73 75 70 70 6f 72 74 73 20 6d 75 6c 74 69  s supports multi
1d50: 70 6c 65 20 76 61 6c 75 65 73 20 74 6f 20 62 65  ple values to be
1d60: 20 73 74 6f 72 65 64 20 69 6e 74 6f 20 74 68 65   stored into the
1d70: 20 73 61 6d 65 20 63 6f 6c 75 6d 6e 20 28 3c 62   same column (<b
1d80: 3e 41 52 52 41 59 3c 2f 62 3e 29 3a 20 53 51 4c  >ARRAY</b>): SQL
1d90: 69 74 65 20 68 61 73 20 6e 6f 20 73 69 6d 69 6c  ite has no simil
1da0: 61 72 20 63 61 70 61 62 69 6c 69 74 79 2c 20 73  ar capability, s
1db0: 6f 20 61 6e 79 20 41 52 52 41 59 20 76 61 6c 75  o any ARRAY valu
1dc0: 65 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 62 65  e will simply be
1dd0: 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f 20   converted into 
1de0: 61 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 73 74  a <b>TEXT</b> st
1df0: 72 69 6e 67 2c 20 65 2e 67 2e 20 61 73 20 69 6e  ring, e.g. as in
1e00: 20 3c 62 3e 27 7b 31 2c 32 2c 33 7d 27 3c 2f 62   <b>'{1,2,3}'</b
1e10: 3e 20 6f 72 20 3c 62 3e 27 7b 61 6c 70 68 61 2c  > or <b>'{alpha,
1e20: 62 65 74 61 2c 67 61 6d 6d 61 2c 64 65 6c 74 61  beta,gamma,delta
1e30: 7d 27 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  }'</b>.</li>..<l
1e40: 69 3e 61 6e 79 20 62 69 6e 61 72 79 20 76 61 6c  i>any binary val
1e50: 75 65 20 28 61 73 20 65 2e 67 2e 20 3c 62 3e 42  ue (as e.g. <b>B
1e60: 59 54 45 41 3c 2f 62 3e 29 20 77 69 6c 6c 20 62  YTEA</b>) will b
1e70: 65 20 73 69 6d 70 6c 79 20 63 6f 6e 76 65 72 74  e simply convert
1e80: 65 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 45 58  ed into a <b>TEX
1e90: 54 3c 2f 62 3e 20 76 61 6c 75 65 20 63 6f 6e 74  T</b> value cont
1ea0: 61 69 6e 69 6e 67 20 74 68 65 20 63 6f 72 72 65  aining the corre
1eb0: 73 70 6f 6e 64 69 6e 67 20 68 65 78 61 64 65 63  sponding hexadec
1ec0: 69 6d 61 6c 20 6e 6f 74 61 74 69 6f 6e 2c 20 65  imal notation, e
1ed0: 2e 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 30 31  .g. as in <b>'01
1ee0: 30 31 30 30 30 30 32 30 45 38 36 34 30 30 30 30  01000020E8640000
1ef0: 43 34 46 43 33 34 42 41 38 34 34 38 32 34 34 31  C4FC34BA84482441
1f00: 35 30 43 31 42 35 44 35 34 31 42 38 35 33 34 31  50C1B5D541B85341
1f10: 27 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75  '</b>.</li>..</u
1f20: 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68  l><br>..<hr>..<h
1f30: 33 3e 68 61 6e 64 6c 69 6e 67 20 50 6f 73 74 47  3>handling PostG
1f40: 49 53 20 67 65 6f 6d 65 74 72 69 65 73 3c 2f 68  IS geometries</h
1f50: 33 3e 0d 0a 50 6f 73 74 47 49 53 20 6f 77 6e 20  3>..PostGIS own 
1f60: 67 65 6f 6d 65 74 72 69 65 73 20 73 69 6d 70 6c  geometries simpl
1f70: 79 20 61 72 65 20 72 65 70 72 65 73 65 6e 74 65  y are represente
1f80: 64 20 62 79 20 61 20 3c 62 3e 42 59 54 45 41 3c  d by a <b>BYTEA<
1f90: 2f 62 3e 20 76 61 6c 75 65 20 74 6f 20 62 65 20  /b> value to be 
1fa0: 69 6e 74 65 72 70 72 65 74 65 64 20 61 63 63 6f  interpreted acco
1fb0: 72 64 69 6e 67 6c 79 20 74 6f 20 3c 62 3e 45 57  rdingly to <b>EW
1fc0: 4b 42 3c 2f 62 3e 20 66 6f 72 6d 61 74 20 73 70  KB</b> format sp
1fd0: 65 63 69 66 69 63 61 74 69 6f 6e 73 2e 0d 0a 3c  ecifications...<
1fe0: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54  verbatim>..CREAT
1ff0: 45 20 54 41 42 4c 45 20 66 72 6f 6d 5f 70 6f 73  E TABLE from_pos
2000: 74 67 69 73 20 41 53 0d 0a 53 45 4c 45 43 54 20  tgis AS..SELECT 
2010: 2a 20 46 52 4f 4d 20 70 67 5f 69 6e 3b 0d 0a 0d  * FROM pg_in;...
2020: 0a 55 50 44 41 54 45 20 66 72 6f 6d 5f 70 6f 73  .UPDATE from_pos
2030: 74 67 69 73 20 53 45 54 20 67 65 6f 6d 65 74 72  tgis SET geometr
2040: 79 20 3d 20 47 65 6f 6d 46 72 6f 6d 45 57 4b 42  y = GeomFromEWKB
2050: 28 67 65 6f 6d 65 74 72 79 29 3b 0d 0a 0d 0a 53  (geometry);....S
2060: 45 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 53  ELECT DISTINCT S
2070: 54 5f 47 65 6f 6d 65 74 72 79 54 79 70 65 28 67  T_GeometryType(g
2080: 65 6f 6d 65 74 72 79 29 2c 20 53 54 5f 53 72 69  eometry), ST_Sri
2090: 64 28 67 65 6f 6d 65 74 72 79 29 2c 20 43 6f 6f  d(geometry), Coo
20a0: 72 64 44 69 6d 65 6e 73 69 6f 6e 28 67 65 6f 6d  rdDimension(geom
20b0: 65 74 72 79 29 0d 0a 46 52 4f 4d 20 66 72 6f 6d  etry)..FROM from
20c0: 5f 70 6f 73 74 67 69 73 3b 0d 0a 2d 2d 2d 2d 2d  _postgis;..-----
20d0: 2d 2d 2d 2d 2d 2d 2d 0d 0a 4c 49 4e 45 53 54 52  -------..LINESTR
20e0: 49 4e 47 7c 32 35 38 33 32 7c 58 59 0d 0a 0d 0a  ING|25832|XY....
20f0: 53 45 4c 45 43 54 20 52 65 63 6f 76 65 72 47 65  SELECT RecoverGe
2100: 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 66 72  ometryColumn('fr
2110: 6f 6d 5f 70 6f 73 74 67 69 73 27 2c 20 27 67 65  om_postgis', 'ge
2120: 6f 6d 65 74 72 79 27 2c 20 32 35 38 33 32 2c 20  ometry', 25832, 
2130: 27 4c 49 4e 45 53 54 52 49 4e 47 27 2c 20 27 58  'LINESTRING', 'X
2140: 59 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  Y');..----------
2150: 2d 2d 0d 0a 31 0d 0a 3c 2f 76 65 72 62 61 74 69  --..1..</verbati
2160: 6d 3e 0d 0a 54 68 69 73 20 73 65 71 75 65 6e 63  m>..This sequenc
2170: 65 20 6f 66 20 53 51 4c 20 73 74 61 74 65 6d 65  e of SQL stateme
2180: 6e 74 73 20 28 53 70 61 74 69 61 4c 69 74 65 20  nts (SpatiaLite 
2190: 73 75 70 70 6f 72 74 20 69 73 20 73 74 72 69 63  support is stric
21a0: 74 6c 79 20 72 65 71 75 69 72 65 64 29 20 77 69  tly required) wi
21b0: 6c 6c 20 74 72 61 6e 73 66 65 72 20 61 20 66 75  ll transfer a fu
21c0: 6c 6c 79 20 71 75 61 6c 69 66 69 65 64 20 47 65  lly qualified Ge
21d0: 6f 6d 65 74 72 79 20 74 61 62 6c 65 20 66 72 6f  ometry table fro
21e0: 6d 20 50 6f 73 74 47 49 53 20 74 6f 20 53 70 61  m PostGIS to Spa
21f0: 74 69 61 4c 69 74 65 3a 0d 0a 3c 75 6c 3e 0d 0a  tiaLite:..<ul>..
2200: 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 31 3c 2f 62  <li><b>step 1</b
2210: 3e 3a 20 66 69 72 73 74 20 77 65 27 6c 6c 20 74  >: first we'll t
2220: 72 61 6e 73 66 65 72 20 74 68 65 20 77 68 6f 6c  ransfer the whol
2230: 65 20 50 6f 73 74 47 49 53 20 74 61 62 6c 65 20  e PostGIS table 
2240: 69 6e 74 6f 20 53 51 4c 69 74 65 3b 20 67 65 6f  into SQLite; geo
2250: 6d 65 74 72 69 65 73 20 61 72 65 20 73 74 69 6c  metries are stil
2260: 6c 20 72 65 70 72 65 73 65 6e 74 65 64 20 62 79  l represented by
2270: 20 74 68 65 69 72 20 3c 62 3e 45 57 4b 42 3c 2f   their <b>EWKB</
2280: 62 3e 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e  b> hexadecimal n
2290: 6f 74 61 74 69 6f 6e 73 2e 3c 2f 6c 69 3e 0d 0a  otations.</li>..
22a0: 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 32 3c 2f 62  <li><b>step 2</b
22b0: 3e 3a 20 74 68 65 6e 20 77 65 27 6c 6c 20 75 73  >: then we'll us
22c0: 65 20 74 68 65 20 3c 62 3e 47 65 6f 6d 46 72 6f  e the <b>GeomFro
22d0: 6d 45 57 4b 42 28 29 3c 2f 62 3e 20 53 51 4c 20  mEWKB()</b> SQL 
22e0: 66 75 6e 63 74 69 6f 6e 20 73 6f 20 74 6f 20 67  function so to g
22f0: 65 74 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e  et the correspon
2300: 64 69 6e 67 20 3c 62 3e 53 70 61 74 69 61 4c 69  ding <b>SpatiaLi
2310: 74 65 27 73 20 42 4c 4f 42 3c 2f 62 3e 20 66 6f  te's BLOB</b> fo
2320: 72 20 65 61 63 68 20 67 65 6f 6d 65 74 72 79 2e  r each geometry.
2330: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74  </li>..<li><b>st
2340: 65 70 20 33 3c 2f 62 3e 3a 20 6e 6f 77 20 77 65  ep 3</b>: now we
2350: 20 73 69 6d 70 6c 79 20 68 61 76 65 20 74 6f 20   simply have to 
2360: 64 69 73 63 6f 76 65 72 20 74 68 65 20 54 79 70  discover the Typ
2370: 65 2c 20 53 52 49 44 20 61 6e 64 20 44 69 6d 65  e, SRID and Dime
2380: 6e 73 69 6f 6e 73 20 64 65 63 6c 61 72 65 64 20  nsions declared 
2390: 62 79 20 74 68 65 73 65 20 67 65 6f 6d 65 74 72  by these geometr
23a0: 69 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c  ies.</li>..<li><
23b0: 62 3e 73 74 65 70 20 34 3c 2f 62 3e 3a 20 61 6e  b>step 4</b>: an
23c0: 64 20 66 69 6e 61 6c 6c 79 20 77 65 20 63 61 6e  d finally we can
23d0: 20 6e 6f 77 20 72 65 63 6f 76 65 72 20 61 20 66   now recover a f
23e0: 75 6c 6c 20 71 75 61 6c 69 66 69 65 64 20 53 70  ull qualified Sp
23f0: 61 74 69 61 4c 69 74 65 27 73 20 6f 77 6e 20 28  atiaLite's own (
2400: 3c 69 3e 6e 61 74 69 76 65 3c 2f 69 3e 29 20 47  <i>native</i>) G
2410: 65 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 2e 3c  eometry column.<
2420: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d  /li>..</ul><br>.
2430: 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 65 78 70 6f 72  .<hr>..<h3>expor
2440: 74 69 6e 67 20 64 61 74 61 20 66 72 6f 6d 20 53  ting data from S
2450: 51 4c 69 74 65 20 74 6f 20 50 6f 73 74 67 72 65  QLite to Postgre
2460: 73 2f 50 6f 73 74 47 49 53 3c 2f 68 33 3e 0d 0a  s/PostGIS</h3>..
2470: 46 6f 72 20 72 61 74 68 65 72 20 6f 62 76 69 6f  For rather obvio
2480: 75 73 20 73 65 63 75 72 69 74 79 20 72 65 61 73  us security reas
2490: 6f 6e 73 2c 20 61 6c 6c 20 56 69 72 74 75 61 6c  ons, all Virtual
24a0: 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 73 20  Postgres tables 
24b0: 61 72 65 20 64 65 63 6c 61 72 65 64 20 74 6f 20  are declared to 
24c0: 62 65 20 3c 69 3e 72 65 61 64 2d 6f 6e 6c 79 3c  be <i>read-only<
24d0: 2f 69 3e 20 62 79 20 64 65 66 61 75 6c 74 2e 3c  /i> by default.<
24e0: 62 72 3e 0d 0a 54 68 69 73 20 61 63 74 75 61 6c  br>..This actual
24f0: 6c 79 20 6d 65 61 6e 73 20 74 68 61 74 20 79 6f  ly means that yo
2500: 75 20 61 72 65 20 65 6e 61 62 6c 65 64 20 74 6f  u are enabled to
2510: 20 65 78 65 63 75 74 65 20 61 6e 79 20 70 6f 73   execute any pos
2520: 73 69 62 6c 65 20 3c 62 3e 53 45 4c 45 43 54 3c  sible <b>SELECT<
2530: 2f 62 3e 20 71 75 65 72 79 2c 20 62 75 74 20 61  /b> query, but a
2540: 6e 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e  ny <b>INSERT</b>
2550: 2c 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20  , <b>UPDATE</b> 
2560: 6f 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e  or <b>DELETE</b>
2570: 20 6f 70 65 72 61 74 69 6f 6e 20 61 66 66 65 63   operation affec
2580: 74 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65  ting the Postgre
2590: 73 20 44 42 4d 53 20 69 73 20 73 74 72 69 63 74  s DBMS is strict
25a0: 6c 79 20 66 6f 72 62 69 64 64 65 6e 2e 0d 0a 3c  ly forbidden...<
25b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54  verbatim>..CREAT
25c0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
25d0: 70 67 5f 6f 75 74 20 0d 0a 20 20 20 20 55 53 49  pg_out ..    USI
25e0: 4e 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72  NG VirtualPostgr
25f0: 65 73 20 28 27 68 6f 73 74 61 64 64 72 3d 31 39  es ('hostaddr=19
2600: 32 2e 31 36 38 2e 31 2e 39 31 20 70 6f 72 74 3d  2.168.1.91 port=
2610: 35 34 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20  5432 dbname=gis 
2620: 75 73 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73  user=sandro pass
2630: 77 6f 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79  word=secret', my
2640: 5f 73 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c  _schema, my_tabl
2650: 65 2c 20 57 29 3b 0d 0a 3c 2f 76 65 72 62 61 74  e, W);..</verbat
2660: 69 6d 3e 0d 0a 41 6e 79 77 61 79 20 79 6f 75 20  im>..Anyway you 
2670: 63 61 6e 20 65 78 70 6c 69 63 69 74 6c 79 20 72  can explicitly r
2680: 65 71 75 65 73 74 20 61 20 56 69 72 74 75 61 6c  equest a Virtual
2690: 50 6f 73 74 67 72 65 73 20 74 61 62 6c 65 20 74  Postgres table t
26a0: 6f 20 73 75 70 70 6f 72 74 20 75 6e 63 6f 6e 73  o support uncons
26b0: 74 72 61 69 6e 65 64 20 3c 69 3e 72 65 61 64 2d  trained <i>read-
26c0: 77 72 69 74 65 3c 2f 69 3e 20 6f 70 65 72 61 74  write</i> operat
26d0: 69 6f 6e 73 2c 20 74 68 69 73 20 69 6e 63 6c 75  ions, this inclu
26e0: 64 69 6e 67 20 61 6e 79 20 3c 62 3e 49 4e 53 45  ding any <b>INSE
26f0: 52 54 3c 2f 62 3e 2c 20 3c 62 3e 55 50 44 41 54  RT</b>, <b>UPDAT
2700: 45 3c 2f 62 3e 20 6f 72 20 3c 62 3e 44 45 4c 45  E</b> or <b>DELE
2710: 54 45 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e 74  TE</b> statement
2720: 20 61 66 66 65 63 74 69 6e 67 20 74 68 65 20 50   affecting the P
2730: 6f 73 74 67 72 65 73 20 44 42 4d 53 2e 3c 62 72  ostgres DBMS.<br
2740: 3e 0d 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20  >..In this case 
2750: 79 6f 75 20 73 69 6d 70 6c 79 20 68 61 76 65 20  you simply have 
2760: 74 6f 20 70 61 73 73 20 61 20 66 75 72 74 68 65  to pass a furthe
2770: 72 20 66 6f 75 72 74 68 20 61 72 67 75 6d 65 6e  r fourth argumen
2780: 74 20 69 6e 74 6f 20 74 68 65 20 3c 62 3e 55 53  t into the <b>US
2790: 49 4e 47 3c 2f 62 3e 20 63 6c 61 75 73 65 20 65  ING</b> clause e
27a0: 78 61 63 74 6c 79 20 63 6f 72 72 65 73 70 6f 6e  xactly correspon
27b0: 64 69 6e 67 20 74 6f 20 74 68 65 20 6c 65 74 74  ding to the lett
27c0: 65 72 20 3c 62 3e 57 3c 2f 62 3e 2e 0d 0a 3c 76  er <b>W</b>...<v
27d0: 65 72 62 61 74 69 6d 3e 0d 0a 44 45 4c 45 54 45  erbatim>..DELETE
27e0: 20 46 52 4f 4d 20 70 67 5f 6f 75 74 3b 0d 0a 0d   FROM pg_out;...
27f0: 0a 49 4e 53 45 52 54 20 49 4e 54 4f 20 70 67 5f  .INSERT INTO pg_
2800: 6f 75 74 20 28 66 6c 64 5f 61 2c 20 66 6c 64 5f  out (fld_a, fld_
2810: 62 2c 20 66 6c 64 5f 63 2c 20 67 65 6f 6d 65 74  b, fld_c, geomet
2820: 72 79 29 0d 0a 53 45 4c 45 43 54 20 66 6c 64 5f  ry)..SELECT fld_
2830: 61 2c 20 66 6c 64 5f 62 2c 20 66 6c 64 5f 63 2c  a, fld_b, fld_c,
2840: 20 41 73 45 57 4b 42 28 67 65 6f 6d 65 74 72 79   AsEWKB(geometry
2850: 29 0d 0a 66 72 6f 6d 20 73 6f 6d 65 5f 74 61 62  )..from some_tab
2860: 6c 65 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  le;..</verbatim>
2870: 0d 0a 49 6e 20 74 68 65 20 61 62 6f 76 65 20 65  ..In the above e
2880: 78 61 6d 70 6c 65 20 77 65 27 6c 6c 20 64 65 6c  xample we'll del
2890: 65 74 65 20 66 69 72 73 74 20 61 6e 79 20 61 6c  ete first any al
28a0: 72 65 61 64 79 20 65 78 69 73 74 69 6e 67 20 72  ready existing r
28b0: 6f 77 20 66 72 6f 6d 20 74 68 65 20 50 6f 73 74  ow from the Post
28c0: 47 49 53 20 74 61 62 6c 65 3b 20 74 68 65 6e 20  GIS table; then 
28d0: 77 65 27 6c 6c 20 73 69 6d 70 6c 79 20 74 72 61  we'll simply tra
28e0: 6e 73 66 65 72 20 74 68 65 20 77 68 6f 6c 65 20  nsfer the whole 
28f0: 74 61 62 6c 65 20 66 72 6f 6d 20 53 70 61 74 69  table from Spati
2900: 61 4c 69 74 65 20 69 6e 74 6f 20 50 6f 73 74 47  aLite into PostG
2910: 49 53 2e 3c 62 72 3e 0d 0a 50 6c 65 61 73 65 20  IS.<br>..Please 
2920: 6e 6f 74 65 2c 20 77 65 27 6c 6c 20 69 6e 76 6f  note, we'll invo
2930: 6b 65 20 74 68 65 20 3c 62 3e 41 73 45 57 4b 42  ke the <b>AsEWKB
2940: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74  ()</b> SQL funct
2950: 69 6f 6e 20 69 6e 20 6f 72 64 65 72 20 74 6f 20  ion in order to 
2960: 63 6f 6e 76 65 72 74 20 61 6e 79 20 53 70 61 74  convert any Spat
2970: 69 61 4c 69 74 65 27 73 20 6f 77 6e 20 3c 62 3e  iaLite's own <b>
2980: 42 4c 4f 42 3c 2f 62 3e 20 67 65 6f 6d 65 74 72  BLOB</b> geometr
2990: 79 20 69 6e 74 6f 20 74 68 65 20 65 71 75 69 76  y into the equiv
29a0: 61 6c 65 6e 74 20 3c 62 3e 42 59 54 45 41 20 45  alent <b>BYTEA E
29b0: 57 4b 42 3c 2f 62 3e 20 6e 6f 74 61 74 69 6f 6e  WKB</b> notation
29c0: 20 72 65 71 75 69 72 65 64 20 62 79 20 50 6f 73   required by Pos
29d0: 74 47 49 53 2e 0a 5a 20 35 34 63 62 38 38 36 39  tGIS..Z 54cb8869
29e0: 66 33 36 32 32 34 65 64 64 37 32 39 33 30 33 62  f36224edd729303b
29f0: 65 39 62 30 31 65 37 62 0a                       e9b01e7b.