Re: [SQL] simple (?) join

2009-09-25 Thread Claus Guttesen
> I have two tables > > create table orders ( > o_id serial primary key > ... > ); > > create table orders_log ( > ol_id serial primary key, > o_id int4 not null references orders(o_id), > ol_timestamp timestamp, > ol_user, > ); > > How can I select all from orders and the last (latest) entry from

Re: [SQL] Convert text from UTF8 to ASCII

2009-03-11 Thread Claus Guttesen
> I store content of an .txt file in a text column in the database. > > server_encoding is UTF8. What does 'psql -l' say? -- regards Claus When lenity and cruelty play for a kingdom, the gentler gamester is the soonest winner. Shakespeare -- Sent via pgsql-sql mailing list (pgsql-sql@postgre

Re: [SQL] seemingly slow for-loop in plpgsql

2008-09-03 Thread Claus Guttesen
> Why in the world are you using a for-loop for this at all? It would be > tremendously faster as a single SQL command: > > update duplicates set hashcode = rtrim(hashcode, E'\n') where > length(hashcode) = 33; Thank you. I was "caught" in the plpgsql-lane. This is of course much simpler and muc

[SQL] seemingly slow for-loop in plpgsql

2008-09-02 Thread Claus Guttesen
Hi. I have a table with a hashcode-field which is a md5-checksum of a file. I updated all null-entries using a rails-script by calling '/sbin/md5 -q' (on FreeBSD). When all null-entries were updated I found out that '\n' was added to the md5-checksum. :-) So I wanted to update the table using plp

Re: [SQL] query: last N price for each product?

2008-07-04 Thread Claus Guttesen
> The query for "latest price for each product" goes like this (which I > can grasp quite easily): > > SELECT * FROM price p1 > WHERE ctime=(SELECT MAX(ctime) FROM price p2 WHERE > p1.product_id=p2.product_id) > > or: > > SELECT * FROM price p1 > WHERE NOT EXISTS (SELECT * FROM price p2 WHERE

Re: [SQL] dbmirror - migration to 8.3 from 7.4

2008-05-07 Thread Claus Guttesen
>> The way i find the primary key of a table is: >>SELECT indkey FROM pg_index WHERE indisprimary='t' AND >> indrelid=TABLEOID; >> i noticed that some columns have been added to pg_index : indisvalid, >> indcheckxmin, indisready,indoption >> Should i include any of them (e.g. indisvalid)

Re: [SQL] dbmirror - migration to 8.3 from 7.4

2008-05-07 Thread Claus Guttesen
> we have been running our own heavily modified/enhanced version of dbmirror, > running on 7.4 for some years, > and now it is the time to upgrade to 8.3. > > The way i find the primary key of a table is: >SELECT indkey FROM pg_index WHERE indisprimary='t' AND > indrelid=TABLEOID; > i not

Re: [SQL] Setting high performance on huge server

2007-04-04 Thread Claus Guttesen
How do I increase my performance knowing that my server is a huge server. Here some parameters I suppose are important on this settings: "shared_buffers";"8000kB";"Sets the number of shared memory buffers used by the server." "max_connections";"100";"Sets the maximum number of concurrent connecti

Re: [SQL] select vs. select count

2007-03-30 Thread Claus Guttesen
> select order_id from > (select o.order_id from orders o join order_lines ol using (order_id) > where o.time > '2006-01-01T00:00' and o.time < '2007-01-01T00:00' > and (ol.item_id = 10 or ol.item_id = 11 or ol.item_id = 12) group by > o.order_id) as prints > inner join > (select ho.order_

Re: [SQL] select vs. select count

2007-03-27 Thread Claus Guttesen
Forgot to mention that this is on postgresql 7.4.14 and FreeBSD 6.2. regards Claus Hi. I'm performing the following query to get all items sold in 2006 which are in category prints or gifts, but not in extra: select order_id from (select o.order_id from orders o join order_lines ol using (or

[SQL] select vs. select count

2007-03-27 Thread Claus Guttesen
Hi. I'm performing the following query to get all items sold in 2006 which are in category prints or gifts, but not in extra: select order_id from (select o.order_id from orders o join order_lines ol using (order_id) where o.time > '2006-01-01T00:00' and o.time < '2007-01-01T00:00' and (ol.ite

Re: [SQL] ERROR: invalid byte sequence for encoding "UTF8": 0x92

2007-03-20 Thread Claus Guttesen
I am using postgres 8.2.3. I have recently converted my database from sql-ascii to UTF8. I have a portal which calls a perl program to insert the data into the database. While inserting, I am getting an error message DBD::Pg::st execute failed: ERROR: invalid byte sequence for encoding