· 7 years ago · Jul 29, 2018, 01:00 AM
1PostgeSQL \lo_import and how to get the resulting OID into an UPDATE command?
2"C:Program FilesPostgreSQL9.0binpsql.exe" -h 192.168.1.12 -p 5432 -d myDB -U my_admin -c "lo_import 'C://im/zzz4.jpg'";
3
4UPDATE species
5SET speciesimages=17755; -- OID from previous command.. how to get the OID ??
6WHERE species='ACCOAA';
7
8ERROR: syntax error at or near ""lo_import 'C://im/zzz4.jpg'""
9LINE 1: "lo_import 'C://im/zzz4.jpg'"
10
11update species
12set speciesimages=lo_import 'C://im/zzz4.jpg'
13where species='ACAAC04';
14
15ERROR: syntax error at or near ""
16LINE 2: set speciesimages=lo_import 'C://im/zzz4.jpg'
17 ^
18
19UPDATE species
20SET speciesimages = lo_import('/path/to/server-local/file/zzz4.jpg')
21WHERE species = 'ACAAC04';
22
23UPDATE species
24SET speciesimages = :LASTOID
25WHERE species = 'ACAAC04';
26
27echo "lo_import '/path/to/my/file/zzz4.jpg' \\ UPDATE species SET speciesimages = :LASTOID WHERE species = 'ACAAC04';" |
28psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin
29
30psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin << EOF
31lo_import '/path/to/my/file/zzz4.jpg'
32UPDATE species
33SET speciesimages = :LASTOID
34WHERE species = 'ACAAC04';
35EOF