pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Barknecht <barknech@ph-cip.uni-koeln.de>
To: pgsql-sql <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] Insert a long text
Date: Mon, 22 Feb 1999 12:37:32 +0100
Message-ID: <19990222123732.A10469@fliwatut> (raw)
In-Reply-To: <F10BB1FAF801D111829B0060971D839F68CBB3@cpsmail>
References: <F10BB1FAF801D111829B0060971D839F68CBB3@cpsmail>

Jackson, DeJuan hat gesagt: // Jackson, DeJuan wrote:

>   1) store the text in chunks in the database.
>      in other words instead of just using
>        CREATE TABLE my_text(message_id INT, data TEXT)
>      try
>        CREATE TABLE my_text(message_id INT, chunk_id INT, data TEXT);
>      then figure out what your insert limit is and break each TEXT
>      block into chunks of that size.

To store longer text I am now trying to do it in this way. But first I have
to find out what is the insert limit. For this I wrote a little test script
with perl and DBI which now gives me some strange results. 

The script is basically this:

#!/usr/bin/perl -w
use diagnostics;
use DBI;
use strict;

# Konfiguration:
my $dbname="einblick";
my $user="freak";
my $passwd="";
my $tabelle = "my_text";

# For testing inserts I made a rather small long text: ~ 420 bytes 
my $text = '
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 0
# ... and so on until
9 9
1 0 0
1 0 1
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
1 0 9
';
my $id = 80;

# PG connect
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $passwd) 
             || die "Can't connect to $dbname: $DBI::errstr";

# SQL-Statement
my $sql = "INSERT INTO $tabelle 
( message_id, chunk_id, data) VALUES ( ?, ?, ?)";
my $sth = $dbh->prepare("$sql") || die "Can't prepare statement: $DBI::errstr";
$sth->trace(2, "/tmp/trace_pg");
my $rc = $sth->execute( $id, 0, $text )
             || die "Can't execute statement: $DBI::errstr";
$sth->finish;
$dbh->disconnect;
# END testscript

This runs without problems at first sight but it does NOT insert the whole
text from $text. Instead it cuts it off at around line "9 9" 
This seems not to be a problem with the data type anymore because I can
change the entry with pgaccess and make it a longer one. The whole text does 
indeed fit into the column but I don't manage to insert it with my script. 

I traced the transaction and this shows something like:

/tmp/trace_pg:
dbd_st_execute: statement = >INSERT INTO my_text 
( message_id, chunk_id, data) values ( 80, 0, '
0 0
0 1
   [... I did shorten the output here!]
9 6
9 7
9 ...')<
    <- execute= 1 at /home/freak/bin/langtext.pl line 137.
    -> finish for DBD::Pg::st (DBI::st=HASH(0x8209244)~0x81ca35c)
    <- finish= 1 at /home/freak/bin/langtext.pl line 139.
    -> DESTROY for DBD::Pg::st (DBI::st=HASH(0x81ca35c)~INNER)
dbd_st_destroy
    <- DESTROY= undef

Obiously I am still doing something wrong here but I have no idea what 
it is. It would be great if someone could help me.
Many thanks in advance,
-- 
                                                     __    __
 Frank Barknecht           ____ ______   ____ __ trip\ \  / /wire ______
                          / __// __  /__/ __// // __  \ \/ /  __ \\  ___\	
                         / /  / ____/  / /  / // ____// /\ \\  ___\\____ \	
                        /_/  /_____/  /_/  /_//_____// /  \ \\_____\\_____\
                                                    /_/    \_\ 



view thread (6+ messages)

Message-ID: <19990222123732.A10469@fliwatut>
Permalink:  ../19990222123732.A10469@fliwatut/
Also on:    postgresql.org/message-id/19990222123732.A10469@fliwatut

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: barknech@ph-cip.uni-koeln.de
  Subject: Re: [SQL] Insert a long text
  In-Reply-To: <19990222123732.A10469@fliwatut>
  References: <F10BB1FAF801D111829B0060971D839F68CBB3@cpsmail> <19990222123732.A10469@fliwatut>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox