[GENERAL] Crosstab query on huge amount of values

2011-01-16 Thread Julia Jacobson

Hello everybody out there using PostgreSQL,

A table with the results of students in different exams

student | date_of_exam | grade
--
Peter   | 2010-09-09   | 2
Tom | 2010-09-09   | 1
Andy| 2010-09-21   | 3
Tom | 2010-09-21   | 4
Peter   | 2010-09-21   | 1
Peter   | 2010-10-11   | 2

shall be transformed to a denormalized view like:

student | grade_2010_09_09 | grade_2010_09_21 | grade_2010_10_11

Peter   | 2| 1| 2
Tom | 1| 4| NULL
Andy| NULL | 3| NULL

I've already done extensive Web-search and posted in Usenet for help 
concerning this problem and was pointed to the tablefunc module which 
seems to be a solution.
Since I only have a database but no administrative rights for the 
PostgreSQL installation, I can't use the tablefunc module.

Is there any way to denormalize my table using a simple SQL script?

Thanks in advance,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Crosstab query on huge amount of values

2011-01-17 Thread Julia Jacobson

Am 17.01.2011 00:20, schrieb Steve Litt:

On Sunday 16 January 2011 17:40:34 Julia Jacobson wrote:

Hello everybody out there using PostgreSQL,

A table with the results of students in different exams

student | date_of_exam | grade
--
Peter   | 2010-09-09   | 2
Tom | 2010-09-09   | 1
Andy| 2010-09-21   | 3
Tom | 2010-09-21   | 4
Peter   | 2010-09-21   | 1
Peter   | 2010-10-11   | 2

shall be transformed to a denormalized view like:

student | grade_2010_09_09 | grade_2010_09_21 | grade_2010_10_11

Peter   | 2| 1| 2
Tom | 1| 4| NULL
Andy| NULL | 3| NULL

I've already done extensive Web-search and posted in Usenet for help
concerning this problem and was pointed to the tablefunc module which
seems to be a solution.
Since I only have a database but no administrative rights for the
PostgreSQL installation, I can't use the tablefunc module.
Is there any way to denormalize my table using a simple SQL script?

Thanks in advance,
Julia


Hi Julia,

If you're denormalizing it just for a report, you could do it in your
application, and just ringtoss rows onto the test periods.

If you want to have a permanent table containing the denormalized material
(and one would have to ask why), then one possible method would be the same as
for the report -- let your application ring toss rows onto the newly created
table containing an array. Since you have no administrative rights, the DBA
would need to create the denormalized table, and add another column every time
there's a new exam.

Let the darn thing run overnight, or perhaps do one exam at a time or a small
range of students at a time. Do you happen to know why they want a
denormalized table as opposed to just making an index sorted by student and
then by grade period? Do you have any idea how long it would take to create an
index sorted first by student and then by exam?

I'm sure there are easier ways of doing it, but what I suggested is one way
that it could work.

HTH

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt



Hello Steve,

Thanks a lot for your answer.
Indeed, I actually want to denormalize my table for a report, but I need 
to join the denormalized table with another table of the database for 
this report.
So when I ring toss rows and columns in my application, it won't be 
possible to do the join anymore.
Although I think PostgreSQL does good in not offering pivot tables like 
Oracle or MS-SQL, I'm really desperately looking for a workaround here.


Regards,
Julia


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Subquery for column names of tablefunc crosstab queries

2011-01-21 Thread Julia Jacobson

Hello everybody out there familiar with the tablefunc module,

Having read the documentation of the tablefunc module,
I'm wondering whether it is possible to get the values for the names of 
the columns for the crosstab query from a subquery.

A minimal example would look like this:

CREATE TABLE mytable(rowid text, rowdt timestamp, temperature int);
INSERT INTO cth VALUES('test1','01 March 2003','42');
INSERT INTO cth VALUES('test2','02 March 2003','53');
INSERT INTO cth VALUES('test3','03 March 2003','49');

SELECT * FROM crosstab
(
  'SELECT rowid, rowdt, temperature FROM mytable ORDER BY 1',
  'SELECT DISTINCT rowdt FROM mytable ORDER BY 1'
)
AS
(
   rowid text  # This works fine
   # Here should be a subquery to get column names
   # automatically,
   # like 'SELECT rowdt FROM mytable'
);

Thanks in advance,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Subquery for column names of tablefunc crosstab queries

2011-01-21 Thread Julia Jacobson
Thanks for your answer. The fact that the column definition list must be 
available to the parser was not obvious to me.
Instead of building the second query dynamically in an application, I 
would prefer a user-defined function, because there will probably be 
several applications in need of it and (please correct me if I'm wrong) 
I hope for a better performance by creating a permanent view of my 
crosstab query.

So I have tried something like:

CREATE FUNCTION denorm_table(mytable_name) RETURNS text AS '
DECLARE
tab_def_list TEXT;
BEGIN
# First query to create table definition list
SELECT DISTINCT rowdt::date INTO tab_def_list FROM mytable_name;
# Crosstab Query
SELECT * FROM crosstab
(
  'SELECT rowid, rowdt, temperature FROM mytable ORDER BY 1',
  'SELECT DISTINCT rowdt FROM mytable ORDER BY 1'
)
AS
(
rowid text,
tab_def_list
);
END;
' LANGUAGE plpgsql;

Being rather unexperienced in PL/pgSQL, I have problems to get the code 
working.
Two further problems are the fact that the names of columns are not 
allowed to begin with a number and every entry in the table definition 
list must not only contain the name of the column but of course also a 
data type (always the same - int).
Is it possible for a newbie to solve my problem by a user-defined 
function in PL/pgSQL or is it rather complicated?



On 01/21/2011 16:08, Joe Conway wrote:

On 01/21/2011 05:48 AM, Julia Jacobson wrote:

Having read the documentation of the tablefunc module,
I'm wondering whether it is possible to get the values for the names of
the columns for the crosstab query from a subquery.
A minimal example would look like this:

CREATE TABLE mytable(rowid text, rowdt timestamp, temperature int);
INSERT INTO cth VALUES('test1','01 March 2003','42');
INSERT INTO cth VALUES('test2','02 March 2003','53');
INSERT INTO cth VALUES('test3','03 March 2003','49');

SELECT * FROM crosstab
(
   'SELECT rowid, rowdt, temperature FROM mytable ORDER BY 1',
   'SELECT DISTINCT rowdt FROM mytable ORDER BY 1'
)
AS
(
rowid text  # This works fine
# Here should be a subquery to get column names
# automatically,
# like 'SELECT rowdt FROM mytable'
);


No, it is not possible. The column definition list needs to be available
to the parser. I usually recommend running this as two queries from your
application. The first does:

SELECT DISTINCT rowdt::date FROM mytable ORDER BY 1;
rowdt

  2003-03-01
  2003-03-02
  2003-03-03
(3 rows)


Then the application dynamically builds the second query and executes
it. Following your example, something like:

SELECT * FROM crosstab
(
   $$SELECT rowid, rowdt::date, temperature FROM mytable ORDER BY 1$$,
   $$VALUES('2003-03-01'),('2003-03-02'),('2003-03-03')$$
)
AS
(
rowid text,
"2003-03-01" int,
"2003-03-02" int,
"2003-03-03" int
);
  rowid | 2003-03-01 | 2003-03-02 | 2003-03-03
---+++
  test1 | 42 ||
  test2 || 53 |
  test3 ||| 49
(3 rows)

HTH,

Joe



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] SELECT INTO array[i] with PL/pgSQL

2011-02-07 Thread Julia Jacobson

Dear PostgreSQL community,

Please consider the following minimal example:

CREATE TABLE example (row_id SERIAL, value TEXT);
INSERT INTO example(value) VALUES ('val1');
INSERT INTO example(value) VALUES ('val2');
INSERT INTO example(value) VALUES ('val3');

CREATE OR REPLACE FUNCTION foo()
RETURNS TEXT
AS
$$
DECLARE
  a TEXT;
  b TEXT[];
  i INT;
BEGIN
  FOR i in 1..3 LOOP
SELECT INTO avalue FROM example WHERE row_id=i;  -- This works
b[i] := a;   -- perfectly!
--  SELECT INTO b[i] value FROM example WHERE row_id=i;  Doesn't work!
  END LOOP;
RETURN b[2];
END;
$$
LANGUAGE 'plpgsql';

The error message indicates a problem with selecting values into an array.
I have read the documentation carefully and have done extensive web 
search, but a more verbose error message and some additional explanation 
would help me to understand the problem.
Is there a way to select values directly into an array without the 
assignment from an additional variable?


Regards,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Linking against static libpq using Visual C++

2011-02-27 Thread Julia Jacobson

Dear PostgreSQL community,

When trying to compile c++ code including libpq against the static 
version libpq.lib, Visual Studio 2010 gives me the following errors:


1>main.obj : error LNK2019: Unresolved external reference "__imp__exit" 
in Funktion "_main".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved external symbol 
"__imp__exit".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__imp__exit".
1>main.obj : error LNK2019: Unresolved external reference 
"__imp__fprintf" in Funktion "_main".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__impiob_func".
1>libpq.lib(win32error.obj) : error LNK2001: Unresolved external symbol 
"__impiob_func".
1>main.obj : error LNK2019: Unresolved external reference 
"__impiob_func" in Funktion "_main".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved external symbol 
"__impiob_func".
1>libpq.lib(encnames.obj) : error LNK2001: Unresolved external symbol 
"__impiob_func".
1>libpq.lib(snprintf.obj) : error LNK2001: Unresolved external symbol 
"__impiob_func".
1>main.obj : error LNK2019: Unresolved external reference 
"@_RTC_CheckStackVars@8" in Funktion "_main".
1>main.obj : error LNK2019: Unresolved external reference 
"__RTC_CheckEsp" in Funktion "_main".

1>main.obj : error LNK2001: Unresolved external symbol "__RTC_Shutdown".
1>main.obj : error LNK2001: Unresolved external symbol "__RTC_InitBase".
1>LINK : error LNK2001: Unresolved external symbol "_mainCRTStartup".
1>libpq.lib(md5.obj) : error LNK2019: Unresolved external reference 
"__imp__free" in Funktion "_pg_md5_hash".
1>libpq.lib(dirent.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(fe-protocol3.obj) : error LNK2001: Unresolved external 
symbol "__imp__free".
1>libpq.lib(fe-auth.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(getaddrinfo.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(fe-exec.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(pqexpbuffer.obj) : error LNK2001: Unresolved external symbol 
"__imp__free".
1>libpq.lib(fe-protocol2.obj) : error LNK2001: Unresolved external 
symbol "__imp__free".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__imp__strdup".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__strdup" in Funktion "_dupEvents".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved external symbol 
"__imp__strdup".
1>libpq.lib(fe-protocol3.obj) : error LNK2001: Unresolved external 
symbol "__imp__strdup".
1>libpq.lib(fe-auth.obj) : error LNK2001: Unresolved external symbol 
"__imp__strdup".
1>libpq.lib(getaddrinfo.obj) : error LNK2019: Unresolved external 
reference "__imp__malloc" in Funktion "_pg_getaddrinfo".
1>libpq.lib(md5.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(dirent.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(fe-protocol3.obj) : error LNK2001: Unresolved external 
symbol "__imp__malloc".
1>libpq.lib(pthread-win32.obj) : error LNK2001: Unresolved external 
symbol "__imp__malloc".
1>libpq.lib(fe-auth.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(fe-exec.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(pqexpbuffer.obj) : error LNK2001: Unresolved external symbol 
"__imp__malloc".
1>libpq.lib(fe-protocol2.obj) : error LNK2001: Unresolved external 
symbol "__imp__malloc".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__realloc" in Funktion "_pqAddTuple".
1>libpq.lib(pqexpbuffer.obj) : error LNK2001: Unresolved external symbol 
"__imp__realloc".
1>libpq.lib(fe-misc.obj) : error LNK2001: Unresolved external symbol 
"__imp__realloc".
1>libpq.lib(dirmod.obj) : error LNK2001: Unresolved external symbol 
"__imp__realloc".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__sscanf" in Funktion "_pqSaveParameterStatus".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__strncpy" in Funktion "_PQoidStatus".
1>libpq.lib(fe-protocol2.obj) : error LNK2001: Unresolved external 
symbol "__imp__strncpy".
1>libpq.lib(fe-protocol3.obj) : error LNK2001: Unresolved external 
symbol "__imp__strncpy".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__strspn" in Funktion "_PQoidStatus".
1>libpq.lib(fe-exec.obj) : error LNK2019: Unresolved external reference 
"__imp__strncmp" in Funktion "_PQoidStatus".
1>libpq.lib(fe-connect.obj) : error LNK2001: Unresolved exter

Re: [GENERAL] Linking against static libpq using Visual C++

2011-02-27 Thread Julia Jacobson
Thanks for your answer. I was indeed using the static libpq version from 
the installer.
I tried to compile my own one with Visual Studio 2010, but this caused a 
lot of problems due to the fact that Visual Studio 2010 has changed the 
manifest tool.
So I built a static version using Visual C++ 2008, which worked without 
problems.
However, when building my application with Visual C++ 2008, the 
following errors are lamented:


1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external 
reference "__imp__WSAIoctl@36" in Funktion "_setKeepalivesWin32".
1>libpq.lib(ip.obj) : error LNK2001: Unvresolved external symbol 
"__imp__WSAIoctl@36".
1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external 
reference "__imp__DeleteSecurityContext@4" in Funktion "_closePGconn".
1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external 
reference "__imp__FreeCredentialsHandle@4" in Funktion "_closePGconn".
1>libpq.lib(ip.obj) : error LNK2019: Unresolved external reference 
"__imp__WSASocketA@24" in Funktion "_pg_foreach_ifaddr".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference 
"_FreeContextBuffer@4" in Funktion "_pg_SSPI_continue".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference 
"_InitializeSecurityContextA@48" in Funktion "_pg_SSPI_continue".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference 
"_AcquireCredentialsHandleA@36" in Funktion "_pg_SSPI_startup".
1>C:\Users\Julia\Desktop\db_con\Debug\db_con.exe : fatal error LNK1120: 
7 Unresolved external references.


Which libraries are missing now?


Am Feb 27, 2011 at 16:18, Magnus Hagander wrote:

Did you build your own static version of libpq, or use the one that
comes with the installer? If the latter, then it's probably that it's
the wrong version of visual studio.

Those imports are from the Visual C runtimes, so that's what you're
missing for those - or using different versions.



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Linking against static libpq using Visual C++

2011-02-27 Thread Julia Jacobson

Thanks again for your answer.
For all those experiencing similar problems, the missing libraries were:
1) ws2_32.lib
2) secur32.lib (for the SSPI functions)
My code is compiled now without errors, but it seems to contain a buffer 
overflow. So there's still some work left for me ...


On Sun, Feb 27, 2011 at 19:00, Magnus Hagander wrote:

On Sun, Feb 27, 2011 at 18:01, Julia Jacobson  wrote:

Thanks for your answer. I was indeed using the static libpq version from the
installer.
I tried to compile my own one with Visual Studio 2010, but this caused a lot
of problems due to the fact that Visual Studio 2010 has changed the manifest
tool.
So I built a static version using Visual C++ 2008, which worked without
problems.
However, when building my application with Visual C++ 2008, the following
errors are lamented:

1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external reference
"__imp__WSAIoctl@36" in Funktion "_setKeepalivesWin32".
1>libpq.lib(ip.obj) : error LNK2001: Unvresolved external symbol
"__imp__WSAIoctl@36".
1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external reference
"__imp__DeleteSecurityContext@4" in Funktion "_closePGconn".
1>libpq.lib(fe-connect.obj) : error LNK2019: Unresolved external reference
"__imp__FreeCredentialsHandle@4" in Funktion "_closePGconn".
1>libpq.lib(ip.obj) : error LNK2019: Unresolved external reference
"__imp__WSASocketA@24" in Funktion "_pg_foreach_ifaddr".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference
"_FreeContextBuffer@4" in Funktion "_pg_SSPI_continue".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference
"_InitializeSecurityContextA@48" in Funktion "_pg_SSPI_continue".
1>libpq.lib(fe-auth.obj) : error LNK2019: Unresolved external reference
"_AcquireCredentialsHandleA@36" in Funktion "_pg_SSPI_startup".
1>C:\Users\Julia\Desktop\db_con\Debug\db_con.exe : fatal error LNK1120: 7
Unresolved external references.

Which libraries are missing now?


At least one of those is winsock, thus probably wsock2_32 or something
like that. The SSPI stuff is from some other system library, don't
know offhand which. You can look up the missing function in the MSDN
documentation, it should list which .lib is needed to access it.



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Linking against static libpq using Visual C++

2011-02-27 Thread Julia Jacobson

My application looks like this:

#include 
#include "libpq-fe.h"

using namespace std;

int main(void)
{
PGconn *conn;
const char *info = "hostaddr = 'postgres.server.com' \
port = '5432' \
dbname = 'mydb' \
user = 'user' \
password = 'secret' \
connect_timeout = '3'";
conn = PQconnectdb (info);
return 0;
}

Unfortunately, I really can't figure out the problem with it.
However, the code works fine when I try to compile it using:
g++ -I"C:\Programs\PostgreSQL8.4\include" \
-L"C:\Programs\PostgreSQL\8.4\lib" \
-lpq \
main.cpp

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Linking against static libpq using Visual C++

2011-02-27 Thread Julia Jacobson

Okay, I could fix it by myself now:
One has to tell Visual C++ to ignore msvcrt.lib.
A warning message during the compilation of my code already lamented a 
conflict between msvcrt and the included libraries.

I should have taken it for serious instead of just ignoring it.
So now everything works fine and I know again why I usually prefer to 
work with GNU tools and linux whenever possible.

Thanks for your help.


My application looks like this:

#include 
#include "libpq-fe.h"

using namespace std;

int main(void)
{
PGconn *conn;
const char *info = "hostaddr = 'postgres.server.com' \
port = '5432' \
dbname = 'mydb' \
user = 'user' \
password = 'secret' \
connect_timeout = '3'";
conn = PQconnectdb (info);
return 0;
}

Unfortunately, I really can't figure out the problem with it.
However, the code works fine when I try to compile it using:
g++ -I"C:\Programs\PostgreSQL8.4\include" \
-L"C:\Programs\PostgreSQL\8.4\lib" \
-lpq \
main.cpp


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Linking against static libpq using Visual C++

2011-03-31 Thread Julia Jacobson

Hi,

Although I finally managed to build libpq using Visual C++, I'm 
continuously experiencing problems with this IDE.
Therefore I switched to MinGW and it was indeed easy to compile libpq 
with it from the first time on.
However, I'm experiencing the same problem as discussed on 
http://archives.postgresql.org/pgsql-hackers-win32/2004-10/msg00010.php
Although linking the static compilation product libpq.a (106 Kb in size) 
to my application, the application only runs with libpq being present. 
This is confirmed by running depends.exe on it, which tells me that the 
application still depends on libpq.

I'm using PostgreSQL version 8.4.6 and the current version of MinGW/MSys.
How can I get a really static libpq and not one that still imports the 
dynamic link libraries?


Thanks in advance,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] psql '\copy' command for writing binary data from BYTEA column to file

2010-09-04 Thread Julia Jacobson

Hello everybody out there using PostgreSQL,
One of the tables in my database contains pictures in jpeg format in a 
column of the type BYTEA.
I have written a script in Python for inserting pictures into the 
database as well as exporting them from the database later. It works fine.
When running psql in Windows XP (PostgreSQL Version 8.3 on client, same 
on server) with the command

"\copy BINARY (SELECT picture FROM my_table LIMIT 1) TO picture.jpg;",
I get a corrupted image file, which can't be displayed or opened by any 
software.
The official documentation 
(http://www.postgresql.org/docs/8.3/interactive/sql-copy.html) contains 
a nice explanation for that:
"The file format used for COPY BINARY changed in PostgreSQL 7.4. The new 
format consists of a file header, zero or more tuples containing the row 
data, and a file trailer. Headers and data are now in network byte 
order. [...]
The file header consists of 15 bytes of fixed fields, followed by a 
variable-length header extension area."
I mean, the insertion of a header and a trailer probably destroys the 
jpeg format of the binary data.
Could anyone help me to find a way for writing the binary data from a 
BYTEA field to a file on the client?

Thanks in advance,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Extracting data from BYTEA column to binary file using libpq

2010-09-14 Thread Julia Jacobson

Hello everybody out there using PostgreSQL,

What is the problem with the following C++ code for the extraction of 
data from a BYTEA column to a binary file?


#include 
#include 
#include 
#include 
#include "libpq-fe.h"
using namespace std;

main ()
{
  PGconn *conn;
  conn = PQconnectdb("hostaddr='databaseserver.com' port='5432' 
dbname='test_db' user='test_user' password='secret'");

  int size;
  const char* contents;
  PGresult* res;
  res = PQexecParams(conn,
  "SELECT filecontent FROM pictures WHERE picture_id='3'",
  0, NULL,NULL,NULL,NULL,
  1);

  if (res && PQresultStatus(res)==PGRES_TUPLES_OK)
  {
size = PQgetlength(res, 0, 0);
contents = PQgetvalue(res, 0, 0);
  }
  ofstream myFile ("picture.jpg", ios::out | ios::binary);
  myFile.write (contents);
  myFile.close();
}

Thanks in advance,
Julia

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] SELF LEFT OUTER JOIN = SELF JOIN including NULL values

2010-09-17 Thread julia . jacobson
Hello everybody out there using PostgreSQL,

After having read the official documentation and having done extensive web 
search, I'm wondering how to perform something like a SELF LEFT OUTER JOIN in 
PostgreSQL, i.e. a SELF JOIN on a table containing NULL values in one of the 
columns to join.

Thanks in advance for your help,
Julia

Heute erleben, was morgen Trend wird - das kann man auf der IFA in Berlin. Oder 
auf arcor.de: Wir stellen Ihnen die wichtigsten News, Trends und Gadgets der 
IFA vor. Natürlich mit dabei: das brandneue IPTV-Angebot von Vodafone! Alles 
rund um die Internationale Funkausstellung in Berlin finden Sie hier: 
http://www.arcor.de/rd/footer.ifa2010

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general