[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: octave and postgres examples
From: |
Olaf Till |
Subject: |
Re: octave and postgres examples |
Date: |
Thu, 20 Jun 2013 09:44:59 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Wed, Jun 19, 2013 at 04:36:10PM -0400, Thomas Grzybowski wrote:
> <snip>
> I could really use some examples of reading and writing tables to
> and from octave arrays. If anyone could post some example code that
> would be very much appreciated.
octave:2> conn = pq_connect (setdbopts ("dbname", "test"));
octave:4> pq_exec_params (conn, "create table octave_array (a float8, b float8,
c float8);")
ans = 0
octave:5> array = reshape (linspace (0, 1, 12), 4, 3)
array =
0.00000 0.36364 0.72727
0.09091 0.45455 0.81818
0.18182 0.54545 0.90909
0.27273 0.63636 1.00000
octave:6> pq_exec_params (conn, "copy octave_array from stdin with binary;",
setdbopts ("copy_in_from_variable", true, "copy_in_data", num2cell (array)))
octave:7> table = pq_exec_params (conn, "select * from octave_array;");
octave:9> cell2mat (table.data)
ans =
0.00000 0.36364 0.72727
0.09091 0.45455 0.81818
0.18182 0.54545 0.90909
0.27273 0.63636 1.00000
octave:10> table.columns
ans =
{
[1,1] = a
[1,2] = b
[1,3] = c
}
octave:11> pq_exec_params (conn, "drop table octave_array;")
ans = 0
octave:12> pq_close (conn)
Olaf
--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net
signature.asc
Description: Digital signature