[GENERAL] On using doubles as primary keys

2015-04-17 Thread Kynn Jones
I have some data in the form of a matrix of doubles (~2 million rows, ~400 columns) that I would like to store in a Pg table, along with the associated table of metadata (same number of rows, ~30 columns, almost all text). This is large enough to make working with it from flat files unwieldy. (Th

[GENERAL] Transforming pg_dump output to be compatible with SQLite 3.x

2014-08-29 Thread Kynn Jones
Greetings! I'm looking for tools/resources/ideas for making pg_dump's output compatible with SQLite v. 3.1.3. Ideally, I'd love to be able to do something like this (Unix): % rm -f mydatabase.db % pg_dump --no-owner --inserts mydatabase | pg_dump2sqlite3 | sqlite3 mydatabase.db ...where pg_

Re: [GENERAL] How to implement a uniqueness constraint across multiple tables?

2014-08-01 Thread Kynn Jones
On Thu, Jul 31, 2014 at 3:52 PM, Kevin Grittner wrote: This goes beyond the capabilities of declarative constraints to > enforce. You can enforce it using triggers, but you need to handle > race conditions, which is not easy with MVCC behavior (where reads > don't block anything and writes don't

Re: [GENERAL] How to implement a uniqueness constraint across multiple tables?

2014-08-01 Thread Kynn Jones
On Thu, Jul 31, 2014 at 3:19 PM, Rob Sargent wrote: > > Wouldn't this be a problem only if new subn() could/would re-use an id? > if new sub() generates a unique id, there would be no chance of two subn > entries having the same id. > I'd thought that the ids of the sub_k tables were never gener

[GENERAL] How to implement a uniqueness constraint across multiple tables?

2014-07-31 Thread Kynn Jones
I want to implement something akin to OO inheritance among DB tables. The idea is to define some "superclass" table, e.g.: CREATE TABLE super ( super_id INT PRIMARY KEY, ... -- other columns ); CREATE TABLE sub_1 ( super_id INT PRIMARY KEY, FOR

Re: [GENERAL] Random-looking primary keys in the range 100000..999999

2014-07-08 Thread Kynn Jones
Sat, Jul 5, 2014 at 4:35 AM, Martijn van Oosterhout wrote: > On Fri, Jul 04, 2014 at 09:24:31AM -0400, Kynn Jones wrote: > > I'm looking for a way to implement pseudorandom primary keys in the range > > 10..99. > > > > The randomization scheme does not need to

Re: [GENERAL] Random-looking primary keys in the range 100000..999999

2014-07-04 Thread Kynn Jones
On Fri, Jul 4, 2014 at 10:13 AM, hubert depesz lubaczewski wrote: > How many rows do you plan on having in this table? > Currently, only around 10K, but there's expectation that the number will grow. It's hard to predict how much, hence the generous extra space. > Why this particular key rang

[GENERAL] Random-looking primary keys in the range 100000..999999

2014-07-04 Thread Kynn Jones
I'm looking for a way to implement pseudorandom primary keys in the range 10..99. The randomization scheme does not need to be cryptographically strong. As long as it is not easy to figure out in a few minutes it's good enough. My starting point for this is the following earlier message

Re: [GENERAL] how to create a role with no privileges?

2014-07-01 Thread Kynn Jones
On Tue, Jul 1, 2014 at 1:28 PM, David G Johnston wrote: > The first rule regarding PostgreSQL permissions is that everything is > forbidden unless allowed - via GRANT. REVOKE simply undoes whatever has > been granted; it does not put up a block to prevent inheritance of granted > permissions. >

Re: [GENERAL] how to create a role with no privileges?

2014-07-01 Thread Kynn Jones
On Tue, Jul 1, 2014 at 12:36 PM, Francisco Olarte wrote: > Without seeing your actual commands, it's difficult to know about the > schema stuff... > Well, the "actual commands" is what the original question was asking for, since I really don't know how to do any of this (I find the documentation

Re: [GENERAL] how to create a role with no privileges?

2014-07-01 Thread Kynn Jones
2014 at 5:37 PM, Jerry Sievers wrote: > Kynn Jones writes: > > > How does one define the most limited role/user possible in PostgreSQL? > > > > Ideally, this role would not be able to do *anything* at all. In > particular, this role would not be able to query meta-info

[GENERAL] how to create a role with no privileges?

2014-06-30 Thread Kynn Jones
How does one define the most limited role/user possible in PostgreSQL? Ideally, this role would not be able to do *anything* at all. In particular, this role would not be able to query meta-information about existing tables, functions, etc. with backslash commands such as \dt, \df. (Of course, i

Re: [GENERAL] Fastest way to check database's existence

2010-10-17 Thread Kynn Jones
Thank you all for your comments and suggestions! ~kj

[GENERAL] Fastest way to check database's existence

2010-10-16 Thread Kynn Jones
I want to code a Perl function (part of a Perl library) for determining the existence of a particular database (in a given host/port). One way would be to just attempt making a connection to it, trapping any errors upon failure (with eval), or discarding the connection upon success. This approach

Re: [GENERAL] How to do pg_dump + pg_restore within Perl script?

2010-05-10 Thread Kynn Jones
On Mon, May 10, 2010 at 2:59 PM, Joshua D. Drake wrote: > On Mon, 2010-05-10 at 17:33 +, Greg Sabino Mullane wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: RIPEMD160 > > > > > > > I would like to replicate the following Unix pipe within a Perl script, > > > perhaps using DBD::Pg: > >

Re: [GENERAL] How to do pg_dump + pg_restore within Perl script?

2010-05-10 Thread Kynn Jones
On Mon, May 10, 2010 at 1:33 PM, Greg Sabino Mullane wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: RIPEMD160 > > > > I would like to replicate the following Unix pipe within a Perl script, > > perhaps using DBD::Pg: > > > > > > % pg_dump -Z9 -Fc -U | pg_restore -v -d -p > > -h localhos

[GENERAL] How to do pg_dump + pg_restore within Perl script?

2010-05-10 Thread Kynn Jones
I would like to replicate the following Unix pipe within a Perl script, perhaps using DBD::Pg: % pg_dump -Z9 -Fc -U | pg_restore -v -d -p -h localhost -U Of course, I can try to use Perl's system, and the like, to run this pipe verbatim, but I this as a last-resort approach. Is there a more

Re: [GENERAL] ISO guidelines/strategies to guard injection attacks

2010-01-21 Thread Kynn Jones
On Tue, Jan 19, 2010 at 4:49 PM, Andy Colson wrote: > On 1/19/2010 3:39 PM, Andy Colson wrote: > >> On 1/19/2010 3:23 PM, Kynn Jones wrote: >> >>> I have a Perl CGI script (using DBD::Pg) that interfaces with a >>> server-side Pg database. I'm looking fo

[GENERAL] PgSQL problem: How to split strings into rows

2010-01-21 Thread Kynn Jones
I have a table X with some column K consisting of whitespace-separated words. Is there some SELECT query that will list all these words (for the entire table) so that there's one word per row in the returned table? E.g. If the table X is K - foo bar baz quux fro

[GENERAL] ISO guidelines/strategies to guard injection attacks

2010-01-19 Thread Kynn Jones
I have a Perl CGI script (using DBD::Pg) that interfaces with a server-side Pg database. I'm looking for general guidelines/tools/strategies that will help me guard against SQL injection attacks. Any pointers/suggestions would be much appreciated. ~K

Re: [GENERAL] How to automatically find the *right* libpq_fe.h?

2009-11-04 Thread Kynn Jones
On Tue, Nov 3, 2009 at 2:39 PM, Steve Atkins wrote: > Rather, use the pg_config you find in the path to get the include directory > (or the compiler flags) or use App::Info::RDBMS::PostgreSQL or as a last > resort $POSTGRES_HOME. > pg_config did the trick. Thanks! Kynn

[GENERAL] How to automatically find the *right* libpq_fe.h?

2009-11-03 Thread Kynn Jones
I'm trying to automate an installation of a collection of Perl modules, which requires determining the path to the correct libpq_fe.h file. My original implementation of the Makefile.PL file for this installation set this path as the first valid path that it could extract from the output of the sy

Re: [GENERAL] How to list a role's permissions for a given relation?

2009-10-28 Thread Kynn Jones
Thanks! kynn On Tue, Oct 27, 2009 at 4:02 PM, Richard Huxton wrote: > Kynn Jones wrote: > > How can I list the permissions of a given user/role for a specific > > relation/view/index, etc.? > > From psql use \dp > > Using plain SQL, the closest I can think o

Re: [GENERAL] Why does pg_dump set default_with_oids to true?

2009-10-27 Thread Kynn Jones
Thank you all. Thanks again! Kynn

[GENERAL] Why does pg_dump set default_with_oids to true?

2009-10-26 Thread Kynn Jones
I've noticed that the dumps generated by pg_dump set the parameter default_with_oids to true in various places (separated by setting it back to false in-between). This happens even for databases whose creation and maintenance did not involve any explicit setting of this parameter. The documentati

[GENERAL] How to list a role's permissions for a given relation?

2009-10-24 Thread Kynn Jones
How can I list the permissions of a given user/role for a specific relation/view/index, etc.? Thanks! Kynn

Re: [GENERAL] How to send multiple SQL commands from Python?

2009-10-10 Thread Kynn Jones
On Sat, Oct 10, 2009 at 4:14 PM, Adrian Klaver wrote: > On Saturday 10 October 2009 12:27:39 pm Adrian Klaver wrote: > > On Saturday 10 October 2009 12:09:29 pm Kynn Jones wrote: > > > I am porting some code from Perl to Python; in the Perl original I use > > > eithe

[GENERAL] How to send multiple SQL commands from Python?

2009-10-10 Thread Kynn Jones
I am porting some code from Perl to Python; in the Perl original I use either DBI::do or a rickety home-built module to pass multiple SQL statements (as one single block of SQL) to the Pg server. The typical usage is something like this: $dbh->do( <

Re: [GENERAL] How to troubleshoot authentication failure?

2009-10-07 Thread Kynn Jones
Thank you all! Someone else in our team found the problem (a missing user in the failing server). k

[GENERAL] How to troubleshoot authentication failure?

2009-10-07 Thread Kynn Jones
I have two Linux servers that are pretty similar to each other, and both are running PostgreSQL servers, but in one server a certain Perl script succeeds in connecting to the localhost server whereas in the other one the same script fails. The error on the second server is of the form "fe_sendauth

Re: [GENERAL] Which header and lib files to use when compiling libpq-code?

2009-04-27 Thread Kynn Jones
On Mon, Apr 27, 2009 at 11:10 AM, Martijn van Oosterhout wrote: > On Mon, Apr 27, 2009 at 10:51:45AM -0400, Kynn Jones wrote: > > I need to compile some code that uses libpq. For this I need to > determine > > the directories to use for the header and library files. > > &

[GENERAL] Which header and lib files to use when compiling libpq-code?

2009-04-27 Thread Kynn Jones
I need to compile some code that uses libpq. For this I need to determine the directories to use for the header and library files. The machine I'm using has multiple copies of the files libpq-fe.h and libpq.a. How can I determine which one of all these copies are the ones that correspond to the

Re: [GENERAL] 'no pg_hba.conf entry for host "[local]", user "postgres", database "postgres"'...

2009-04-14 Thread Kynn Jones
On Tue, Apr 14, 2009 at 2:53 PM, Alvaro Herrera wrote: > Kynn Jones escribió: > > > Is there a general way to get positive confirmation that a particular > > pg_hba.conf has been re-read upon bouncing the server with > > SHOW hba_file; That's handy. Thanks! Kynn

Re: [GENERAL] 'no pg_hba.conf entry for host "[local]", user "postgres", database "postgres"'...

2009-04-14 Thread Kynn Jones
On Tue, Apr 14, 2009 at 12:22 PM, Tom Lane wrote: > Kynn Jones writes: > > On Mon, Apr 13, 2009 at 4:54 PM, Scott Marlowe >wrote: > >> On Mon, Apr 13, 2009 at 2:01 PM, Kynn Jones wrote: > >>> as the postgres user, I get the error > >>> psql:

Re: [GENERAL] 'no pg_hba.conf entry for host "[local]", user "postgres", database "postgres"'...

2009-04-14 Thread Kynn Jones
On Mon, Apr 13, 2009 at 4:54 PM, Scott Marlowe wrote: > On Mon, Apr 13, 2009 at 2:01 PM, Kynn Jones wrote: > > When I try to run > > % psql > > as the postgres user, I get the error > > psql: FATAL: no pg_hba.conf entry for host "[local]", user "p

[GENERAL] 'no pg_hba.conf entry for host "[local]", user "postgres", database "postgres"'...

2009-04-13 Thread Kynn Jones
When I try to run % psql as the postgres user, I get the error psql: FATAL: no pg_hba.conf entry for host "[local]", user "postgres", database "postgres", SSL off I don't understand this error, since the pg_hba.conf file includes the line: local all all ident sameuser What could explain this

Re: [GENERAL] DBD::Pg`s $dbh->func( "/path/to/file", `lo_import` ) fails silently

2009-03-19 Thread Kynn Jones
On Wed, Mar 18, 2009 at 3:57 PM, Greg Sabino Mullane wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: RIPEMD160 > > > > I'm trying to use Perl's DBD::Pg module to import a file as a large > object. > > For this I'm using the following: > > my $oid = $dbh->func( "/absolute/path/to/file", 'lo_i

[GENERAL] DBD::Pg's $dbh->func( "/path/to/file", 'lo_import' ) fails silently

2009-03-18 Thread Kynn Jones
I'm trying to use Perl's DBD::Pg module to import a file as a large object. For this I'm using the following: my $oid = $dbh->func( "/absolute/path/to/file", 'lo_import' ); When I do this, a new record is added to pg_largeobject, with a proper-looking non-null loid, but the data field remains emp

Re: [GENERAL] Scanning a large binary field

2009-03-15 Thread Kynn Jones
On Sun, Mar 15, 2009 at 5:06 PM, John R Pierce wrote: > Kynn Jones wrote: > >> I have a C program that reads a large binary file, and uses the read >> information plus some user-supplied arguments to generate an in-memory data >> structure that is used during the re

[GENERAL] Scanning a large binary field

2009-03-15 Thread Kynn Jones
I have a C program that reads a large binary file, and uses the read information plus some user-supplied arguments to generate an in-memory data structure that is used during the remainder of the program's execution. I would like to adapt this code so that it gets the original binary data from a P

[GENERAL] How to get the PID associated with a Perl DBI dbh?

2009-03-12 Thread Kynn Jones
Is there a reliable way to find out the (Unix) PID associated with a database handle generated by Perl DBI's database connection? TIA! Kynn

Re: [GENERAL] How to echo statements in sourced file?

2008-12-04 Thread Kynn Jones
Thank you all. From your replies I was able to figure out what I needed: "\set ECHO queries" Kynn On Wed, Dec 3, 2008 at 7:14 PM, Kynn Jones <[EMAIL PROTECTED]> wrote: > Hi. I have a collection of SQL statements stored in a file that I run > periodically via cron. Runni

[GENERAL] How to echo statements in sourced file?

2008-12-03 Thread Kynn Jones
Hi. I have a collection of SQL statements stored in a file that I run periodically via cron. Running this "script" takes a bit too long, even for a cron job, and I would like to profile it. I learned from Andreas Kretschmer (in another thread, in the pgsql-performance list) about the \timing dire

Re: [GENERAL] psql: what's the SQL to compute the ratio of table sizes?

2008-10-17 Thread Kynn Jones
Thanks for all your suggestions! Kynn

[GENERAL] psql: what's the SQL to compute the ratio of table sizes?

2008-10-17 Thread Kynn Jones
Suppose I have two table X and Y and I want to compute the ratio of the number of rows in X and the number of rows in Y. What would be the SQL I could type into a psql session to get this number? This is an example of the recurring problem of performing arithmetic using the result of various calls

Re: [GENERAL] How to select rows that are the max for each subcategory?

2008-09-25 Thread Kynn Jones
Thank you all! Kynn

[GENERAL] How to select rows that are the max for each subcategory?

2008-09-25 Thread Kynn Jones
Suppose I have a table T that has, among its columns, the fields X and Y, where Y is an integer, and multiple rows with the same value of X are possible. I want to select the rows corresponding to the greatest values of Y for each value of X. E.g. suppose that T is X Y Z a 1 eenie a 3 meenie a

[GENERAL] How to create a case-insensitive unique constraint?

2008-09-02 Thread Kynn Jones
Hi! If I try something like ALTER TABLE foo ADD CONSTRAINT foo_unique_xy UNIQUE ( UPPER( x ), UPPER( y ) ); ...I get a syntax error ERROR: syntax error at or near "(" LINE 3: UNIQUE ( UPPER( x ), UPPER( y ) ); Is there a way to do this? TIA! Kynn

[GENERAL] max_fsm_relations question

2008-08-05 Thread Kynn Jones
Hi. I have a database that is created and populated by a Perl script. (FWIW, the size of this database is about 12GB, according to pg_database_size()). If, right after the database is built, I connect to it and manually run VACUUM ANALYZE, I get the warning NOTICE: max_fsm_relations(1000) equa

Re: [GENERAL] limits?

2008-06-23 Thread Kynn Jones
On Mon, Jun 23, 2008 at 2:21 PM, Steve Atkins <[EMAIL PROTECTED]> wrote: > > In real use you're unlikely to hit any limits, theoretical or practical, > but if you start to use a silly number of tables and so on you're likely to > hit performance issues eventually. I'm not sure where that threshold

[GENERAL] limits?

2008-06-23 Thread Kynn Jones
How can I find the limits (if any) on things such as the maximum number of tables, views, indices, columns-per-table, size of database, etc.? (At the moment I'm particularly interested any limits that my exist on the numbers of tables and views that may exist in any one database.) TIA! Kynn

Re: [GENERAL] Easiest way to copy table from one db to another?

2008-06-20 Thread Kynn Jones
On Wed, Jun 18, 2008 at 4:08 PM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > On Wed, Jun 18, 2008 at 1:48 PM, Kynn Jones <[EMAIL PROTECTED]> wrote: > > > > > > What's the simplest way to copy a table from one database to another one > > runni

[GENERAL] Easiest way to copy table from one db to another?

2008-06-18 Thread Kynn Jones
What's the simplest way to copy a table from one database to another one running on the same server? TIA! Kynn

[GENERAL] Advice for "hot-swapping" databases

2008-06-13 Thread Kynn Jones
Hi. I'm trying to automate the updating of a database. This entails creating the new database from scratch (which takes a long time), under a different name, say mydb_tmp, and once this new database is ready, doing a "hot swap", i.e. renaming the existing database to something like mydb_20080613

[GENERAL] pg_restore frozen?

2008-06-04 Thread Kynn Jones
When I try to run pg_restore (as the postgres superuser), it appears to freeze after printing the following: pg_restore -U yours_truly -d somedb /path/to/somedb.dmp pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore: [archiver (db)] Error from TOC entry 24; 1255 365299855 FUNCTION

[GENERAL] GROUP BY, ORDER & LIMIT ?

2008-05-06 Thread Kynn Jones
Suppose table X has two columns: class (TEXT) and size (INT). I want a listing showing the (up to) 5 largest values of "size" for each value of "class" (for some values of "class" the total number of available records may be less than 5). What would be the simplest way to achieve such a listing?

Re: [GENERAL] shared memory/max_locks_per_transaction error

2008-03-17 Thread Kynn Jones
Tom, Alvaro: Thank you much for the clarification. It's "back to the drawing board" for me! Kynn On Mon, Mar 17, 2008 at 10:55 AM, Tom Lane <[EMAIL PROTECTED]> wrote: > "Kynn Jones" <[EMAIL PROTECTED]> writes: > > I'm leaning towards the r

Re: [GENERAL] shared memory/max_locks_per_transaction error

2008-03-17 Thread Kynn Jones
On Fri, Mar 14, 2008 at 7:12 PM, Tom Lane <[EMAIL PROTECTED]> wrote: > "Kynn Jones" <[EMAIL PROTECTED]> writes: > > Initially I didn't know what our max_locks_per_transaction was (nor even > a > > typical value for it), but in light of the proce

Re: [GENERAL] How to silence psql notices, warnings, etc.?

2008-03-17 Thread Kynn Jones
Tom, Albe, Thanks for the client_min_messages pointer; it did the trick. On Sun, Mar 16, 2008 at 2:53 PM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > > If you start postgresql from the pg_ctl command line and it's set to > log to stdout, then continue to use that terminal for psql afterwards, > yo

[GENERAL] UPDATE stalls when run in "batch mode"

2008-03-16 Thread Kynn Jones
I was running an SQL file in psql (via \i) and I noticed that the execution had been stuck at a particular place for a few hours, which was far longer than expected. So I killed the processing of the file (with Ctrl-C), vacuumed everything I could think of and tried again. The same thing happened

[GENERAL] shared memory/max_locks_per_transaction error

2008-03-14 Thread Kynn Jones
I've written a PL/pgSQL function that is supposed to create a whole bunch (~4000) tables: CREATE OR REPLACE FUNCTION create_tables () RETURNS void AS $$ DECLARE _s RECORD; _t TEXT; BEGIN DROP TABLE IF EXISTS base CASCADE; CREATE TABLE base ( /* omit lengthy definition */ ); FOR _s IN SEL

[GENERAL] How to silence psql notices, warnings, etc.?

2008-03-14 Thread Kynn Jones
Hi! How does one silence NOTICE and WARNING messages in psql? I've tried \set QUIET on, \set VERBOSITY terse, and even \o /dev/null, but I still get them! TIA! Kynn

Re: [GENERAL] Trigger to run @ connection time?

2008-03-12 Thread Kynn Jones
On Tue, Mar 11, 2008 at 4:51 PM, Andrej Ricnik-Bay <[EMAIL PROTECTED]> wrote: > On 12/03/2008, Kynn Jones <[EMAIL PROTECTED]> wrote: > Of course I may not have quite > understood how that "this procedure adds useful definitions, > mostly subs, to Perl's ma

Re: [GENERAL] Trigger to run @ connection time?

2008-03-12 Thread Kynn Jones
On Tue, Mar 11, 2008 at 5:28 PM, Tom Lane <[EMAIL PROTECTED]> wrote: > "Kynn Jones" <[EMAIL PROTECTED]> writes: > > If one can set up this insert operation so that it happens automatically > > whenever a new connection is made, I'd like to learn how it

Re: [GENERAL] Trigger to run @ connection time?

2008-03-11 Thread Kynn Jones
On Mon, Mar 10, 2008 at 7:47 PM, Alban Hertroys < [EMAIL PROTECTED]> wrote: > > You can't define triggers on system tables. > Oh, well... :-/ Thanks for the reality check! > If not, is there some other way to set up a trigger that > Oops. I guess a cut-and-paste error in my original message m

Re: [GENERAL] ISO something like "#if 0 ... #endif" for SQL code

2008-03-11 Thread Kynn Jones
On Mon, Mar 10, 2008 at 12:28 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > > Personally I use vim to comment out small blocks. However, this is > rarely required as I break my SQL up into logical chunks in separate > files. I should get into that habit in any case. Thanks for pointing it out.

Re: [GENERAL] ISO something like "#if 0 ... #endif" for SQL code

2008-03-11 Thread Kynn Jones
On Tue, Mar 11, 2008 at 10:10 AM, Gurjeet Singh <[EMAIL PROTECTED]> wrote: > The SQL standard, and Postgres, allow you to nest comments; some > commercial RDBMS' do not provide this, and hence people think it's not > possible in SQL. > Ah! Finally I see what Martin was getting at in his reply.

Re: [GENERAL] ISO something like "#if 0 ... #endif" for SQL code

2008-03-11 Thread Kynn Jones
On Tue, Mar 11, 2008 at 7:17 AM, Sam Mason <[EMAIL PROTECTED]> wrote: > > I'm not quite sure if this would help your use case, but a few editors > allow you to send blocks of text to other processes. For example, under > Emacs I can hit Ctrl+C twice and it will grab the current paragraph > and se

[GENERAL] On defining Perl functions within PLPERL code

2008-03-10 Thread Kynn Jones
In a recent post I mentioned that I had a PLPERL procedure that ...adds useful definitions, mostly subs, to Perl's main package. I thought this claim needs further clarification, since the docs for PLPERL include a warning that may give readers the impression that defining Perl functions within

[GENERAL] Trigger to run @ connection time?

2008-03-10 Thread Kynn Jones
Hi! I want to set up a trigger (somehow) that, whenever someone connects database my_db, will fire and thereby run a stored PLPERL procedure perl_setup() in the new connection's environment. (BTW, this procedure adds useful definitions, mostly subs, to Perl's main package. This needs to be done

[GENERAL] ISO something like "#if 0 ... #endif" for SQL code

2008-03-10 Thread Kynn Jones
Hi! When it comes to programming SQL, my newbie approach is to write my code in a file test.sql, which I test from within psql by using my_db=> \i /some/path/test.sql ...and (once I'm satisfied with the code) copy and paste it to a different file that has the SQL I've written so far for the pr

[GENERAL] "Consider compacting this relation..." ???

2008-02-28 Thread Kynn Jones
I just ran VACUUM ANALYZE and got this warning I've never seen before: WARNING: relation "public.some_big_table" contains more than "max_fsm_pages" pages with useful free space HINT: Consider compacting this relation or increasing the configuration parameter "max_fsm_pages". What does the hint

[GENERAL] How to monitor the progress of a stored procedure?

2008-02-27 Thread Kynn Jones
(Sorry for asking so many questions!) What techniques can one use to monitor the progress of a stored procedure? Specifically, how can I get the procedure to print a progress indicator message to the screen every once in a while? I have a stored procedure that has been running for a very long tim

Re: [GENERAL] How to "paste two tables side-by-side"?

2008-02-27 Thread Kynn Jones
On Wed, Feb 27, 2008 at 7:39 AM, Kynn Jones <[EMAIL PROTECTED]> wrote: > Suppose I have two tables, A and B, with k(A) and k(B) columns > respectively, and let's assume to begin with that they have the same number > of rows r(A) = r(B) = r. > What's the simplest way t

[GENERAL] How to "paste two tables side-by-side"?

2008-02-27 Thread Kynn Jones
Suppose I have two tables, A and B, with k(A) and k(B) columns respectively, and let's assume to begin with that they have the same number of rows r(A) = r(B) = r. What's the simplest way to produce a table C having r rows and k(A) + k(B) columns, and whose i-th row consists of the k(A) columns of

[GENERAL] How to copy tables between databases?

2008-02-26 Thread Kynn Jones
Is there a simple way to copy a table from one database to another without generating an intermediate dump file? TIA! Kynn

Re: [GENERAL] "RETURNS SETOF" function question

2008-02-25 Thread Kynn Jones
On Sun, Feb 24, 2008 at 7:08 PM, Erik Jones <[EMAIL PROTECTED]> wrote: > > There was an article that covered this in the Postgres Online Journal > ( > http://www.postgresonline.com/journal/index.php?/categories/6-pl-programming). > Basically, do this: > > CREATE OR REPLACE FUNCTION foo(text, text

[GENERAL] "RETURNS SETOF" function question

2008-02-24 Thread Kynn Jones
Suppose that stored procedure foo has the signature: foo( text, text ) RETURNS SETOF text Also, I have some table bar, and that column bar.baz is of type text. Now, I'd like to run something like SELECT foo( "frobozz", baz ) FROM bar; If I try this psql complains that I'm trying to execute

Re: [GENERAL] PostgreSQL's hashing function?

2008-02-23 Thread Kynn Jones
On Fri, Feb 22, 2008 at 8:12 PM, Greg Stark <[EMAIL PROTECTED]> wrote: You could use hashtext() which is Postgres's internal hash function. Awesome! > There's some possibility it could change in future versions of Postgres > though. I can live with that, especially if all that changes is the

Re: [GENERAL] Queries w/ "computed" table names? (eval in Pg?)

2008-02-23 Thread Kynn Jones
On Fri, Feb 22, 2008 at 6:51 PM, Steve Atkins <[EMAIL PROTECTED]> wrote: > > On Feb 22, 2008, at 3:40 PM, Kynn Jones wrote: > > > Hi. Suppose I have a database that contains a "meta table" that > > holds the names of other the tables in the database, key

[GENERAL] Queries w/ "computed" table names? (eval in Pg?)

2008-02-22 Thread Kynn Jones
Hi. Suppose I have a database that contains a "meta table" that holds the names of other the tables in the database, keyed by human-readable but longish strings. I would like to write queries that first "compute" the names of some tables (i.e. by looking them up in "meta table"), and after that t

[GENERAL] PostgreSQL's hashing function?

2008-02-22 Thread Kynn Jones
Hi! Does PostgreSQL expose its hash function? I need a fast way to hash a string to a short code using characters in the set [A-Za-z0-9_]. (I'm not sure yet how long this code needs to be, but I think even something as short as length 2 may be enough.) TIA! Kynn

[GENERAL] Vacuous errors in pg_dump ... | pg_restore pipeline

2008-02-20 Thread Kynn Jones
Hi. I've written a Unix shell (zsh) script to streamline the process of duplicating a database. At the heart of this script I have the following pipeline: pg_dump -U $OWNER -Fc $FROM | pg_restore -U $OWNER -d $TO As far as the shell is concerned, this pipeline fails, due to three errors emitt

[GENERAL] Foreign keys and inheritance

2007-11-19 Thread Kynn Jones
I have two classes of objects, A and B, where B is just a special case of A. (I.e., to describe a B-type object I need to specify the same fields as for an A-type object, plus a whole bunch additional fields specific to B alone.) Furthermore, there's a third class T that is in a many-to-one relat

Re: [GENERAL] How to temporarily disable a table's FK constraints?

2007-11-06 Thread Kynn Jones
On 11/5/07, andy <[EMAIL PROTECTED]> wrote: > Hey, I was just thinking about this... instead of disabling the FK's, > what about adding a temp table where you could COPY into, then fire off > a bunch of update's to setup the id fields, etc, etc, then do an Insert > into realtable select * from temp

Re: [GENERAL] How to temporarily disable a table's FK constraints?

2007-11-05 Thread Kynn Jones
On 11/5/07, Erik Jones <[EMAIL PROTECTED]> wrote: > ...see about redefining the foreign key > as being deferrable... Yep, that'll do it. Thanks! kj ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.pos

Re: [GENERAL] How to temporarily disable a table's FK constraints?

2007-11-05 Thread Kynn Jones
On 11/5/07, Erik Jones <[EMAIL PROTECTED]> wrote: > On Nov 5, 2007, at 10:50 AM, Kynn Jones wrote: > > Is there a standard way to disable a table foreign-key constraint > > temporarily? > > > > I thought that this would be a fairly common thing to want to do

[GENERAL] How to temporarily disable a table's FK constraints?

2007-11-05 Thread Kynn Jones
Hi, everyone. Is there a standard way to disable a table foreign-key constraint temporarily? I thought that this would be a fairly common thing to want to do, but I only found this snippet online: -- to disable UPDATE pg_class SET reltriggers=0 WHERE relname = 'your_table'; -- to re-enable UPDA

Re: [GENERAL] Populating large DB from Perl script

2007-11-02 Thread Kynn Jones
> So... not really an answer (other than I used a stored proc) Actually, I'm interested in your solution. Just to make sure I understood what you did: you bulk-populated (i.e. with $dbh->do('COPY...'), $dbh->pg_putline(...), $dbh->pg_endcopy) the referring tables, with their fkey constraints disa

[GENERAL] Populating large DB from Perl script

2007-11-01 Thread Kynn Jones
Hi. This is a recurrent problem that I have not been able to find a good solution for. I have large database that needs to be built from scratch roughly once every month. I use a Perl script to do this. The tables are very large, so I avoid as much as possible using in-memory data structures,

[GENERAL] UNIQUE INDEX and PRIMARY KEY

2007-10-20 Thread Kynn Jones
This is a follow-up to a question I asked earlier. On 10/19/07, Gregory Stark <[EMAIL PROTECTED]> wrote: > What you need is: > > CREATE UNIQUE INDEX foo_uniq_x_y on foo (canonicalize(x,y)); > > > LOCATION: base_yyerror, scan.l:795 OK, now, what if instead of this -> ALTER TABLE foo ADD CONSTRAI

Re: [GENERAL] Order-independent multi-field uniqueness constraint?

2007-10-20 Thread Kynn Jones
On 10/19/07, Gregory Stark <[EMAIL PROTECTED]> wrote: > "Kynn Jones" <[EMAIL PROTECTED]> writes: > > > CREATE OR REPLACE FUNCTION canonicalize( anyelement, anyelement ) > > RETURNS anyarray AS > > $$ > > BEGIN > > IF $1 < $2 THEN R

[GENERAL] Order-independent multi-field uniqueness constraint?

2007-10-19 Thread Kynn Jones
I have a table used to store information about pairs of items. This information is independent of the order of the two items in the pair, so having two records X Y Y X in the table would be redundant. But as far as I can tell, this situation would not violate a uniquen

[GENERAL] How to set config param temporarily?

2007-10-16 Thread Kynn Jones
I'd like to set some config parameter "temporarily"; i.e. so that the new setting is active, say, only during the execution of the next SQL statement. This is the best I've come up with: -- first, save the original setting of the parameter CREATE TEMP TABLE save_config AS SELECT setting FROM pg

[GENERAL] How to view the SQL that Pg actually executes?

2007-10-16 Thread Kynn Jones
I understand that in some cases (e.g. when add_missing_from is true), Pg will modifiy some SQL input before running it. Is there a way to get Pg to print out the SQL it will actually execute? Is it possible to get to *just* print out this SQL without actually executing it? TIA! kj

Re: [GENERAL] One database vs. hundreds?

2007-08-28 Thread Kynn Jones
Thank you very much for your replies. Given the differences in the opinions expressed, I thought I would describe the database briefly. The purpose of the database is basically translation of terms. Imagine a collection of disjoint sets A, B, C, ... Now imagine that for each element of a set mul

[GENERAL] One database vs. hundreds?

2007-08-28 Thread Kynn Jones
I'm hoping to get some advice on a design question I'm grappling with. I have a database now that in many respects may be regarded as an collection of a few hundred much smaller "parallel databases", all having the same schema. What I mean by this is that, as far as the intended use of this parti

Re: [GENERAL] ISO TESTS for a Pg lexer+parser

2007-07-19 Thread Kynn Jones
On 7/6/07, Stephen Frost <[EMAIL PROTECTED]> wrote: * Kynn Jones ([EMAIL PROTECTED]) wrote: > Hi! I am in the process of writing a PostgreSQL lexer/parser in Perl, > because everything else I've found in this area is too buggy. I'm > basing this lexer/parser on the

[GENERAL] ISO TESTS for a Pg lexer+parser

2007-07-06 Thread Kynn Jones
Hi! I am in the process of writing a PostgreSQL lexer/parser in Perl, because everything else I've found in this area is too buggy. I'm basing this lexer/parser on the lexer and parser encoded respectively in scan.l and gram.y under src/backend/parser. I'm looking for a solid collection of test

Re: [GENERAL] Q re installing Pg on OS X?

2007-04-15 Thread Kynn Jones
OK, I found the answer to my question about the "roles" error. Still, it would be nice to have more up-to-date instructions on how to install PostgreSQL on OS X. Any pointers would be much appreciated! TIA! kj On 4/15/07, Kynn Jones <[EMAIL PROTECTED]> wrote: I

  1   2   >