Re: [SQL] Query from shell

2006-04-06 Thread Owen Jacobson
Judith wrote: >Hi every body, somebody can show me hot to execute a > query from a shell echo QUERY HERE | psql databasename Or, if you want to run several queries, run psql and run your queries there. ---(end of broadcast)--- TIP 2: Don'

Re: [SQL] pgcrypto-crypt

2006-04-06 Thread Owen Jacobson
Guy Fraser wrote: > On Thu, 2006-06-04 at 13:53 +0530, AKHILESH GUPTA wrote: > > dear all, > > i want to encrypt and decrypt one of the fields in my table (i.e- > > password field) > > i have searched and with the help of pgcrypto package, using function > > "crypt", i am able to encrypt my data,

Re: [SQL] Bitfields always atomic? Other way to store attributes?

2006-03-28 Thread Owen Jacobson
TJ O'Donnell wrote: > > If I have two threads modifying the same "bit" field: > > thread1=> update table set bf=bf | '01000' > > thread2=> update table set bf=bf | '1' > > Will this operation always be safe (e.g. result in bf='11000')? Or > > Won't this always result in bf='11xxx', d

Re: [SQL] OUT parameter

2006-03-23 Thread Owen Jacobson
Tom Lane wrote: > "Owen Jacobson" <[EMAIL PROTECTED]> writes: > > I'd say there's no problem with this, PROVIDED you can ensure you'll > > never abort before completing the computation. > > Not really an issue in Postgres: we do not suppor

Re: [SQL] OUT parameter

2006-03-22 Thread Owen Jacobson
Daniel Caune wrote: > Is there any suggestion against using OUT parameter for local > calculation such as using a local variable? > > CREATE OR REPLACE FUNCTION foo(a IN int, >b1 OUT int, >b2 OUT int) > AS $$ > BEGIN > FOR (...) LO

Re: [SQL] Using a parameter in Interval

2006-03-21 Thread Owen Jacobson
Here's one I used to convert an int to an interval in another project: CREATE OR REPLACE FUNCTION to_interval (sec INTEGER) RETURNS INTERVAL AS $$ BEGIN RETURN (sec || ' seconds')::INTERVAL; END; $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; select to_interval (5); to_interval - 00:00:0

Re: [SQL] plpqsql and RETURN NEXT requires a LOOP?

2006-03-21 Thread Owen Jacobson
In general, to do anything useful with RETURN NEXT you need a loop. However, it doesn't need to be a loop over another resultset: you can do a computation in a loop, returning values as you go. Excuse the outlook-ism. -Owen -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PRO

Re: [SQL] After Trigger assignment to NEW

2006-02-24 Thread Owen Jacobson
Achilleus Mantzios wrote: > O Tom Lane έγραψε στις Feb 24, 2006 : > > > By definition, an AFTER trigger is too late to change what was > > stored. Use a BEFORE trigger. > > Too late if someone wants to store it. > I wanna store the intented original values, thats why i use > AFTER trigger. > Bu

Re: [SQL] Question about index scan vs seq scan when using count()

2006-02-23 Thread Owen Jacobson
Kashmira Patel wrote: > I did do an EXPLAIN ANALYZE as well, it also showed a > sequential scan. The table has about 600+ rows, with around 6 of them > matching the given id. Wouldn't an index scan be faster in this case? Not necessarily. It's entirely possible, if your rows are small, that 600

Re: [SQL] Update in all tables

2006-02-22 Thread Owen Jacobson
Scott Marlowe wrote: > On Wed, 2006-02-22 at 15:13, Andrew Sullivan wrote: > > > No, sorry. While we're at it, though, if you have the same field in > > several tables, it's a good sign that your database is badly > > normalised. You shouldn't have to update more than one table (which > > is why

Re: [SQL] Given 02-01-2006 to 02-28-2006, output all days.

2006-02-17 Thread Owen Jacobson
-Owen -Original Message- From: Henry Ortega [mailto:[EMAIL PROTECTED] Sent: Friday, February 17, 2006 2:06 PM To: Owen Jacobson Subject: Re: [SQL] Given 02-01-2006 to 02-28-2006, output all days. This sounds good. I don't have plpgsql loaded though. I am trying to load plpgsql and it's g

Re: [SQL] Given 02-01-2006 to 02-28-2006, output all days.

2006-02-17 Thread Owen Jacobson
Henry Ortega wrote: (question about set of all days between two dates) I don't know of a builtin way to do it off the top of my head, but it's a pretty simple function to write: create function days (start date, finish date) returns setof date as $$ declare curdate date; begin curdate := st

Re: [SQL] Using EXPLAIN-ANALYZE

2006-02-16 Thread Owen Jacobson
Kashmira Patel wrote: > So I would have to put in lots of rows of data in the table > before using the explain command? No, but PostgreSQL's query planner may take a different approach for a small table than a large one. The statistics used are generated during VACUUM ANALYZE/VACUUM FULL ope

Re: [SQL] How to force PostgreSQL using an index

2006-02-15 Thread Owen Jacobson
Daniel Caune wrote: > > Andrew Sullivan wrote: > > > On Wed, Feb 15, 2006 at 04:58:54PM -0500, Daniel Caune wrote: > > > > > > > > Is there a way to force PostgreSQL using an index for a SELECT > > > statement? > > > > Your best bet is to do > > > > set enable_indexscan=false; > > > > and then

Re: [SQL] How to force PostgreSQL using an index

2006-02-15 Thread Owen Jacobson
SET SESSION enable_seqscan TO OFF could be interpreted as a strong hint to the server that you want it to use indexes. It's not completely mandatory (the server WILL still do a sequential scan if it has to) but postgresql will strongly prefer index scans. You may also have some luck twiddling

Re: [SQL] alter table

2006-02-15 Thread Owen Jacobson
Maciej Piekielniak wrote: > > Hello Owen, > > Wednesday, February 15, 2006, 8:56:05 PM, you wrote: > >> ALTER TABLE proc MODIFY name varchar(64) DEFAULT '' NOT NULL; > > OJ> Not under 7.4. > > Hmm, maybe postgres can copy constraints and properties in > "create table .. as select"? What is it

Re: [SQL] alter table

2006-02-15 Thread Owen Jacobson
Maciej Piekielniak wrote: > > Wednesday, February 15, 2006, 8:31:17 PM, you wrote: > OJ> Note that prior to 8.0 PostgreSQL does not support > multiple ALTER actions in a single query. To get an > equivalent effect, wrap separate ALTER TABLE queries in a transaction: > > OJ> BEGIN; > OJ> alter

Re: [SQL] alter table

2006-02-15 Thread Owen Jacobson
Andreas Kretschmer wrote: > > Maciej Piekielniak <[EMAIL PROTECTED]> schrieb: > > > Hello Andreas, > > > > Wednesday, February 15, 2006, 7:54:28 PM, you wrote: > > AK> test=# alter table xyz alter column id set default > nextval('xyz_seq'), alter column foo set default ''; > > > > PGAdmin-SQL:

Re: [SQL] Modifying postgresql.org file

2006-02-15 Thread Owen Jacobson
Andrew Sullivan wrote: > > On Wed, Feb 15, 2006 at 08:15:46AM -0800, Ken Hill wrote: > > It has been suggested to me to increase my work_mem to make queries > > preform faster. I believe I do this in the 'postgresql.org' file. I > > seem to have two of these files: > > > > /etc/postgresql/7.4/ma

Re: [SQL] Problems with distinct

2006-02-13 Thread Owen Jacobson
Andreas Joseph Krogh wrote: > Any idea why this works: > > SELECT distinct(g.groupname), g.id, g.p_id FROM onp_group g, > onp_group g2 > WHERE g.id IN(SELECT g2.id UNION SELECT group_id FROM > onp_group_children WHERE > child_id = g2.id) > AND g2.id IN(1,2,109,105, 112); > > And not this: >

Re: [SQL] Non Matching Records in Two Tables

2006-02-08 Thread Owen Jacobson
Ken Hill wrote: > I need some help with a bit of SQL. I have two tables. I want > to find records in one table that don't match records in another > table based on a common column in the two tables. Both tables > have a column named 'key100'. I was trying something like: > > SELECT count(*) > FRO

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > Markus Schaber wrote: > > > Bryce Nesbitt wrote: > > > > > >> BEGIN; > >> DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > >> WHERE reservation_id IN > >> (select reservation_id from reservations where date > magic) > >> ); > >> DELETE F

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > Owen Jacobson wrote: > > > BEGIN; > > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > > WHERE reservation_id = reservation_to_delete); > > DELETE FROM isuse WHERE reservation_id = reservation_to_delete; > &

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Owen Jacobson wrote: > BEGIN; > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > WHERE reservation_id = reservation_to_delete); > DELETE FROM isuse WHERE reservation_id = reservation_to_delete; > DELETE FROM reservations WHERE reservation_id = > res

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > When I delete a record from a certain table, I need to delete a > (possibly) attached note as well. How can I do this with > postgres? The > tables are like this: > > reservation > reservation_id > stuff... > > isuse > issue_id > reservation_id r

Re: [SQL] Does PostgreSQL support job?

2006-02-01 Thread Owen Jacobson
Daniel Caune wrote: > Hi, > > I try to find in the documentation whether PostgreSQL supports job, > but I miserably failed. Does PostgreSQL support job? If not, what > is the mechanism mostly adopted by PostgreSQL administrators for > running jobs against PostgreSQL? I was thinking about usi

Re: [SQL] psql in the command line

2006-01-25 Thread Owen Jacobson
Alvaro Herrera wrote: > [EMAIL PROTECTED] wrote: > > > test:/opt/pgsql# echo "copy test from '/data/log/bla';" | psql logdb > > COPY > > > > But when I try to execute it as root user I get the following error: > > > > [est/data/log] su - postgres -c "echo 'copy test from > /data/log/bla;'| > >

Re: [SQL] pgadmin

2006-01-23 Thread Owen Jacobson
Mark Fenbers wrote: > I'm having trouble with installing pgadmin. If this is not the > apporpriate group for seeking help with this, please excuse > me and tell > the correct one. I have not found anything else more appropriate. > > 'make' for pgadmin fails, I think it is because I don't hav

Re: [SQL] best way for constants in the database

2006-01-16 Thread Owen Jacobson
chester c young wrote: > anybody have a good way to impliment constants in the database? > > using an immutable pgpgsql function, constant_name() - works, but not > necessarily very efficient. A function declared IMMUTABLE should be efficient enough; it'll usually be evaluated once per query at

Re: [SQL] Multi-row update w. plpgsql function

2005-12-13 Thread Owen Jacobson
Daniel Hertz wrote: > Given a set of checkbox values that are submitted through an > html form, > how do you loop through the submitted values to update more > than one row > in a table? > > Imagine a table called 'message_table': > > mid | message | status > +-+--- > 1 |

Re: [SQL] how to replace

2005-09-08 Thread Owen Jacobson
Michael Höller wrote: > Hello, > > I initially thought this is simple.. I want to relpace a character to > nothing. Eg. relace "B" to "" -> ABCD to ACD. > > All me approches vaild but I am sure that I have seen it already and > think it was not tricky.. > > Can someone please help me ? From t

Re: [SQL] Turn off auto-commit

2005-09-02 Thread Owen Jacobson
You can turn off autocommit by explicitly starting a transaction (eg. with BEGIN; in psql or by turning off autocommit through ODBC).  Statements inside the transaction will not have their own, automatically-commited transactions.   HTH, Owen -Original Message-From: [EMAIL PROT

Re: [SQL] [HACKERS] ALTER TABLE ( smallinto -> boolean ) ...

2005-09-01 Thread Owen Jacobson
Marc G. Fournier wrote: > Moved off of -hackers, since its long gotten out of that realm :) > > On Thu, 1 Sep 2005, Tom Lane wrote: > > > "Marc G. Fournier" <[EMAIL PROTECTED]> writes: > >> On Mon, 29 Aug 2005, Tom Lane wrote: > >>> No, because there's no built-in cast from smallint to bool. > >

Re: [SQL] What libraries need to be included in C program for encrypt and decrypt functions?

2005-08-16 Thread Owen Jacobson
As I mentioned in email, the function "encrypt" exposed by libcrypt (the -lcrypt part of your command line) has nothing to do with the "encrypt" function available in pgcrypto.sql, which You Cannot Call From C.  You have to embed calls to it inside an SQL query like   INSERT INTO some_table

Re: [SQL] SQL Newbie

2005-08-12 Thread Owen Jacobson
Nick Stone wrote: > Hope this helps > > SELECT > * > FROM > speed_history as outside etc.. > WHERE > (speed = ( > SELECT > speed > FROM > speed_history as inside etc.. > WHERE >

Re: [SQL] Fwd: How to encrypt a column

2005-08-11 Thread Owen Jacobson
Jeff Lu wrote: > Owen Jacobson <[EMAIL PROTECTED]> wrote: >> Jeff Lu wrote: >> >>> Hi, >>> >>> I'm interested in encrypting an column in table. Are there any >>> example using "C" to create the encrypted column, inserting an

Re: [SQL] Fwd: How to encrypt a column

2005-08-11 Thread Owen Jacobson
Jeff Lu wrote: > Hi, > > I'm interested in encrypting an column in table. Are there any > example using "C" to create the encrypted column, inserting and > retreiving data to/from it? > > the table is: > CREATE TABLE mytable ( > id SERIAL PRIMARY KEY, > crypted_content BYTEA > ); > > I

Re: **SPAM** [SQL] Faster count(*)?

2005-08-10 Thread Owen Jacobson
Tom Lane wrote: > [EMAIL PROTECTED] writes: > > I believe running count(*) means fulltable scan, and there's no way > > to do it without it. But what about some "intermediate" table, with > > the necessary counts? > > There's a fairly complete discussion in the PG list archives of a > reasonably-e

[SQL] Faster count(*)?

2005-08-09 Thread Owen Jacobson
Salve. I understand from various web searches and so on that PostgreSQL's MVCC mechanism makes it very hard to use indices or table metadata to optimise count(*). Is there a better way to guess the "approximate size" of a table? I'm trying to write a trigger that fires on insert and performs som