Artifact 028b24c51958dd4b9558c3e818a14c5a0413fddd:
0000: 44 20 32 30 31 33 2d 30 38 2d 31 33 54 31 35 3a D 2013-08-13T15: 0010: 35 31 3a 34 37 2e 35 39 38 0a 4c 20 74 75 74 6f 51:47.598.L tuto 0020: 72 69 61 6c 0a 50 20 37 39 61 38 34 61 64 30 32 rial.P 79a84ad02 0030: 30 35 37 32 66 33 61 30 62 66 38 31 30 30 34 62 0572f3a0bf81004b 0040: 65 34 39 64 61 63 37 61 61 31 38 35 63 31 34 0a e49dac7aa185c14. 0050: 55 20 73 61 6e 64 72 6f 0a 57 20 31 31 34 34 30 U sandro.W 11440 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 33 3e ..<br><br>..<h3> 00d0: 61 62 6f 75 74 20 56 69 72 74 75 61 6c 50 47 3c about VirtualPG< 00e0: 2f 68 33 3e 0d 0a 3c 62 3e 56 69 72 74 75 61 6c /h3>..<b>Virtual 00f0: 50 47 3c 2f 62 3e 20 69 73 20 61 20 3c 69 3e 6c PG</b> is a <i>l 0100: 6f 61 64 61 62 6c 65 20 64 79 6e 61 6d 69 63 20 oadable dynamic 0110: 65 78 74 65 6e 73 69 6f 6e 20 6d 6f 64 75 6c 65 extension module 0120: 3c 2f 69 3e 20 66 6f 72 20 62 6f 74 68 20 3c 62 </i> for both <b 0130: 3e 53 51 4c 69 74 65 3c 2f 62 3e 20 61 6e 64 20 >SQLite</b> and 0140: 3c 62 3e 53 70 61 74 69 61 4c 69 74 65 3c 2f 62 <b>SpatiaLite</b 0150: 3e 3b 20 69 74 73 20 69 6e 74 65 6e 64 65 64 20 >; its intended 0160: 73 63 6f 70 65 20 69 73 20 73 75 70 70 6f 72 74 scope is support 0170: 69 6e 67 20 64 69 72 65 63 74 20 64 61 74 61 20 ing direct data 0180: 65 78 63 68 61 6e 67 65 20 66 6f 72 6d 2f 74 6f exchange form/to 0190: 20 3c 62 3e 50 6f 73 74 67 72 65 53 51 4c 3c 2f <b>PostgreSQL</ 01a0: 62 3e 20 61 6e 64 20 3c 62 3e 50 6f 73 74 47 49 b> and <b>PostGI 01b0: 53 3c 2f 62 3e 20 74 61 72 67 65 74 73 20 73 69 S</b> targets si 01c0: 6d 70 6c 79 20 75 73 69 6e 67 20 62 61 73 69 63 mply using basic 01d0: 2c 20 70 6c 61 69 6e 20 3c 69 3e 53 51 4c 20 73 , plain <i>SQL s 01e0: 74 61 74 65 6d 65 6e 74 73 3c 2f 69 3e 2e 3c 62 tatements</i>.<b 01f0: 72 3e 0d 0a 54 68 65 20 65 78 74 65 6e 73 69 6f r>..The extensio 0200: 6e 20 6d 6f 64 75 6c 65 20 73 69 6d 70 6c 79 20 n module simply 0210: 69 73 20 61 6e 20 6f 72 64 69 6e 61 72 79 20 3c is an ordinary < 0220: 69 3e 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 i>dynamic librar 0230: 79 3c 2f 69 3e 20 28 3c 62 3e 2e 64 6c 6c 3c 2f y</i> (<b>.dll</ 0240: 62 3e 20 6f 6e 20 57 69 6e 64 6f 77 73 2c 20 3c b> on Windows, < 0250: 62 3e 2e 73 6f 3c 2f 62 3e 20 6f 6e 20 55 6e 69 b>.so</b> on Uni 0260: 78 20 61 6e 64 20 4c 69 6e 75 78 2c 20 3c 62 3e x and Linux, <b> 0270: 2e 64 79 6c 69 62 3c 2f 62 3e 20 6f 6e 20 4d 61 .dylib</b> on Ma 0280: 63 20 4f 73 20 58 29 3b 20 73 6f 20 74 68 65 20 c Os X); so the 0290: 66 69 72 73 74 20 74 68 69 6e 67 20 74 6f 20 62 first thing to b 02a0: 65 20 64 6f 6e 65 20 69 6e 20 6f 72 64 65 72 20 e done in order 02b0: 74 6f 20 61 63 74 69 76 61 74 65 20 74 68 69 73 to activate this 02c0: 20 65 78 74 65 6e 73 69 6f 6e 20 69 73 20 6c 6f extension is lo 02d0: 61 64 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 ading the corres 02e0: 70 6f 6e 64 69 6e 67 20 6c 69 62 72 61 72 79 20 ponding library 02f0: 66 72 6f 6d 20 61 20 76 61 6c 69 64 20 53 51 4c from a valid SQL 0300: 69 74 65 2f 53 70 61 74 69 61 4c 69 74 65 20 63 ite/SpatiaLite c 0310: 6f 6e 6e 65 63 74 69 6f 6e 2e 0d 0a 3c 76 65 72 onnection...<ver 0320: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6c batim>..SELECT l 0330: 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 27 6c oad_extension('l 0340: 69 62 76 69 72 74 75 61 6c 70 67 2d 31 27 29 3b ibvirtualpg-1'); 0350: 0d 0a 2d 2d 2d 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a ..------..NULL.. 0360: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 74 61 </verbatim>..<ta 0370: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 ble bgcolor="#ff 0380: 66 66 65 38 22 20 77 69 64 74 68 3d 22 31 30 30 ffe8" width="100 0390: 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 %">..<tr><td ali 03a0: 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 55 gn="center"><b>U 03b0: 73 65 66 75 6c 20 68 69 6e 74 73 20 61 6e 64 20 seful hints and 03c0: 73 75 67 67 65 73 74 69 6f 6e 73 3a 20 74 72 6f suggestions: tro 03d0: 75 62 6c 65 73 68 6f 6f 74 69 6e 67 3c 2f 62 3e ubleshooting</b> 03e0: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e </td></tr>..<tr> 03f0: 3c 74 64 3e 3c 68 72 3e 3c 2f 74 64 3e 3c 2f 74 <td><hr></td></t 0400: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54 68 r>..<tr><td>..Th 0410: 69 73 20 6f 70 65 72 61 74 69 6f 6e 20 63 6f 75 is operation cou 0420: 6c 64 20 65 76 65 6e 74 75 61 6c 6c 79 20 66 61 ld eventually fa 0430: 69 6c 20 66 6f 72 20 73 65 76 65 72 61 6c 20 64 il for several d 0440: 69 66 66 65 72 65 6e 74 20 72 65 61 73 6f 6e 73 ifferent reasons 0450: 3a 20 68 65 72 65 20 61 72 65 20 74 68 65 20 6d : here are the m 0460: 6f 73 74 20 66 72 65 71 75 65 6e 74 73 3a 0d 0a ost frequents:.. 0470: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 59 6f 75 20 61 72 <ul>..<li>You ar 0480: 65 20 75 73 69 6e 67 20 73 6f 6d 65 20 6f 64 64 e using some odd 0490: 20 76 65 72 73 69 6f 6e 20 6f 66 20 53 51 4c 69 version of SQLi 04a0: 74 65 33 2f 6c 69 62 73 71 6c 69 74 65 33 20 66 te3/libsqlite3 f 04b0: 6f 72 62 69 64 64 69 6e 67 20 74 6f 20 6c 6f 61 orbidding to loa 04c0: 64 20 61 6e 79 20 64 79 6e 61 6d 69 63 20 65 78 d any dynamic ex 04d0: 74 65 6e 73 69 6f 6e 73 2e 3c 62 72 3e 0d 0a 54 tensions.<br>..T 04e0: 68 69 73 20 66 65 61 74 75 72 65 20 63 6f 75 6c his feature coul 04f0: 64 20 65 76 65 6e 74 75 61 6c 6c 79 20 62 65 20 d eventually be 0500: 64 69 73 61 62 6c 65 64 20 61 74 20 62 75 69 6c disabled at buil 0510: 64 20 74 69 6d 65 3b 20 69 66 20 74 68 69 73 20 d time; if this 0520: 69 73 20 79 6f 75 72 20 63 61 73 65 20 79 6f 75 is your case you 0530: 20 73 69 6d 70 6c 65 20 68 61 76 65 20 74 6f 20 simple have to 0540: 73 77 69 74 63 68 20 74 6f 20 73 6f 6d 65 20 64 switch to some d 0550: 69 66 66 65 72 65 6e 74 20 53 51 4c 69 74 65 20 ifferent SQLite 0560: 74 6f 6f 6c 6b 69 74 20 73 75 70 70 6f 72 74 69 toolkit supporti 0570: 6e 67 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e ng dynamic exten 0580: 73 69 6f 6e 20 6f 72 20 62 75 69 6c 64 20 6f 6e sion or build on 0590: 65 20 62 79 20 79 6f 75 72 73 65 6c 66 2e 3c 2f e by yourself.</ 05a0: 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 20 6f 70 65 li>..<li>The ope 05b0: 72 61 74 69 6e 67 20 73 79 73 74 65 6d 20 63 6f rating system co 05c0: 75 6c 64 20 62 65 20 75 6e 61 62 6c 65 20 74 6f uld be unable to 05d0: 20 63 6f 72 72 65 63 74 6c 79 20 6c 6f 63 61 74 correctly locat 05e0: 65 20 74 68 65 20 64 79 6e 61 6d 69 63 20 6c 69 e the dynamic li 05f0: 62 72 61 72 79 20 74 6f 20 62 65 20 6c 6f 61 64 brary to be load 0600: 65 64 2e 3c 62 72 3e 0d 0a 54 68 65 20 6d 6f 73 ed.<br>..The mos 0610: 74 20 72 65 63 65 6e 74 20 76 65 72 73 69 6f 6e t recent version 0620: 73 20 6f 66 20 53 51 4c 69 74 65 20 61 72 65 20 s of SQLite are 0630: 73 6d 61 72 74 20 65 6e 6f 75 67 68 20 74 6f 20 smart enough to 0640: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 68 61 automatically ha 0650: 6e 64 6c 65 20 61 6e 79 20 70 6c 61 74 66 6f 72 ndle any platfor 0660: 6d 20 73 70 65 63 69 66 69 63 20 73 75 66 66 69 m specific suffi 0670: 78 3a 20 73 6f 20 79 6f 75 20 61 72 65 20 6e 6f x: so you are no 0680: 20 6c 6f 6e 67 65 72 20 72 65 71 75 69 72 65 64 longer required 0690: 20 74 6f 20 73 70 65 63 69 66 79 20 61 6e 79 20 to specify any 06a0: 3c 62 3e 2e 64 6c 6c 3c 2f 62 3e 20 6f 72 20 3c <b>.dll</b> or < 06b0: 62 3e 2e 73 6f 3c 2f 62 3e 20 73 75 66 66 69 78 b>.so</b> suffix 06c0: 2e 20 49 66 20 79 6f 75 20 77 69 73 68 20 74 6f . If you wish to 06d0: 20 64 6f 20 73 6f 2c 20 79 6f 75 20 63 61 6e 20 do so, you can 06e0: 65 76 65 6e 74 75 61 6c 6c 79 20 73 70 65 63 69 eventually speci 06f0: 66 79 20 74 68 65 20 66 75 6c 6c 20 70 61 74 68 fy the full path 0700: 20 6c 65 61 64 69 6e 67 20 74 6f 20 74 68 65 20 leading to the 0710: 64 79 6e 61 6d 69 63 20 6c 69 62 72 61 72 79 2c dynamic library, 0720: 20 74 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 this including 0730: 61 6e 79 20 73 75 66 66 69 78 2e 3c 62 72 3e 0d any suffix.<br>. 0740: 0a 41 6e 79 77 61 79 20 74 68 65 20 64 65 66 61 .Anyway the defa 0750: 75 6c 74 20 62 65 68 61 76 69 6f 75 72 20 6f 66 ult behaviour of 0760: 20 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 6e 73 69 <b>load_extensi 0770: 6f 6e 28 29 3c 2f 62 3e 20 69 73 20 74 68 65 20 on()</b> is the 0780: 6f 6e 65 20 74 6f 20 73 65 61 72 63 68 20 74 68 one to search th 0790: 65 20 72 65 71 75 69 72 65 64 20 64 79 6e 61 6d e required dynam 07a0: 69 63 20 6c 69 62 72 61 72 79 20 66 6f 6c 6c 6f ic library follo 07b0: 77 69 6e 67 20 74 68 65 20 73 74 61 6e 64 61 72 wing the standar 07c0: 64 20 70 6c 61 74 66 6f 72 6d 20 73 70 65 63 69 d platform speci 07d0: 66 69 63 20 72 75 6c 65 73 2e 0d 0a 3c 2f 6c 69 fic rules...</li 07e0: 3e 0d 0a 3c 6c 69 3e 54 68 65 20 64 79 6e 61 6d >..<li>The dynam 07f0: 69 63 20 6c 69 62 72 61 72 79 20 69 74 73 65 6c ic library itsel 0800: 66 20 63 6f 75 6c 64 20 62 65 20 63 6f 72 72 65 f could be corre 0810: 63 74 6c 79 20 6c 6f 63 61 74 65 64 2c 20 62 75 ctly located, bu 0820: 74 20 73 6f 6d 65 20 66 75 72 74 68 65 72 20 64 t some further d 0830: 65 70 65 6e 64 69 6e 67 20 6c 69 62 72 61 72 79 epending library 0840: 20 63 6f 75 6c 64 20 6e 6f 74 2c 20 74 68 75 73 could not, thus 0850: 20 66 6f 72 62 69 64 64 69 6e 67 20 74 6f 20 6c forbidding to l 0860: 6f 61 64 20 74 68 65 20 6d 61 69 6e 20 6c 69 62 oad the main lib 0870: 72 61 72 79 2e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c rary.<br>..<u>Pl 0880: 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 3c ease note</u>: < 0890: 62 3e 56 69 72 74 75 61 6c 50 47 3c 2f 62 3e 20 b>VirtualPG</b> 08a0: 64 65 70 65 6e 64 73 20 6f 6e 20 74 68 65 20 50 depends on the P 08b0: 6f 73 74 67 72 65 53 51 4c 20 6f 77 6e 20 63 6c ostgreSQL own cl 08c0: 69 65 6e 74 20 6c 69 62 72 61 72 79 20 28 3c 62 ient library (<b 08d0: 3e 6c 69 62 70 71 3c 2f 62 3e 29 2e 3c 2f 6c 69 >libpq</b>).</li 08e0: 3e 0d 0a 3c 6c 69 3e 49 6e 20 61 6e 79 20 63 61 >..<li>In any ca 08f0: 73 65 2c 20 69 66 20 79 6f 75 20 61 72 65 20 75 se, if you are u 0900: 73 69 6e 67 20 73 6f 6d 65 20 69 6e 74 65 72 61 sing some intera 0910: 63 74 69 76 65 20 74 6f 6f 6c 20 73 75 63 68 20 ctive tool such 0920: 61 73 20 3c 62 3e 73 71 6c 69 74 65 33 3c 2f 62 as <b>sqlite3</b 0930: 3e 2c 20 3c 62 3e 73 70 61 74 69 61 6c 69 74 65 >, <b>spatialite 0940: 3c 2f 62 3e 20 6f 72 20 3c 62 3e 73 70 61 74 69 </b> or <b>spati 0950: 61 6c 69 74 65 5f 67 75 69 3c 2f 62 3e 20 73 6f alite_gui</b> so 0960: 6d 65 20 75 73 65 66 75 6c 20 61 6e 64 20 6d 65 me useful and me 0970: 61 6e 69 6e 67 66 75 6c 20 65 72 72 6f 72 20 6d aningful error m 0980: 65 73 73 61 67 65 20 77 69 6c 6c 20 73 75 72 65 essage will sure 0990: 6c 79 20 62 65 20 64 69 73 70 6c 61 79 65 64 20 ly be displayed 09a0: 65 78 70 6c 61 69 6e 69 6e 67 20 74 68 65 20 66 explaining the f 09b0: 61 69 6c 75 72 65 20 63 61 75 73 65 2e 3c 62 72 ailure cause.<br 09c0: 3e 0d 0a 54 68 69 73 20 63 6f 75 6c 64 20 6e 6f >..This could no 09d0: 74 20 62 65 20 73 75 70 70 6f 72 74 65 64 20 77 t be supported w 09e0: 68 69 6c 65 20 61 74 74 65 6d 70 74 69 6e 67 20 hile attempting 09f0: 74 6f 20 6c 6f 61 64 20 61 6e 20 65 78 74 65 6e to load an exten 0a00: 73 69 6f 6e 20 66 72 6f 6d 20 73 6f 6d 65 20 6c sion from some l 0a10: 61 6e 67 75 61 67 65 20 62 69 6e 64 69 6e 67 20 anguage binding 0a20: 28 65 2e 67 2e 20 3c 62 3e 2e 4e 45 54 3c 2f 62 (e.g. <b>.NET</b 0a30: 3e 2c 20 3c 62 3e 50 79 74 68 6f 6e 3c 2f 62 3e >, <b>Python</b> 0a40: 20 6f 72 20 3c 62 3e 4a 61 76 61 3c 2f 62 3e 29 or <b>Java</b>) 0a50: 2e 0d 0a 49 6e 20 74 68 69 73 20 63 61 73 65 20 ...In this case 0a60: 61 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 69 64 attempting to id 0a70: 65 6e 74 69 66 79 20 74 68 65 20 72 65 61 6c 20 entify the real 0a80: 65 72 72 6f 72 20 63 61 75 73 65 20 63 6f 75 6c error cause coul 0a90: 64 20 62 65 20 72 65 61 6c 6c 79 20 70 61 69 6e d be really pain 0aa0: 66 75 6c 20 64 75 65 20 74 6f 20 70 6f 6f 72 20 ful due to poor 0ab0: 61 6e 64 20 73 6c 6f 70 70 79 20 64 69 61 67 6e and sloppy diagn 0ac0: 6f 73 74 69 63 20 73 75 70 70 6f 72 74 2e 3c 2f ostic support.</ 0ad0: 6c 69 3e 0d 0a 3c 6c 69 3e 54 68 65 72 65 20 61 li>..<li>There a 0ae0: 72 65 20 6e 6f 20 75 6e 69 76 65 72 73 61 6c 20 re no universal 0af0: 72 75 6c 65 73 20 64 69 63 74 61 74 69 6e 67 20 rules dictating 0b00: 77 68 65 72 65 20 74 6f 20 70 6c 61 63 65 20 79 where to place y 0b10: 6f 75 72 20 65 78 74 65 6e 73 69 6f 6e 20 6d 6f our extension mo 0b20: 64 75 6c 65 73 3b 20 61 20 67 6f 6f 64 20 73 75 dules; a good su 0b30: 67 67 65 73 74 69 6f 6e 20 69 73 20 74 6f 20 61 ggestion is to a 0b40: 6c 77 61 79 73 20 70 6c 61 63 65 20 61 6c 6c 20 lways place all 0b50: 74 68 65 6d 20 69 6e 20 74 68 65 20 6d 6f 73 74 them in the most 0b60: 20 61 70 70 72 6f 70 72 69 61 74 65 20 73 79 73 appropriate sys 0b70: 74 65 6d 20 64 69 72 65 63 74 6f 72 79 2e 3c 2f tem directory.</ 0b80: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 3e 49 li>..</ul>..<b>I 0b90: 6d 70 6f 72 74 61 6e 74 20 6e 6f 74 69 63 65 3c mportant notice< 0ba0: 2f 62 3e 3a 20 74 68 65 20 76 65 72 79 20 72 65 /b>: the very re 0bb0: 63 65 6e 74 20 53 51 4c 69 74 65 20 3c 62 3e 33 cent SQLite <b>3 0bc0: 2e 37 2e 31 37 3c 2f 62 3e 20 69 6e 74 72 6f 64 .7.17</b> introd 0bd0: 75 63 65 64 20 6d 61 6e 79 20 69 6e 74 65 72 65 uced many intere 0be0: 73 74 69 6e 67 20 61 64 76 61 6e 63 65 64 20 66 sting advanced f 0bf0: 65 61 74 75 72 65 73 20 74 6f 20 3c 62 3e 6c 6f eatures to <b>lo 0c00: 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 29 3c 2f ad_extension()</ 0c10: 62 3e 3b 0d 0a 65 61 72 6c 69 65 72 20 76 65 72 b>;..earlier ver 0c20: 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65 20 sions of SQLite 0c30: 63 6f 75 6c 64 20 70 72 6f 62 61 62 6c 79 20 62 could probably b 0c40: 65 20 73 6f 6d 65 77 61 79 20 6c 69 6d 69 74 65 e someway limite 0c50: 64 2e 0d 0a 49 66 20 74 68 69 73 20 69 73 20 79 d...If this is y 0c60: 6f 75 72 20 63 61 73 65 2c 20 70 6c 65 61 73 65 our case, please 0c70: 20 63 6f 6e 73 69 64 65 72 20 74 68 61 74 3a 0d consider that:. 0c80: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 73 70 65 63 69 .<ul>..<li>speci 0c90: 66 79 69 6e 67 20 61 6e 79 20 3c 62 3e 2e 64 6c fying any <b>.dl 0ca0: 6c 3c 2f 62 3e 2c 20 3c 62 3e 2e 73 6f 3c 2f 62 l</b>, <b>.so</b 0cb0: 3e 20 6f 72 20 3c 62 3e 2e 64 79 6c 69 62 3c 2f > or <b>.dylib</ 0cc0: 62 3e 20 73 75 66 66 69 78 20 63 6f 75 6c 64 20 b> suffix could 0cd0: 62 65 20 73 74 72 69 63 74 6c 79 20 72 65 71 75 be strictly requ 0ce0: 69 72 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e ired.</li>..<li> 0cf0: 61 73 20 69 74 20 63 6f 75 6c 64 20 62 65 20 72 as it could be r 0d00: 65 71 75 69 72 65 64 20 74 6f 20 65 78 70 6c 69 equired to expli 0d10: 63 69 74 6c 79 20 73 70 65 63 69 66 79 20 74 68 citly specify th 0d20: 65 20 65 78 74 65 6e 73 69 6f 6e 20 65 6e 74 72 e extension entr 0d30: 79 20 70 6f 69 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c y point.</li>..< 0d40: 6c 69 3e 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 li>accordingly t 0d50: 6f 20 61 6c 6c 20 74 68 69 73 2c 20 79 6f 75 27 o all this, you' 0d60: 6c 6c 20 70 72 6f 62 61 62 6c 79 20 62 65 20 72 ll probably be r 0d70: 65 71 75 69 72 65 64 20 74 6f 20 70 61 73 73 20 equired to pass 0d80: 61 72 67 75 6d 65 6e 74 73 20 6c 69 6b 65 20 74 arguments like t 0d90: 6f 20 66 6f 6c 6c 6f 77 69 6e 67 20 6f 6e 65 73 o following ones 0da0: 20 74 6f 20 3c 62 3e 6c 6f 61 64 5f 65 78 74 65 to <b>load_exte 0db0: 6e 73 69 6f 6e 28 29 3c 2f 62 3e 20 77 68 69 6c nsion()</b> whil 0dc0: 65 20 75 73 69 6e 67 20 73 6f 6d 65 20 6f 62 73 e using some obs 0dd0: 6f 6c 65 74 65 20 53 51 4c 69 74 65 33 20 76 65 olete SQLite3 ve 0de0: 72 73 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 76 65 rsion.</li>..<ve 0df0: 72 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 rbatim>..SELECT 0e00: 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 28 27 load_extension(' 0e10: 2f 75 73 72 2f 6c 6f 63 61 6c 2f 6c 69 62 2f 6c /usr/local/lib/l 0e20: 69 62 76 69 72 74 75 61 6c 70 67 2e 73 6f 27 2c ibvirtualpg.so', 0e30: 20 27 73 71 6c 69 74 65 33 5f 76 69 72 74 75 61 'sqlite3_virtua 0e40: 6c 70 67 5f 69 6e 69 74 27 29 3b 0d 0a 2d 2d 2d lpg_init');..--- 0e50: 2d 2d 2d 0d 0a 4e 55 4c 4c 0d 0a 3c 2f 76 65 72 ---..NULL..</ver 0e60: 62 61 74 69 6d 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c batim>..</ul>..< 0e70: 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 /td></tr>..</tab 0e80: 6c 65 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c le><br>..<hr>..< 0e90: 68 33 3e 63 72 6f 73 73 2d 44 42 4d 53 20 64 61 h3>cross-DBMS da 0ea0: 74 61 20 65 78 63 68 61 6e 67 65 3a 20 53 51 4c ta exchange: SQL 0eb0: 20 61 6e 64 20 56 69 72 74 75 61 6c 50 6f 73 74 and VirtualPost 0ec0: 67 72 65 73 20 74 61 62 6c 65 73 3c 2f 68 33 3e gres tables</h3> 0ed0: 0d 0a 41 66 74 65 72 20 73 75 63 63 65 73 73 66 ..After successf 0ee0: 75 6c 6c 79 20 6c 6f 61 64 69 6e 67 20 74 68 65 ully loading the 0ef0: 20 3c 62 3e 76 69 72 74 75 61 6c 70 67 3c 2f 62 <b>virtualpg</b 0f00: 3e 20 64 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 > dynamic extens 0f10: 69 6f 6e 20 79 6f 75 20 61 72 65 20 6e 6f 77 20 ion you are now 0f20: 72 65 61 64 79 20 74 6f 20 63 72 65 61 74 65 20 ready to create 0f30: 3c 62 3e 56 69 72 74 75 61 6c 50 6f 73 74 67 65 <b>VirtualPostge 0f40: 73 3c 2f 62 3e 20 74 61 62 6c 65 73 2e 3c 62 72 s</b> tables.<br 0f50: 3e 0d 0a 54 68 65 73 65 20 61 72 65 20 3c 69 3e >..These are <i> 0f60: 71 75 69 74 65 20 61 6c 6d 6f 73 74 3c 2f 69 3e quite almost</i> 0f70: 20 6f 72 64 69 6e 61 72 79 20 44 42 20 74 61 62 ordinary DB tab 0f80: 6c 65 73 20 61 73 20 61 6e 79 20 6f 74 68 65 72 les as any other 0f90: 3b 20 79 6f 75 20 63 61 6e 20 65 78 65 63 75 74 ; you can execut 0fa0: 65 20 61 6e 79 20 72 65 67 75 6c 61 72 20 53 51 e any regular SQ 0fb0: 4c 20 73 74 61 74 65 6d 65 6e 74 20 28 3c 69 3e L statement (<i> 0fc0: 53 45 4c 45 43 54 3c 2f 69 3e 2c 20 3c 69 3e 49 SELECT</i>, <i>I 0fd0: 4e 53 45 52 54 3c 2f 69 3e 2c 20 3c 69 3e 55 50 NSERT</i>, <i>UP 0fe0: 44 41 54 45 3c 2f 69 3e 20 6f 72 20 3c 69 3e 44 DATE</i> or <i>D 0ff0: 45 4c 45 54 45 3c 2f 69 3e 29 20 62 79 20 73 70 ELETE</i>) by sp 1000: 65 63 69 66 79 69 6e 67 20 74 68 65 73 65 20 56 ecifying these V 1010: 69 72 74 75 61 6c 20 54 61 62 6c 65 73 20 61 73 irtual Tables as 1020: 20 74 68 65 20 73 65 6c 65 63 74 65 64 20 74 61 the selected ta 1030: 72 67 65 74 2e 3c 62 72 3e 0d 0a 54 68 65 72 65 rget.<br>..There 1040: 20 69 73 20 6f 6e 6c 79 20 61 20 73 74 72 6f 6e is only a stron 1050: 67 20 64 69 66 66 65 72 65 6e 63 65 20 64 69 73 g difference dis 1060: 74 69 6e 67 75 69 73 68 69 6e 67 20 61 20 3c 62 tinguishing a <b 1070: 3e 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 >VirtualPostgres 1080: 3c 2f 62 3e 20 74 61 62 6c 65 3b 20 69 74 27 73 </b> table; it's 1090: 20 70 68 79 73 69 63 61 6c 20 6c 6f 63 61 74 69 physical locati 10a0: 6f 6e 20 69 73 6e 27 74 20 77 69 74 68 69 6e 20 on isn't within 10b0: 74 68 65 20 63 75 72 72 65 6e 74 6c 79 20 63 6f the currently co 10c0: 6e 6e 65 63 74 65 64 20 53 51 4c 69 74 65 20 44 nnected SQLite D 10d0: 42 2c 20 62 75 74 20 69 73 20 69 6e 73 74 65 61 B, but is instea 10e0: 64 20 77 69 74 68 69 6e 20 73 6f 6d 65 20 3c 62 d within some <b 10f0: 3e 50 6f 73 74 67 72 65 53 51 4c 3c 2f 62 3e 20 >PostgreSQL</b> 1100: 44 42 4d 53 2e 3c 62 72 3e 0d 0a 53 6f 20 61 20 DBMS.<br>..So a 1110: 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 VirtualPostgres 1120: 74 61 62 6c 65 20 65 66 66 65 63 74 69 76 65 6c table effectivel 1130: 79 20 61 63 74 73 20 61 73 20 61 20 3c 69 3e 62 y acts as a <i>b 1140: 72 69 64 67 65 3c 2f 69 3e 20 6a 6f 69 6e 69 6e ridge</i> joinin 1150: 67 20 53 51 4c 69 74 65 20 61 6e 64 20 50 6f 73 g SQLite and Pos 1160: 74 67 72 65 73 2c 20 61 6e 64 20 61 6c 6c 6f 77 tgres, and allow 1170: 69 6e 67 20 74 6f 20 70 65 72 66 6f 72 6d 20 61 ing to perform a 1180: 6e 79 20 6b 69 6e 64 20 6f 66 20 63 72 6f 73 73 ny kind of cross 1190: 20 64 61 74 61 20 65 78 63 68 61 6e 67 65 20 28 data exchange ( 11a0: 3c 69 3e 69 6e 20 62 6f 74 68 20 64 69 72 65 63 <i>in both direc 11b0: 74 69 6f 6e 73 3c 2f 69 3e 29 20 69 6e 20 74 68 tions</i>) in th 11c0: 65 20 65 61 73 69 65 73 74 20 77 61 79 2e 0d 0a e easiest way... 11d0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 <verbatim>..CREA 11e0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 TE VIRTUAL TABLE 11f0: 20 70 67 5f 69 6e 20 0d 0a 20 20 20 20 55 53 49 pg_in .. USI 1200: 4e 47 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 NG VirtualPostgr 1210: 65 73 20 28 27 68 6f 73 74 3d 6c 6f 63 61 6c 68 es ('host=localh 1220: 6f 73 74 20 70 6f 72 74 3d 35 34 33 32 20 64 62 ost port=5432 db 1230: 6e 61 6d 65 3d 67 69 73 20 75 73 65 72 3d 73 61 name=gis user=sa 1240: 6e 64 72 6f 20 70 61 73 73 77 6f 72 64 3d 73 65 ndro password=se 1250: 63 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 6d 61 cret', my_schema 1260: 2c 20 6d 79 5f 74 61 62 6c 65 29 3b 0d 0a 3c 2f , my_table);..</ 1270: 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 69 73 20 verbatim>..This 1280: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 20 77 69 SQL statement wi 1290: 6c 6c 20 63 72 65 61 74 65 20 69 6e 74 6f 20 74 ll create into t 12a0: 68 65 20 53 51 4c 69 74 65 20 44 42 20 61 20 74 he SQLite DB a t 12b0: 61 62 6c 65 20 6e 61 6d 65 64 20 3c 62 3e 70 67 able named <b>pg 12c0: 5f 69 6e 3c 2f 62 3e 3b 20 61 6e 79 77 61 79 20 _in</b>; anyway 12d0: 74 68 65 20 64 61 74 61 20 70 68 79 73 69 63 61 the data physica 12e0: 6c 20 73 74 6f 72 61 67 65 20 66 6f 72 20 74 68 l storage for th 12f0: 69 73 20 74 61 62 6c 65 20 77 69 6c 6c 20 62 65 is table will be 1300: 20 69 6e 74 6f 20 74 68 65 20 50 6f 73 74 67 72 into the Postgr 1310: 65 73 20 44 42 4d 53 3a 0d 0a 3c 75 6c 3e 0d 0a es DBMS:..<ul>.. 1320: 3c 6c 69 3e 74 68 65 20 66 69 72 73 74 20 61 72 <li>the first ar 1330: 67 75 6d 65 6e 74 20 74 6f 20 56 69 72 74 75 61 gument to Virtua 1340: 6c 50 6f 73 74 67 72 65 73 20 69 73 20 74 68 65 lPostgres is the 1350: 20 3c 69 3e 63 6f 6e 6e 65 63 74 69 6f 6e 20 73 <i>connection s 1360: 74 72 69 6e 67 3c 2f 69 3e 20 72 65 71 75 69 72 tring</i> requir 1370: 65 64 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 ed in order to e 1380: 73 74 61 62 6c 69 73 68 20 61 20 63 6f 6e 6e 65 stablish a conne 1390: 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 50 6f 73 ction to the Pos 13a0: 74 67 72 65 73 20 44 42 4d 53 20 73 65 72 76 65 tgres DBMS serve 13b0: 72 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 73 65 63 r.</li>..<li>sec 13c0: 6f 6e 64 20 61 6e 64 20 74 68 69 72 64 20 61 72 ond and third ar 13d0: 67 75 6d 65 6e 74 73 20 72 65 73 70 65 63 74 69 guments respecti 13e0: 76 65 6c 79 20 61 72 65 20 74 68 65 20 3c 69 3e vely are the <i> 13f0: 73 63 68 65 6d 61 20 6e 61 6d 65 3c 2f 69 3e 20 schema name</i> 1400: 61 6e 64 20 74 68 65 20 3c 69 3e 74 61 62 6c 65 and the <i>table 1410: 20 6e 61 6d 65 3c 2f 69 3e 20 69 64 65 6e 74 69 name</i> identi 1420: 66 79 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 fying the Postgr 1430: 65 73 20 74 61 72 67 65 74 20 74 61 62 6c 65 2e es target table. 1440: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 </li>..</ul>..<v 1450: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 erbatim>..CREATE 1460: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 70 VIRTUAL TABLE p 1470: 67 5f 69 6e 20 0d 0a 20 20 20 20 55 53 49 4e 47 g_in .. USING 1480: 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 65 73 VirtualPostgres 1490: 20 28 27 68 6f 73 74 61 64 64 72 3d 31 39 32 2e ('hostaddr=192. 14a0: 31 36 38 2e 31 2e 39 31 20 70 6f 72 74 3d 35 34 168.1.91 port=54 14b0: 33 32 20 64 62 6e 61 6d 65 3d 67 69 73 20 75 73 32 dbname=gis us 14c0: 65 72 3d 73 61 6e 64 72 6f 20 70 61 73 73 77 6f er=sandro passwo 14d0: 72 64 3d 73 65 63 72 65 74 27 2c 20 6d 79 5f 73 rd=secret', my_s 14e0: 63 68 65 6d 61 2c 20 6d 79 5f 74 61 62 6c 65 29 chema, my_table) 14f0: 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a ;..</verbatim>.. 1500: 53 61 6d 65 20 61 73 20 61 62 6f 76 65 2c 20 74 Same as above, t 1510: 68 65 20 74 69 6d 65 20 65 73 74 61 62 6c 69 73 he time establis 1520: 68 69 6e 67 20 61 20 63 6f 6e 6e 65 63 74 69 6f hing a connectio 1530: 6e 20 74 6f 20 61 20 50 6f 73 74 67 72 65 73 20 n to a Postgres 1540: 69 6e 73 74 61 6e 63 65 20 72 75 6e 6e 69 6e 67 instance running 1550: 20 6f 6e 20 73 6f 6d 65 20 64 69 66 66 65 72 65 on some differe 1560: 6e 74 20 63 6f 6d 70 75 74 65 72 20 6f 6e 20 74 nt computer on t 1570: 68 65 20 73 61 6d 65 20 6c 6f 63 61 6c 20 61 72 he same local ar 1580: 65 61 20 6e 65 74 77 6f 72 6b 2e 3c 62 72 3e 0d ea network.<br>. 1590: 0a 50 6c 65 61 73 65 20 63 6f 6e 73 75 6c 74 20 .Please consult 15a0: 74 68 65 20 50 6f 73 74 67 72 65 73 20 6f 77 6e the Postgres own 15b0: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 66 documentation f 15c0: 6f 72 20 61 6e 79 20 6f 74 68 65 72 20 64 65 74 or any other det 15d0: 61 69 6c 20 61 62 6f 75 74 20 3c 69 3e 63 6f 6e ail about <i>con 15e0: 6e 65 63 74 69 6f 6e 20 73 74 72 69 6e 67 73 3c nection strings< 15f0: 2f 69 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e /i>...<verbatim> 1600: 0d 0a 50 52 41 47 4d 41 20 74 61 62 6c 65 5f 69 ..PRAGMA table_i 1610: 6e 66 6f 28 70 67 5f 69 6e 29 3b 0d 0a 3c 2f 76 nfo(pg_in);..</v 1620: 65 72 62 61 74 69 6d 3e 0d 0a 59 6f 75 20 63 61 erbatim>..You ca 1630: 6e 20 65 78 65 63 75 74 65 20 74 68 65 20 61 62 n execute the ab 1640: 6f 76 65 20 50 52 41 47 4d 41 20 64 69 72 65 63 ove PRAGMA direc 1650: 74 69 76 65 20 69 6e 20 6f 72 64 65 72 20 74 6f tive in order to 1660: 20 69 64 65 6e 74 69 66 79 20 61 6c 6c 20 63 6f identify all co 1670: 6c 75 6d 6e 73 20 64 65 63 6c 61 72 65 64 20 62 lumns declared b 1680: 79 20 74 68 65 20 50 6f 73 74 67 72 65 73 20 74 y the Postgres t 1690: 61 62 6c 65 2c 20 61 6e 64 20 74 68 65 69 72 20 able, and their 16a0: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 64 61 corresponding da 16b0: 74 61 2d 74 79 70 65 2e 3c 62 72 3e 0d 0a 49 66 ta-type.<br>..If 16c0: 20 79 6f 75 20 61 72 65 20 61 63 74 75 61 6c 6c you are actuall 16d0: 79 20 75 73 69 6e 67 20 3c 62 3e 73 70 61 74 69 y using <b>spati 16e0: 61 6c 69 74 65 5f 67 75 69 3c 2f 62 3e 20 79 6f alite_gui</b> yo 16f0: 75 20 63 61 6e 20 63 68 65 63 6b 20 74 68 65 20 u can check the 1700: 73 61 6d 65 20 69 6e 66 6f 73 20 62 79 20 75 73 same infos by us 1710: 69 6e 67 20 74 68 65 20 61 70 70 72 6f 70 72 69 ing the appropri 1720: 61 74 65 20 67 72 61 70 68 69 63 73 20 74 6f 6f ate graphics too 1730: 6c 73 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d ls...<verbatim>. 1740: 0a 53 45 4c 45 43 54 20 61 2c 20 62 2c 20 63 2c .SELECT a, b, c, 1750: 20 43 6f 75 6e 74 28 2a 29 20 41 53 20 63 6e 74 Count(*) AS cnt 1760: 0d 0a 46 52 4f 4d 20 70 67 5f 69 6e 0d 0a 57 48 ..FROM pg_in..WH 1770: 45 52 45 20 65 20 49 53 20 4e 4f 54 20 4e 55 4c ERE e IS NOT NUL 1780: 4c 0d 0a 47 52 4f 55 50 20 42 59 20 61 2c 20 62 L..GROUP BY a, b 1790: 2c 20 63 0d 0a 4f 52 44 45 52 20 42 59 20 63 6e , c..ORDER BY cn 17a0: 74 20 44 45 53 43 3b 0d 0a 3c 2f 76 65 72 62 61 t DESC;..</verba 17b0: 74 69 6d 3e 0d 0a 59 6f 75 20 63 61 6e 20 65 78 tim>..You can ex 17c0: 65 63 75 74 65 20 61 6e 79 20 6b 69 6e 64 20 6f ecute any kind o 17d0: 66 20 3c 62 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 f <b>SELECT</b> 17e0: 71 75 65 72 79 20 75 73 69 6e 67 20 61 20 56 69 query using a Vi 17f0: 72 74 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 rtualPostgres ta 1800: 62 6c 65 2c 20 65 78 61 63 74 6c 79 20 61 73 20 ble, exactly as 1810: 69 66 20 69 74 20 77 61 73 20 61 20 67 65 6e 75 if it was a genu 1820: 69 6e 65 20 6e 61 74 69 76 65 20 74 61 62 6c 65 ine native table 1830: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 ...<verbatim>..C 1840: 52 45 41 54 45 20 54 41 42 4c 45 20 69 6d 70 6f REATE TABLE impo 1850: 72 74 65 64 5f 66 72 6f 6d 5f 70 67 20 41 53 0d rted_from_pg AS. 1860: 0a 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 70 .SELECT * FROM p 1870: 67 5f 69 6e 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 g_in;..</verbati 1880: 6d 3e 0d 0a 41 6e 64 20 79 6f 75 20 63 61 6e 20 m>..And you can 1890: 6f 62 76 69 6f 75 73 6c 79 20 63 72 65 61 74 65 obviously create 18a0: 20 61 6e 64 20 70 6f 70 75 6c 61 74 65 20 61 20 and populate a 18b0: 6c 6f 63 61 6c 20 63 6f 70 79 20 6f 66 20 74 68 local copy of th 18c0: 65 20 72 65 6d 6f 74 65 20 50 6f 73 74 67 72 65 e remote Postgre 18d0: 73 20 74 61 62 6c 65 3a 20 6e 6f 77 20 61 6c 6c s table: now all 18e0: 20 64 61 74 61 20 61 72 65 20 70 65 72 6d 61 6e data are perman 18f0: 65 6e 74 6c 79 20 73 74 6f 72 65 64 20 77 69 74 ently stored wit 1900: 68 69 6e 20 79 6f 75 72 20 53 51 4c 69 74 65 20 hin your SQLite 1910: 44 42 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d DB...<verbatim>. 1920: 0a 44 52 4f 50 20 54 41 42 4c 45 20 70 67 5f 69 .DROP TABLE pg_i 1930: 6e 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d n;..</verbatim>. 1940: 0a 53 6f 20 79 6f 75 20 63 61 6e 20 66 69 6e 61 .So you can fina 1950: 6c 6c 79 20 64 72 6f 70 20 74 68 65 20 56 69 72 lly drop the Vir 1960: 74 75 61 6c 50 6f 73 74 67 72 65 73 20 74 61 62 tualPostgres tab 1970: 6c 65 2c 20 61 6e 64 20 74 68 69 73 20 77 69 6c le, and this wil 1980: 6c 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 74 65 l immediately te 1990: 72 6d 69 6e 61 74 65 20 74 68 65 20 63 6f 6e 6e rminate the conn 19a0: 65 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 50 6f ection to the Po 19b0: 73 74 67 72 65 73 20 44 42 4d 53 2e 3c 62 72 3e stgres DBMS.<br> 19c0: 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e <br>..<hr>..<h3> 19d0: 64 61 74 61 2d 74 79 70 65 20 6d 61 70 70 69 6e data-type mappin 19e0: 67 20 61 6e 64 20 72 65 6c 61 74 65 64 20 63 6f g and related co 19f0: 6e 76 65 72 73 69 6f 6e 73 3c 2f 68 33 3e 0d 0a nversions</h3>.. 1a00: 52 61 74 68 65 72 20 6f 62 76 69 6f 75 73 6c 79 Rather obviously 1a10: 20 53 51 4c 69 74 65 20 61 6e 64 20 50 6f 73 74 SQLite and Post 1a20: 67 72 65 73 20 73 75 70 70 6f 72 74 73 20 76 65 gres supports ve 1a30: 72 79 20 64 69 66 66 65 72 65 6e 74 20 6b 69 6e ry different kin 1a40: 64 20 6f 66 20 64 61 74 61 2d 74 79 70 65 73 2e d of data-types. 1a50: 20 54 68 65 20 66 65 77 20 66 6f 6c 6c 6f 77 69 The few followi 1a60: 6e 67 20 72 75 6c 65 73 20 61 70 70 6c 79 3a 0d ng rules apply:. 1a70: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 6b .<ul>..<li>any k 1a80: 69 6e 64 20 6f 66 20 3c 62 3e 49 4e 54 45 47 45 ind of <b>INTEGE 1a90: 52 3c 2f 62 3e 20 76 61 6c 75 65 20 69 73 20 70 R</b> value is p 1aa0: 72 65 73 65 72 76 65 64 20 61 73 20 73 75 63 68 reserved as such 1ab0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 .</li>..<li>the 1ac0: 73 61 6d 65 20 69 73 20 66 6f 72 20 3c 62 3e 46 same is for <b>F 1ad0: 4c 4f 41 54 3c 2f 62 3e 20 76 61 6c 75 65 73 2e LOAT</b> values. 1ae0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4d 4f </li>..<li><b>MO 1af0: 4e 45 59 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 4e NEY</b> and <b>N 1b00: 55 4d 45 52 49 43 3c 2f 62 3e 20 76 61 6c 75 65 UMERIC</b> value 1b10: 73 20 61 72 65 20 63 6f 6e 76 65 72 74 65 64 20 s are converted 1b20: 69 6e 74 6f 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 into <b>FLOAT</b 1b30: 3e 20 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a > values.</li>.. 1b40: 3c 6c 69 3e 3c 62 3e 43 48 41 52 3c 2f 62 3e 20 <li><b>CHAR</b> 1b50: 61 6e 64 20 3c 62 3e 56 41 52 43 48 41 52 3c 2f and <b>VARCHAR</ 1b60: 62 3e 20 76 61 6c 75 65 73 20 61 72 65 20 61 6c b> values are al 1b70: 77 61 79 73 20 63 6f 6e 76 65 72 74 65 64 20 69 ways converted i 1b80: 6e 74 6f 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 nto <b>TEXT</b> 1b90: 76 61 6c 75 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c values.</li>..<l 1ba0: 69 3e 3c 62 3e 44 41 54 45 3c 2f 62 3e 2c 20 3c i><b>DATE</b>, < 1bb0: 62 3e 54 49 4d 45 3c 2f 62 3e 20 61 6e 64 20 3c b>TIME</b> and < 1bc0: 62 3e 54 49 4d 45 53 54 41 4d 50 3c 2f 62 3e 20 b>TIMESTAMP</b> 1bd0: 76 61 6c 75 65 73 20 61 72 65 20 61 6c 77 61 79 values are alway 1be0: 73 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 6f s converted into 1bf0: 20 3c 62 3e 46 4c 4f 41 54 3c 2f 62 3e 20 76 61 <b>FLOAT</b> va 1c00: 6c 75 65 73 20 63 6f 72 72 65 73 70 6f 6e 64 69 lues correspondi 1c10: 6e 67 20 74 6f 20 74 68 65 20 3c 61 20 68 72 65 ng to the <a hre 1c20: 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 73 71 f="http://www.sq 1c30: 6c 69 74 65 2e 6f 72 67 2f 6c 61 6e 67 5f 64 61 lite.org/lang_da 1c40: 74 65 66 75 6e 63 2e 68 74 6d 6c 22 3e 4a 75 6c tefunc.html">Jul 1c50: 69 61 6e 44 61 79 3c 2f 61 3e 20 6e 6f 74 61 74 ianDay</a> notat 1c60: 69 6f 6e 20 73 75 70 70 6f 72 74 65 64 20 62 79 ion supported by 1c70: 20 53 51 4c 69 74 65 2e 3c 62 72 3e 0d 0a 59 6f SQLite.<br>..Yo 1c80: 75 20 63 61 6e 20 74 68 65 6e 20 69 6e 76 6f 6b u can then invok 1c90: 65 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 e the appropriat 1ca0: 65 20 66 75 6e 63 74 69 6f 6e 20 62 65 74 77 65 e function betwe 1cb0: 65 6e 20 3c 62 3e 44 61 74 65 28 29 3c 2f 62 3e en <b>Date()</b> 1cc0: 2c 20 3c 62 3e 54 69 6d 65 28 29 3c 2f 62 3e 20 , <b>Time()</b> 1cd0: 6f 72 20 3c 62 3e 44 61 74 65 54 69 6d 65 28 29 or <b>DateTime() 1ce0: 3c 2f 62 3e 20 73 6f 20 74 6f 20 67 65 74 20 62 </b> so to get b 1cf0: 61 63 6b 20 74 68 65 20 73 74 61 6e 64 61 72 64 ack the standard 1d00: 20 53 51 4c 20 6e 6f 74 61 74 69 6f 6e 20 66 6f SQL notation fo 1d10: 72 20 64 61 74 65 73 20 61 6e 64 20 74 69 6d 65 r dates and time 1d20: 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e s.</li>..<li><b> 1d30: 42 4f 4f 4c 3c 2f 62 3e 20 76 61 6c 75 65 73 20 BOOL</b> values 1d40: 61 72 65 20 61 6c 77 61 79 73 20 63 6f 6e 76 65 are always conve 1d50: 72 74 65 64 20 69 6e 74 6f 20 3c 62 3e 49 4e 54 rted into <b>INT 1d60: 45 47 45 52 3c 2f 62 3e 20 76 61 6c 75 65 73 3a EGER</b> values: 1d70: 20 3c 62 3e 30 3c 2f 62 3e 20 63 6f 72 72 65 73 <b>0</b> corres 1d80: 70 6f 6e 64 69 6e 67 20 74 6f 20 3c 62 3e 46 41 ponding to <b>FA 1d90: 4c 53 45 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c LSE</b>.</li>..< 1da0: 6c 69 3e 50 6f 73 74 67 72 65 73 20 73 75 70 70 li>Postgres supp 1db0: 6f 72 74 73 20 6d 75 6c 74 69 70 6c 65 20 76 61 orts multiple va 1dc0: 6c 75 65 73 20 74 6f 20 62 65 20 73 74 6f 72 65 lues to be store 1dd0: 64 20 69 6e 74 6f 20 74 68 65 20 73 61 6d 65 20 d into the same 1de0: 63 6f 6c 75 6d 6e 20 28 3c 62 3e 41 52 52 41 59 column (<b>ARRAY 1df0: 3c 2f 62 3e 29 3a 20 53 51 4c 69 74 65 20 68 61 </b>): SQLite ha 1e00: 73 20 6e 6f 20 73 69 6d 69 6c 61 72 20 63 61 70 s no similar cap 1e10: 61 62 69 6c 69 74 79 2c 20 73 6f 20 61 6e 79 20 ability, so any 1e20: 41 52 52 41 59 20 76 61 6c 75 65 20 77 69 6c 6c ARRAY value will 1e30: 20 73 69 6d 70 6c 79 20 62 65 20 63 6f 6e 76 65 simply be conve 1e40: 72 74 65 64 20 69 6e 74 6f 20 61 20 3c 62 3e 54 rted into a <b>T 1e50: 45 58 54 3c 2f 62 3e 20 73 74 72 69 6e 67 2c 20 EXT</b> string, 1e60: 65 2e 67 2e 20 61 73 20 69 6e 20 3c 62 3e 27 7b e.g. as in <b>'{ 1e70: 31 2c 32 2c 33 7d 27 3c 2f 62 3e 20 6f 72 20 3c 1,2,3}'</b> or < 1e80: 62 3e 27 7b 61 6c 70 68 61 2c 62 65 74 61 2c 67 b>'{alpha,beta,g 1e90: 61 6d 6d 61 2c 64 65 6c 74 61 7d 27 3c 2f 62 3e amma,delta}'</b> 1ea0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 79 20 .</li>..<li>any 1eb0: 62 69 6e 61 72 79 20 76 61 6c 75 65 20 28 61 73 binary value (as 1ec0: 20 65 2e 67 2e 20 3c 62 3e 42 59 54 45 41 3c 2f e.g. <b>BYTEA</ 1ed0: 62 3e 29 20 77 69 6c 6c 20 62 65 20 73 69 6d 70 b>) will be simp 1ee0: 6c 79 20 63 6f 6e 76 65 72 74 65 64 20 69 6e 74 ly converted int 1ef0: 6f 20 61 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 o a <b>TEXT</b> 1f00: 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 69 6e 67 value containing 1f10: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi 1f20: 6e 67 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e ng hexadecimal n 1f30: 6f 74 61 74 69 6f 6e 2c 20 65 2e 67 2e 20 61 73 otation, e.g. as 1f40: 20 69 6e 20 3c 62 3e 27 30 31 30 31 30 30 30 30 in <b>'01010000 1f50: 32 30 45 38 36 34 30 30 30 30 43 34 46 43 33 34 20E8640000C4FC34 1f60: 42 41 38 34 34 38 32 34 34 31 35 30 43 31 42 35 BA8448244150C1B5 1f70: 44 35 34 31 42 38 35 33 34 31 27 3c 2f 62 3e 2e D541B85341'</b>. 1f80: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e </li>..</ul><br> 1f90: 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 68 61 6e 64 ..<hr>..<h3>hand 1fa0: 6c 69 6e 67 20 50 6f 73 74 47 49 53 20 67 65 6f ling PostGIS geo 1fb0: 6d 65 74 72 69 65 73 3c 2f 68 33 3e 0d 0a 50 6f metries</h3>..Po 1fc0: 73 74 47 49 53 20 6f 77 6e 20 67 65 6f 6d 65 74 stGIS own geomet 1fd0: 72 69 65 73 20 73 69 6d 70 6c 79 20 61 72 65 20 ries simply are 1fe0: 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 represented by a 1ff0: 20 3c 62 3e 42 59 54 45 41 3c 2f 62 3e 20 76 61 <b>BYTEA</b> va 2000: 6c 75 65 20 74 6f 20 62 65 20 69 6e 74 65 72 70 lue to be interp 2010: 72 65 74 65 64 20 61 63 63 6f 72 64 69 6e 67 6c reted accordingl 2020: 79 20 74 6f 20 3c 62 3e 45 57 4b 42 3c 2f 62 3e y to <b>EWKB</b> 2030: 20 66 6f 72 6d 61 74 20 73 70 65 63 69 66 69 63 format specific 2040: 61 74 69 6f 6e 73 2e 0d 0a 3c 76 65 72 62 61 74 ations...<verbat 2050: 69 6d 3e 0d 0a 43 52 45 41 54 45 20 54 41 42 4c im>..CREATE TABL 2060: 45 20 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 41 E from_postgis A 2070: 53 0d 0a 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d S..SELECT * FROM 2080: 20 70 67 5f 69 6e 3b 0d 0a 0d 0a 55 50 44 41 54 pg_in;....UPDAT 2090: 45 20 66 72 6f 6d 5f 70 6f 73 74 67 69 73 20 53 E from_postgis S 20a0: 45 54 20 67 65 6f 6d 65 74 72 79 20 3d 20 47 65 ET geometry = Ge 20b0: 6f 6d 46 72 6f 6d 45 57 4b 42 28 67 65 6f 6d 65 omFromEWKB(geome 20c0: 74 72 79 29 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 try);....SELECT 20d0: 44 49 53 54 49 4e 43 54 20 53 54 5f 47 65 6f 6d DISTINCT ST_Geom 20e0: 65 74 72 79 54 79 70 65 28 67 65 6f 6d 65 74 72 etryType(geometr 20f0: 79 29 2c 20 53 54 5f 53 72 69 64 28 67 65 6f 6d y), ST_Srid(geom 2100: 65 74 72 79 29 2c 20 43 6f 6f 72 64 44 69 6d 65 etry), CoordDime 2110: 6e 73 69 6f 6e 28 67 65 6f 6d 65 74 72 79 29 0d nsion(geometry). 2120: 0a 46 52 4f 4d 20 66 72 6f 6d 5f 70 6f 73 74 67 .FROM from_postg 2130: 69 73 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d is;..----------- 2140: 2d 0d 0a 4c 49 4e 45 53 54 52 49 4e 47 7c 32 35 -..LINESTRING|25 2150: 38 33 32 7c 58 59 0d 0a 0d 0a 53 45 4c 45 43 54 832|XY....SELECT 2160: 20 52 65 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 RecoverGeometry 2170: 43 6f 6c 75 6d 6e 28 27 66 72 6f 6d 5f 70 6f 73 Column('from_pos 2180: 74 67 69 73 27 2c 20 27 67 65 6f 6d 65 74 72 79 tgis', 'geometry 2190: 27 2c 20 32 35 38 33 32 2c 20 27 4c 49 4e 45 53 ', 25832, 'LINES 21a0: 54 52 49 4e 47 27 2c 20 27 58 59 27 29 3b 0d 0a TRING', 'XY');.. 21b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d ------------..1. 21c0: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54 68 .</verbatim>..Th 21d0: 69 73 20 73 65 71 75 65 6e 63 65 20 6f 66 20 53 is sequence of S 21e0: 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 20 28 53 QL statements (S 21f0: 70 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 patiaLite suppor 2200: 74 20 69 73 20 73 74 72 69 63 74 6c 79 20 72 65 t is strictly re 2210: 71 75 69 72 65 64 29 20 77 69 6c 6c 20 74 72 61 quired) will tra 2220: 6e 73 66 65 72 20 61 20 66 75 6c 6c 79 20 71 75 nsfer a fully qu 2230: 61 6c 69 66 69 65 64 20 47 65 6f 6d 65 74 72 79 alified Geometry 2240: 20 74 61 62 6c 65 20 66 72 6f 6d 20 50 6f 73 74 table from Post 2250: 47 49 53 20 74 6f 20 53 70 61 74 69 61 4c 69 74 GIS to SpatiaLit 2260: 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 e:..<ul>..<li><b 2270: 3e 73 74 65 70 20 31 3c 2f 62 3e 3a 20 66 69 72 >step 1</b>: fir 2280: 73 74 20 77 65 27 6c 6c 20 74 72 61 6e 73 66 65 st we'll transfe 2290: 72 20 74 68 65 20 77 68 6f 6c 65 20 50 6f 73 74 r the whole Post 22a0: 47 49 53 20 74 61 62 6c 65 20 69 6e 74 6f 20 53 GIS table into S 22b0: 51 4c 69 74 65 3b 20 67 65 6f 6d 65 74 72 69 65 QLite; geometrie 22c0: 73 20 61 72 65 20 73 74 69 6c 6c 20 72 65 70 72 s are still repr 22d0: 65 73 65 6e 74 65 64 20 62 79 20 74 68 65 69 72 esented by their 22e0: 20 3c 62 3e 45 57 4b 42 3c 2f 62 3e 20 68 65 78 <b>EWKB</b> hex 22f0: 61 64 65 63 69 6d 61 6c 20 6e 6f 74 61 74 69 6f adecimal notatio 2300: 6e 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 ns.</li>..<li><b 2310: 3e 73 74 65 70 20 32 3c 2f 62 3e 3a 20 74 68 65 >step 2</b>: the 2320: 6e 20 77 65 27 6c 6c 20 75 73 65 20 74 68 65 20 n we'll use the 2330: 3c 62 3e 47 65 6f 6d 46 72 6f 6d 45 57 4b 42 28 <b>GeomFromEWKB( 2340: 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 )</b> SQL functi 2350: 6f 6e 20 73 6f 20 74 6f 20 67 65 74 20 74 68 65 on so to get the 2360: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 3c corresponding < 2370: 62 3e 53 70 61 74 69 61 4c 69 74 65 27 73 20 42 b>SpatiaLite's B 2380: 4c 4f 42 3c 2f 62 3e 20 66 6f 72 20 65 61 63 68 LOB</b> for each 2390: 20 67 65 6f 6d 65 74 72 79 2e 3c 2f 6c 69 3e 0d geometry.</li>. 23a0: 0a 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 33 3c 2f .<li><b>step 3</ 23b0: 62 3e 3a 20 6e 6f 77 20 77 65 20 73 69 6d 70 6c b>: now we simpl 23c0: 79 20 68 61 76 65 20 74 6f 20 64 69 73 63 6f 76 y have to discov 23d0: 65 72 20 74 68 65 20 54 79 70 65 2c 20 53 52 49 er the Type, SRI 23e0: 44 20 61 6e 64 20 44 69 6d 65 6e 73 69 6f 6e 73 D and Dimensions 23f0: 20 64 65 63 6c 61 72 65 64 20 62 79 20 74 68 65 declared by the 2400: 73 65 20 67 65 6f 6d 65 74 72 69 65 73 2e 3c 2f se geometries.</ 2410: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65 70 li>..<li><b>step 2420: 20 34 3c 2f 62 3e 3a 20 61 6e 64 20 66 69 6e 61 4</b>: and fina 2430: 6c 6c 79 20 77 65 20 63 61 6e 20 6e 6f 77 20 72 lly we can now r 2440: 65 63 6f 76 65 72 20 61 20 66 75 6c 6c 20 71 75 ecover a full qu 2450: 61 6c 69 66 69 65 64 20 53 70 61 74 69 61 4c 69 alified SpatiaLi 2460: 74 65 27 73 20 6f 77 6e 20 28 3c 69 3e 6e 61 74 te's own (<i>nat 2470: 69 76 65 3c 2f 69 3e 29 20 47 65 6f 6d 65 74 72 ive</i>) Geometr 2480: 79 20 63 6f 6c 75 6d 6e 2e 3c 2f 6c 69 3e 0d 0a y column.</li>.. 2490: 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d </ul><br>..<hr>. 24a0: 0a 3c 68 33 3e 65 78 70 6f 72 74 69 6e 67 20 64 .<h3>exporting d 24b0: 61 74 61 20 66 72 6f 6d 20 53 51 4c 69 74 65 20 ata from SQLite 24c0: 74 6f 20 50 6f 73 74 67 72 65 73 2f 50 6f 73 74 to Postgres/Post 24d0: 47 49 53 3c 2f 68 33 3e 0d 0a 46 6f 72 20 72 61 GIS</h3>..For ra 24e0: 74 68 65 72 20 6f 62 76 69 6f 75 73 20 73 65 63 ther obvious sec 24f0: 75 72 69 74 79 20 72 65 61 73 6f 6e 73 2c 20 61 urity reasons, a 2500: 6c 6c 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 ll VirtualPostgr 2510: 65 73 20 74 61 62 6c 65 73 20 61 72 65 20 64 65 es tables are de 2520: 63 6c 61 72 65 64 20 74 6f 20 62 65 20 3c 69 3e clared to be <i> 2530: 72 65 61 64 2d 6f 6e 6c 79 3c 2f 69 3e 20 62 79 read-only</i> by 2540: 20 64 65 66 61 75 6c 74 2e 3c 62 72 3e 0d 0a 54 default.<br>..T 2550: 68 69 73 20 61 63 74 75 61 6c 6c 79 20 6d 65 61 his actually mea 2560: 6e 73 20 74 68 61 74 20 79 6f 75 20 61 72 65 20 ns that you are 2570: 65 6e 61 62 6c 65 64 20 74 6f 20 65 78 65 63 75 enabled to execu 2580: 74 65 20 61 6e 79 20 70 6f 73 73 69 62 6c 65 20 te any possible 2590: 3c 62 3e 53 45 4c 45 43 54 3c 2f 62 3e 20 71 75 <b>SELECT</b> qu 25a0: 65 72 79 2c 20 62 75 74 20 61 6e 79 20 3c 62 3e ery, but any <b> 25b0: 49 4e 53 45 52 54 3c 2f 62 3e 2c 20 3c 62 3e 55 INSERT</b>, <b>U 25c0: 50 44 41 54 45 3c 2f 62 3e 20 6f 72 20 3c 62 3e PDATE</b> or <b> 25d0: 44 45 4c 45 54 45 3c 2f 62 3e 20 6f 70 65 72 61 DELETE</b> opera 25e0: 74 69 6f 6e 20 61 66 66 65 63 74 69 6e 67 20 74 tion affecting t 25f0: 68 65 20 50 6f 73 74 67 72 65 73 20 44 42 4d 53 he Postgres DBMS 2600: 20 69 73 20 73 74 72 69 63 74 6c 79 20 66 6f 72 is strictly for 2610: 62 69 64 64 65 6e 2e 0d 0a 3c 76 65 72 62 61 74 bidden...<verbat 2620: 69 6d 3e 0d 0a 43 52 45 41 54 45 20 56 49 52 54 im>..CREATE VIRT 2630: 55 41 4c 20 54 41 42 4c 45 20 70 67 5f 6f 75 74 UAL TABLE pg_out 2640: 20 0d 0a 20 20 20 20 55 53 49 4e 47 20 56 69 72 .. USING Vir 2650: 74 75 61 6c 50 6f 73 74 67 72 65 73 20 28 27 68 tualPostgres ('h 2660: 6f 73 74 61 64 64 72 3d 31 39 32 2e 31 36 38 2e ostaddr=192.168. 2670: 31 2e 39 31 20 70 6f 72 74 3d 35 34 33 32 20 64 1.91 port=5432 d 2680: 62 6e 61 6d 65 3d 67 69 73 20 75 73 65 72 3d 73 bname=gis user=s 2690: 61 6e 64 72 6f 20 70 61 73 73 77 6f 72 64 3d 73 andro password=s 26a0: 65 63 72 65 74 27 2c 20 6d 79 5f 73 63 68 65 6d ecret', my_schem 26b0: 61 2c 20 6d 79 5f 74 61 62 6c 65 2c 20 57 29 3b a, my_table, W); 26c0: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 41 ..</verbatim>..A 26d0: 6e 79 77 61 79 20 79 6f 75 20 63 61 6e 20 65 78 nyway you can ex 26e0: 70 6c 69 63 69 74 6c 79 20 72 65 71 75 65 73 74 plicitly request 26f0: 20 61 20 56 69 72 74 75 61 6c 50 6f 73 74 67 72 a VirtualPostgr 2700: 65 73 20 74 61 62 6c 65 20 74 6f 20 73 75 70 70 es table to supp 2710: 6f 72 74 20 75 6e 63 6f 6e 73 74 72 61 69 6e 65 ort unconstraine 2720: 64 20 3c 69 3e 72 65 61 64 2d 77 72 69 74 65 3c d <i>read-write< 2730: 2f 69 3e 20 6f 70 65 72 61 74 69 6f 6e 73 2c 20 /i> operations, 2740: 74 68 69 73 20 69 6e 63 6c 75 64 69 6e 67 20 61 this including a 2750: 6e 79 20 3c 62 3e 49 4e 53 45 52 54 3c 2f 62 3e ny <b>INSERT</b> 2760: 2c 20 3c 62 3e 55 50 44 41 54 45 3c 2f 62 3e 20 , <b>UPDATE</b> 2770: 6f 72 20 3c 62 3e 44 45 4c 45 54 45 3c 2f 62 3e or <b>DELETE</b> 2780: 20 73 74 61 74 65 6d 65 6e 74 20 61 66 66 65 63 statement affec 2790: 74 69 6e 67 20 74 68 65 20 50 6f 73 74 67 72 65 ting the Postgre 27a0: 73 20 44 42 4d 53 2e 3c 62 72 3e 0d 0a 49 6e 20 s DBMS.<br>..In 27b0: 74 68 69 73 20 63 61 73 65 20 79 6f 75 20 73 69 this case you si 27c0: 6d 70 6c 79 20 68 61 76 65 20 74 6f 20 70 61 73 mply have to pas 27d0: 73 20 61 20 66 75 72 74 68 65 72 20 66 6f 75 72 s a further four 27e0: 74 68 20 61 72 67 75 6d 65 6e 74 20 69 6e 74 6f th argument into 27f0: 20 74 68 65 20 3c 62 3e 55 53 49 4e 47 3c 2f 62 the <b>USING</b 2800: 3e 20 63 6c 61 75 73 65 20 65 78 61 63 74 6c 79 > clause exactly 2810: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 corresponding t 2820: 6f 20 74 68 65 20 6c 65 74 74 65 72 20 3c 62 3e o the letter <b> 2830: 57 3c 2f 62 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 W</b>...<verbati 2840: 6d 3e 0d 0a 44 45 4c 45 54 45 20 46 52 4f 4d 20 m>..DELETE FROM 2850: 70 67 5f 6f 75 74 3b 0d 0a 0d 0a 49 4e 53 45 52 pg_out;....INSER 2860: 54 20 49 4e 54 4f 20 70 67 5f 6f 75 74 20 28 66 T INTO pg_out (f 2870: 6c 64 5f 61 2c 20 66 6c 64 5f 62 2c 20 66 6c 64 ld_a, fld_b, fld 2880: 5f 63 2c 20 67 65 6f 6d 65 74 72 79 29 0d 0a 53 _c, geometry)..S 2890: 45 4c 45 43 54 20 66 6c 64 5f 61 2c 20 66 6c 64 ELECT fld_a, fld 28a0: 5f 62 2c 20 66 6c 64 5f 63 2c 20 41 73 45 57 4b _b, fld_c, AsEWK 28b0: 42 28 67 65 6f 6d 65 74 72 79 29 0d 0a 66 72 6f B(geometry)..fro 28c0: 6d 20 73 6f 6d 65 5f 74 61 62 6c 65 3b 0d 0a 3c m some_table;..< 28d0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 6e 20 74 /verbatim>..In t 28e0: 68 65 20 61 62 6f 76 65 20 65 78 61 6d 70 6c 65 he above example 28f0: 20 77 65 27 6c 6c 20 64 65 6c 65 74 65 20 66 69 we'll delete fi 2900: 72 73 74 20 61 6e 79 20 61 6c 72 65 61 64 79 20 rst any already 2910: 65 78 69 73 74 69 6e 67 20 72 6f 77 20 66 72 6f existing row fro 2920: 6d 20 74 68 65 20 50 6f 73 74 47 49 53 20 74 61 m the PostGIS ta 2930: 62 6c 65 3b 20 74 68 65 6e 20 77 65 27 6c 6c 20 ble; then we'll 2940: 73 69 6d 70 6c 79 20 74 72 61 6e 73 66 65 72 20 simply transfer 2950: 74 68 65 20 77 68 6f 6c 65 20 74 61 62 6c 65 20 the whole table 2960: 66 72 6f 6d 20 53 70 61 74 69 61 4c 69 74 65 20 from SpatiaLite 2970: 69 6e 74 6f 20 50 6f 73 74 47 49 53 2e 3c 62 72 into PostGIS.<br 2980: 3e 0d 0a 50 6c 65 61 73 65 20 6e 6f 74 65 2c 20 >..Please note, 2990: 77 65 27 6c 6c 20 69 6e 76 6f 6b 65 20 74 68 65 we'll invoke the 29a0: 20 3c 62 3e 41 73 45 57 4b 42 28 29 3c 2f 62 3e <b>AsEWKB()</b> 29b0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 6e SQL function in 29c0: 20 6f 72 64 65 72 20 74 6f 20 63 6f 6e 76 65 72 order to conver 29d0: 74 20 61 6e 79 20 53 70 61 74 69 61 4c 69 74 65 t any SpatiaLite 29e0: 27 73 20 6f 77 6e 20 3c 62 3e 42 4c 4f 42 3c 2f 's own <b>BLOB</ 29f0: 62 3e 20 67 65 6f 6d 65 74 72 79 20 69 6e 74 6f b> geometry into 2a00: 20 74 68 65 20 65 71 75 69 76 61 6c 65 6e 74 20 the equivalent 2a10: 3c 62 3e 42 59 54 45 41 20 45 57 4b 42 3c 2f 62 <b>BYTEA EWKB</b 2a20: 3e 20 6e 6f 74 61 74 69 6f 6e 20 72 65 71 75 69 > notation requi 2a30: 72 65 64 20 62 79 20 50 6f 73 74 47 49 53 2e 3c red by PostGIS.< 2a40: 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f br>..<table bgco 2a50: 6c 6f 72 3d 22 23 66 66 66 66 65 38 22 20 77 69 lor="#ffffe8" wi 2a60: 64 74 68 3d 22 31 30 30 25 22 3e 0d 0a 3c 74 72 dth="100%">..<tr 2a70: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 ><td align="cent 2a80: 65 72 22 3e 3c 62 3e 43 61 76 65 61 74 3a 20 41 er"><b>Caveat: A 2a90: 73 45 57 4b 42 28 29 3c 2f 62 3e 3c 2f 74 64 3e sEWKB()</b></td> 2aa0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c </tr>..<tr><td>< 2ab0: 68 72 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c hr></td></tr>..< 2ac0: 74 72 3e 3c 74 64 3e 0d 0a 41 6e 79 20 70 72 65 tr><td>..Any pre 2ad0: 76 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 6f 66 vious version of 2ae0: 20 53 70 61 74 69 61 4c 69 74 65 20 28 74 68 69 SpatiaLite (thi 2af0: 73 20 69 6e 63 6c 75 64 69 6e 67 20 74 68 65 20 s including the 2b00: 63 75 72 72 65 6e 74 20 3c 62 3e 34 2e 31 2e 31 current <b>4.1.1 2b10: 3c 2f 62 3e 29 20 73 75 70 70 6f 72 74 65 64 20 </b>) supported 2b20: 61 20 62 75 67 67 69 73 68 20 3c 62 3e 41 73 45 a buggish <b>AsE 2b30: 57 4b 42 28 29 3c 2f 62 3e 20 69 6d 70 6c 65 6d WKB()</b> implem 2b40: 65 6e 74 61 74 69 6f 6e 20 63 6f 6d 70 6c 65 74 entation complet 2b50: 65 6c 79 20 75 6e 61 62 6c 65 20 74 6f 20 63 72 ely unable to cr 2b60: 65 61 74 65 20 76 61 6c 69 64 20 45 57 4b 42 20 eate valid EWKB 2b70: 47 65 6f 6d 65 74 72 69 65 73 20 74 6f 20 62 65 Geometries to be 2b80: 20 70 61 73 73 65 64 20 74 6f 20 50 6f 73 74 47 passed to PostG 2b90: 49 53 2e 0d 0a 49 20 70 72 65 73 75 6d 65 20 74 IS...I presume t 2ba0: 68 61 74 20 6e 6f 62 6f 64 79 20 72 65 61 6c 6c hat nobody reall 2bb0: 79 20 61 74 74 65 6d 70 74 65 64 20 74 6f 20 75 y attempted to u 2bc0: 73 65 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e se this function 2bd0: 20 62 65 66 6f 72 65 2c 20 73 6f 20 74 68 69 73 before, so this 2be0: 20 62 75 67 20 70 61 73 73 65 64 20 63 6f 6d 70 bug passed comp 2bf0: 6c 65 74 65 6c 79 20 75 6e 6e 6f 74 69 63 65 64 letely unnoticed 2c00: 20 73 69 6e 63 65 20 6e 6f 77 2e 3c 62 72 3e 0d since now.<br>. 2c10: 0a 55 73 69 6e 67 20 74 68 65 20 6c 61 74 65 73 .Using the lates 2c20: 74 20 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 t version of the 2c30: 20 63 6f 64 65 20 61 76 61 69 6c 61 62 6c 65 20 code available 2c40: 66 72 6f 6d 20 74 68 65 20 46 6f 73 73 69 6c 20 from the Fossil 2c50: 72 65 70 6f 73 69 74 6f 72 79 20 69 73 20 73 74 repository is st 2c60: 72 69 63 74 6c 79 20 72 65 71 75 69 72 65 64 20 rictly required 2c70: 73 6f 20 74 6f 20 72 65 61 6c 6c 79 20 67 65 74 so to really get 2c80: 20 61 20 77 6f 72 6b 69 6e 67 20 41 73 45 57 4b a working AsEWK 2c90: 4b 28 29 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e K()...</td></tr> 2ca0: 0d 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e ..</table>..<br> 2cb0: 0d 0a 42 61 63 6b 20 74 6f 20 3c 62 3e 56 69 72 ..Back to <b>Vir 2cc0: 74 75 61 6c 50 47 3c 2f 62 3e 20 3c 61 20 68 72 tualPG</b> <a hr 2cd0: 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e ef="https://www. 2ce0: 67 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 gaia-gis.it/foss 2cf0: 69 6c 2f 76 69 72 74 75 61 6c 70 67 2f 69 6e 64 il/virtualpg/ind 2d00: 65 78 22 3e 68 6f 6d 65 20 70 61 67 65 3c 2f 61 ex">home page</a 2d10: 3e 0a 5a 20 61 30 39 65 38 31 30 64 38 38 64 35 >.Z a09e810d88d5 2d20: 63 30 61 66 65 64 62 39 33 37 66 32 65 61 31 62 c0afedb937f2ea1b 2d30: 34 30 65 37 0a 40e7.