Re: [GENERAL] From select to delete

2011-10-30 Thread Alexander Farber
I've got another great advice to use DELETE ... USING instead of DELETE ... (SUB-SELECT), so my procedure looks now like this (for archive): create or replace function pref_delete_user(_id varchar, _reason varchar) returns void as $BODY$ begin c

[GENERAL] Adding 1 week to a timestamp, which can be NULL or expired

2011-11-20 Thread Alexander Farber
Hello, I'm trying to add 1 week "VIP-status" to all users in a table: update pref_users set vip = max(vip, now()) + interval '1 week'; but max() doesn't work with timestamps. Is there maybe still a way to solve it with a one-liner? Thank you Alex -- Sent via pgsql-general mailing list (pg

[GENERAL] Verifying a timestamp is null or in the past

2011-12-29 Thread Alexander Farber
Hello fellow postgres users, in my game using PostgreSQL 8.4.9 players can purchase a VIP ("very important person") status: # \d pref_users; Table "public.pref_users" Column |Type | Modifiers +-+---

Re: [GENERAL] Verifying a timestamp is null or in the past

2011-12-29 Thread Alexander Farber
Thank you Andreas - now that one case works ok, On Thu, Dec 29, 2011 at 7:44 PM, Andreas Kretschmer wrote: > Try "if (not coalesce(has_vip, false)) then ..." but the other case not: # create or replace function pref_move_week(_from varchar, _to varchar) returns void as $BODY$

Re: [GENERAL] Verifying a timestamp is null or in the past

2011-12-30 Thread Alexander Farber
Hello again, please 1 more question: can I have a SELECT statement inside of an IF-conditional? The doc http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html does not list such an example. I'm asking, because I'd like to get rid of the has_vip variable in my rewritten procedu

Re: [GENERAL] Verifying a timestamp is null or in the past

2011-12-30 Thread Alexander Farber
Awesome advices here. Thank you and happy new year. On Fri, Dec 30, 2011 at 2:07 PM, Alban Hertroys wrote: > select 1 from pref_users where id=_from and vip > current_timestamp + > interval '1 week'; > > if not found then >    return; > end if; > > "found" is a special pl/psql keyword that tel

[GENERAL] join and having clause

2011-12-30 Thread Alexander Farber
Hello, I have an 8.4.9 table, where users can assess other users (i.e. "nice" vs. "not nice"): # \d pref_rep Table "public.pref_rep" Column |Type | Modifiers +-+

Re: [GENERAL] Verifying a timestamp is null or in the past

2011-12-30 Thread Alexander Farber
Hello again, > On Fri, Dec 30, 2011 at 2:07 PM, Alban Hertroys wrote: >> select 1 from pref_users where id=_from and vip > current_timestamp + >> interval '1 week'; >> >> if not found then >>    return; >> end if; >> unfortunately I get the error in PostgreSQL 8.4.9: # select pref_move_week('D

Re: [GENERAL] Verifying a timestamp is null or in the past

2011-12-30 Thread Alexander Farber
Is it because my procedure is declared as "void"? -- 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] Verifying a timestamp is null or in the past

2012-01-01 Thread Alexander Farber
Hello Ray and others, On Sat, Dec 31, 2011 at 10:26 AM, Raymond O'Donnell wrote: >> # select pref_move_week('DE16290', 'DE1'); >> ERROR:  query has no destination for result data >> HINT:  If you want to discard the results of a SELECT, use PERFORM instead. >> CONTEXT:  PL/pgSQL function "pref_mo

[GENERAL] Appending a newline to a column value - in a psql cronjob

2012-01-13 Thread Alexander Farber
Hello! I'm using PostgreSQL 8.4.9 on CentOS 6.2 and with bash. The following cronjob works well for me (trying to send a mail to myself - for moderation): 6 6 * * * psql -c "select 'http://mysite/user.php?id=' ||id, about from pref_rep where length(about) > 1 and la

[GENERAL] Counting different strings (OK%, FB%) in same table, grouped by week number

2012-02-22 Thread Alexander Farber
Hello, I have a table holding week numbers (as strings) and user ids starting with OK, VK, FB, GG, MR, DE (coming through diff. soc. networks to my site): afarber@www:~> psql psql (8.4.9) Type "help" for help. pref=> select * from pref_money; id| money | yw ---

Re: [GENERAL] Counting different strings (OK%, FB%) in same table, grouped by week number

2012-02-22 Thread Alexander Farber
Thank you David - On Wed, Feb 22, 2012 at 9:56 PM, David Johnston wrote: > SELECT SUM(CASE WHEN id ~ '^FB' THEN 1 ELSE 0 END) AS fb_cnt, repeat for each > known type (and I generally code one for unknown as well). > > Depending of your use case building out the non-column version and pushing it

[GENERAL] Which data type to use for UTF8 JSON and perl/PHP: varchar, text or bytea?

2012-04-26 Thread Alexander Farber
Hello, I run a small card game with PostgreSQL 8.4.11 on CentOS 6 at https://apps.facebook.com/video-preferans/ List of databases Name| Owner | Encoding | Collation |Ctype| Access privileges ---+--+--+-+

Re: [GENERAL] Which data type to use for UTF8 JSON and perl/PHP: varchar, text or bytea?

2012-04-26 Thread Alexander Farber
Hello, On Thu, Apr 26, 2012 at 10:11 PM, Merlin Moncure wrote: >> Does anybody have an advice on what data type >> to use best for such a JSON "string"? >> >> Should I take varchar, text or bytea. >> >> And for the latter - how to handle it in Perl >> if I currently use DBI and DBD::Pg? >> >> For

[GENERAL] How to add "on delete cascade" constraints

2012-04-27 Thread Alexander Farber
Hello, in 8.4.9 is it please possible to add "on delete cascades" to the both foreign keys in the following table w/o dropping the table? # \d pref_scores Table "public.pref_scores" Column | Type | Modifiers -+---+--- id | char

Re: [GENERAL] How to add "on delete cascade" constraints

2012-04-27 Thread Alexander Farber
So it's not a problem to drop and recreate the FOREIGN KEYs? And can I use START TRANSACTION while doing it? On Fri, Apr 27, 2012 at 9:30 PM, Raymond O'Donnell wrote: > On 27/04/2012 19:59, Alexander Farber wrote: >> in 8.4.9 is it please possible to add "on delete

Re: [GENERAL] How to add "on delete cascade" constraints

2012-04-27 Thread Alexander Farber
Thank you - this has worked perfectly On Fri, Apr 27, 2012 at 10:18 PM, Richard Broersma wrote: > You could, but you don't need to since you can do all of this is one > statement: > > ALTER TABLE public.pref_scores > DROP CONSTRAINT pref_scores_gid_fkey, > ADD CONSTRAINT pref_scores_gid_fkey >  

[GENERAL] Lock out PostgreSQL users for maintenance

2012-05-11 Thread Alexander Farber
Hello, In PostgreSQL 8.4.9 with pgbouncer 1.3.4 in pool_mode = session (but some users connect to the database directly) - when I login as "super user" with psql -U postgres -W postgres What is the command please to disconnect all "normal users" and prevent them from connecting again while I

[GENERAL] 8.2.6 -> 8.1.11: syntax error at or near "OWNED BY"

2008-12-10 Thread Alexander Farber
Hello, I've pg_dump'ed a database from PostgreSQL 8.2.6 / openSUSE 10.3 and now trying to load it as a "postgres" user at 8.1.1 / CentOS 5.2 and get numerous errors like: CREATE TABLE ALTER TABLE CREATE SEQUENCE ALTER TABLE psql:denkwerk.sql:1156: ERROR: syntax error at or near "OWNED" at charac

Re: [GENERAL] 8.2.6 -> 8.1.11: syntax error at or near "OWNED BY"

2008-12-10 Thread Alexander Farber
Thank you for replies, I've decided to upgrade by adding http://yum.pgsqlrpms.org/ to the yum config at my CentOS server -- 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] 8.2.6 -> 8.1.11: syntax error at or near "OWNED BY"

2008-12-10 Thread Alexander Farber
Hello, On Wed, Dec 10, 2008 at 3:49 PM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > We run pgsql 8.3 on Centos 5.2 and are VERY happy with the PGDG rpms on it. > thanks for the confirmation Scott. I have installed PGDG with pgsql 8.2 at my CentOS 5.2 server and it seems to work now. I hope any upd

[GENERAL] Rotating WAL files

2009-02-24 Thread Alexander Farber
Hello, I've just read about WAL and tried to set these 2 commands for my test database (which is doing nothing 99% of time): archive_command = 'cp -v %p /var/lib/pgsql/data/archive/%f' archive_timeout = 300 # force a logfile segment switch after this

[GENERAL] Log SQL code before executing it

2009-03-06 Thread Alexander Farber
Dear PgSQL users, is there please a way to display the executed SQL code? I'm using phpBB 3.0.4 / PostgreSQL 8.2.6 / PHP 5.2.5 / OpenBSD 4.3 to develop a card game in Flash / C / Perl (at http://preferans.de ) and would like to log each game round by simply posting and replying in one of the phpB

[GENERAL] convert(... using windows_1251_to_utf8) - works on cli, but not in a c prog.

2006-12-23 Thread Alexander Farber
Hello, I'm programming a small Flash game with PostgreSQL 8.1.4 and phpBB serving as backend. The data in the database is in windows_1251 encoding. For my game I have to convert it into utf8, and at the command prompt it seems to work (I recon this because 7 win1251 chars seem to produce 14 utf8

Re: [GENERAL] convert(... using windows_1251_to_utf8) - works on cli, but not in a c prog.

2006-12-23 Thread Alexander Farber
I started to prepare a test case and realized I had a bug. So convert() works for me, sorry for my previous message! Regards Alex -- http://preferans.de ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [GENERAL] convert(... using windows_1251_to_utf8) - works on cli, but not in a c prog.

2006-12-28 Thread Alexander Farber
Hello Alvaro, On 12/24/06, Alvaro Herrera <[EMAIL PROTECTED]> wrote: Alexander Farber wrote: > I started to prepare a test case and realized I had a bug. > So convert() works for me, sorry for my previous message! In any case, it's probably saner if you SET client_encoding at

[GENERAL] Knowing the length(convert(username using windows_1251_to_utf8))

2007-01-11 Thread Alexander Farber
Hello PostgreSQL users! I have this data stored in WIN1251 encoding, which is being fetched by a libpq application I'm developing: phpbb=> show client_encoding; - WIN1251 (1 row) phpbb=> \d phpbb_users; username | character varying(25) | not null default '

Re: [GENERAL] Knowing the length(convert(username using windows_1251_to_utf8))

2007-01-11 Thread Alexander Farber
And additional question please: Can I still be sure that the data returned in the convert(username using windows_1251_to_utf8) column will be 0-terminated or should I fetch the data length using PQgetlength and maintain that value in my C-program? Thank you Alex On 1/11/07, Alexander Farber

Re: [GENERAL] Knowing the length(convert(username using windows_1251_to_utf8))

2007-01-11 Thread Alexander Farber
Hi Martijn, On 1/11/07, Martijn van Oosterhout wrote: If you need the string in UTF-8, why not just set the "client_encoding" to "utf8" and then the server will only send you strings in utf8, not conversion necessary. actually you are right, because I need all my data in UTF8 anyway (for a we

[GENERAL] Basic questions about PQprepare()

2006-01-27 Thread Alexander Farber
Hello, I'm trying to write an Apache 1.3.29 module connecting to PostgreSQL 8.1.0 on OpenBSD -current and have few probably simple questions: When an Apache child is initialized, I'd like to establish connection to the database and to prepare 2 queries. And then later in the repeating response ph

Re: [GENERAL] Basic questions about PQprepare()

2006-01-28 Thread Alexander Farber
t the fastest method?) Regards Alex On 1/28/06, Tom Lane <[EMAIL PROTECTED]> wrote: > Alexander Farber <[EMAIL PROTECTED]> writes: > > 4) How do I set the last PQprepare argument, the const Oid *paramTypes? > > You'd need to look up the OIDs of the parameter types. I

[GENERAL] How to change the default database for a user

2006-01-30 Thread Alexander Farber
Hello, I've created a user and a database both wrongly named "phpbb". After that I have renamed both to "punbb" using "ALTER DATABASE" and "ALTER USER". Now everything works fine, except I always have to specify the database when connecting (both using psql or the PQconnectdb() from my C-program):

Re: [GENERAL] How to change the default database for a user

2006-01-30 Thread Alexander Farber
Hi, On 1/30/06, Doug McNaught <[EMAIL PROTECTED]> wrote: > Alexander Farber <[EMAIL PROTECTED]> writes: > > h754814:afarber {103} psql -U punbb > > psql: FATAL: database "phpbb" does not exist > > psql uses your Unix username as the default dat

Re: [GENERAL] How to change the default database for a user

2006-01-30 Thread Alexander Farber
Argh, I had "phpbb" in my env ( ~/.login) too: setenv PGDATA /var/postgresql/data setenv PGDATABASE phpbb setenv PGHOST /var/www/tmp setenv PGUSER phpbb Now everything makes sense (I was thinking about some kind of system table for default databases). Sorry an

[GENERAL] libpq: bind message supplies 2 parameters, but prepared statement requires 1

2006-07-02 Thread Alexander Farber
Hello, these 2 statements work fine for me on the psql-prompt: punbb=> select id, username, md5('deadbeef' || password) from users where id = 7; id | username | md5 +--+-- 7 | Alex | b962415469222eeb31e739c3afbc8a4a (1 row) punbb=>

[GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
Hello, in my application I'm trying to authenticate users against a table called "users". The integer column "id" should match, but also an md5 hash of the "password" column (salted with a string) should match. My authentication function (written in C, using libpq) should return a "username" (is

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
from users where id = 4; QUERY PLAN -- Index Scan using users_pkey on users (cost=0.00..5.95 rows=1 width=156) Index Cond: (id = 4) (2 rows) Regards Alex On 7/3/06, Martijn van Oosterhout wrote: On Mon, Jul 03, 2006 at 03:13:15P

Re: [GENERAL] Optimizing query: select ... where id = 4 and md5(...) = '...'

2006-07-03 Thread Alexander Farber
Hi Alban, On 7/3/06, Alban Hertroys <[EMAIL PROTECTED]> wrote: Alexander Farber wrote: > punbb=> select username, md5('deadbeef' || password) from users where id > = 4; > username | md5 > --+-- > Vasja

[GENERAL] select * from users where user_id NOT in (select ban_userid from banlist)

2006-08-17 Thread Alexander Farber
Hello, I have this strange problem that the following statement works: phpbb=> select user_id, username from phpbb_users phpbb-> where user_id in (select ban_userid from phpbb_banlist); user_id | username -+-- 3 | La-Li (1 row) But the negative one returns nothing: phpb

Re: [GENERAL] select * from users where user_id NOT in (select

2006-08-18 Thread Alexander Farber
Hello, thank you and sorry for asking a FAQ. I've fixed my problem now by: select user_id, username from phpbb_users where user_id not in (select ban_userid from phpbb_banlist where ban_userid is not null); but still your explanation feels illogical to me even though I know you're right... On

[GENERAL] undefined reference to `PQprepare' with postgresql-dev 7.4.7-6sarge2

2006-08-24 Thread Alexander Farber
Hello, I'm trying to compile a libpq program under Debian 3.1r2 with these packages installed: $ dpkg -l | grep postgres ii postgresql 7.4.7-6sarge2 object-relational SQL database management sy ii postgresql-cli 7.4.7-6sarge2 front-end programs for PostgreSQL ii postgresql-con 7.4.7-6sa

Re: [GENERAL] undefined reference to `PQprepare' with postgresql-dev 7.4.7-6sarge2

2006-08-24 Thread Alexander Farber
bpq-program, to detect an older PostgreSQL version? The headers /usr/include/postgresql/libpq-fe.h and /usr/include/postgresql/postgres_ext.h don't have any PG_VERSION or similar define... On 8/24/06, Alexander Farber <[EMAIL PROTECTED]> wrote: I'm trying to compile a libpq progra

Re: [GENERAL] undefined reference to `PQprepare' with postgresql-dev 7.4.7-6sarge2

2006-08-24 Thread Alexander Farber
On 8/24/06, Tom Lane <[EMAIL PROTECTED]> wrote: "Alexander Farber" <[EMAIL PROTECTED]> writes: > Does anybody have an idea please, what could I be doing wrong? Trying to use a subroutine added in 8.0 in 7.4. Regards Alex -- http://preferans.de

Re: [GENERAL] undefined reference to `PQprepare' with postgresql-dev 7.4.7-6sarge2

2006-08-24 Thread Alexander Farber
Ok, I've upgraded to: $ dpkg -l | grep postgres ii postgresql-8.1 8.1.4-4bpo1object-relational SQL database, version 8.1 ii postgresql-cli 8.1.4-4bpo1front-end programs for PostgreSQL 8.1 ii postgresql-cli 57bpo1 manager for multiple PostgreSQL client versi ii postgr

<    1   2   3   4