[SQL] Subselects to Joins? Or: how to design phone calls database

2011-12-10 Thread Mario Splivalo
I have a table called 'calls' which holds 'call detail records'. Let's assume the table looks like this: CREATE TABLE cdr ( call_id serial, phone_number text ); And I have a table with country call prefixes, that looks like this: CREATE TABLE prefixes ( prefix text,

Re: [SQL] Get the max viewd product_id for user_id

2010-12-05 Thread Mario Splivalo
On 12/05/2010 05:57 PM, Mario Splivalo wrote: The issue in both approaches is that if I have two product_ids that are viewed same number of times and share the first place as most viewed products by that user, I'll get only one of them (LIMIT 1 OR MAX() can only return one row :). And

Re: [SQL] Get the max viewd product_id for user_id

2010-12-05 Thread Mario Splivalo
On 12/03/2010 12:40 PM, Jayadevan M wrote: Hello, I went this way, but for a large number of user_id's, it's quite slow: CREATE VIEW v_views AS SELECT user_id, product_id, count(*) as views FROM viewlog GROUP BY user_id, product_id SELECT DISTINCT user_id, (SELECT product_

Re: [SQL] Get the max viewd product_id for user_id

2010-12-05 Thread Mario Splivalo
On 12/03/2010 12:40 PM, Jayadevan M wrote: Hello, I went this way, but for a large number of user_id's, it's quite slow: CREATE VIEW v_views AS SELECT user_id, product_id, count(*) as views FROM viewlog GROUP BY user_id, product_id SELECT DISTINCT user_id, (SELECT product_

[SQL] Get the max viewd product_id for user_id

2010-12-03 Thread Mario Splivalo
I have a log-table where I record when some user_id has viewed some product_id: CREATE TABLE viewlog ( user_id integer, product_id integer, view_timestamp timestamp with time zone ) Now, I would like to get result that gives me, for each user_id, product_id of the produ

Re: [SQL] Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-20 Thread Mario Splivalo
Tom Lane wrote: I think what Mario is actually complaining about is that partial unique indexes are not part of the SQL standard, and he wants a solution that at least gives the illusion that it might be portable to some other RDBMS in the future. Correct. As far as I can see there is no parti

Re: [SQL] Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Mario Splivalo
Jasen Betts wrote: > ... > >> The 'proper' way to do this (as suggested by earlier posts on this >> mailing list) is to use partial UNIQUE indexes, but I have problem with >> that too: indexes are not part of DDL (no matter that primary key >> constraints and/or unique constraints use indexes to e

[SQL] CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Mario Splivalo
The 'data integrity' rule for database I'm designing says that any subject we're tracking (persons, companies, whatever) is assigned an agreement that can be in several states: 'Approved', 'Unapproved' or 'Obsolete'. One subject can have only one (or none) 'Approved' or 'Unapproved' agreement, and

[SQL] Using CASE in plpgsql causes 'ERROR: cache lookup failed'

2010-04-14 Thread Mario Splivalo
I have an enum-type, like this: CREATE TYPE type_enum_service_type AS ENUM ('Banner', 'Ticker', 'Memo'); Then I have a table, like this: CREATE TABLE services ( service_id integer NOT NULL, service_type type_enum_service_type NOT NULL, service_keyword character varying NOT NULL, servi

[SQL] Using information_schema to find about function parameters?

2009-10-29 Thread Mario Splivalo
I looked at the information_schema.routines, to get information about the functions in the database, but there doesn't seem to be a way to extract the parameters information about functions? Where would I seek for such information? Mike -- Sent via pgsql-sql mailing list (pgsql-sql@postg

[SQL] CREATE INDEX on column of type 'point'

2009-09-16 Thread Mario Splivalo
As I have discovered, there is no way to just create index on a column of type 'point' - postgres complains about not knowing the default operator class, no matter what index type I use. Now, my table looks like this: CREATE TABLE places ( place_id integer primary key, coordina

Re: [SQL] CHECK constraint on multiple tables

2009-09-14 Thread Mario Splivalo
Tom Lane wrote: > Mario Splivalo writes: >> I have two tables, tableA and tableB: >> CREATE TABLE tableA (idA integer primary key, email character varying >> unique); >> CREATE TABLE tableB (idB integer primary key, email character varying >> unique); > >&

Re: [SQL] CHECK constraint on multiple tables

2009-09-14 Thread Mario Splivalo
How would you do it, without creating third table? Mario Ries van Twisk wrote: > can't you solve it creating a reference between the tables? > > Ries > On Sep 14, 2009, at 8:24 AM, Mario Splivalo wrote: > >> I have two tables, tableA and tableB: >> >

[SQL] CHECK constraint on multiple tables

2009-09-14 Thread Mario Splivalo
I have two tables, tableA and tableB: CREATE TABLE tableA (idA integer primary key, email character varying unique); CREATE TABLE tableB (idB integer primary key, email character varying unique); Now, I want to create check constraint in both tables that would disallow records to either table whe

Re: [SQL] Trapping 'invalid input syntax for integer'

2009-09-10 Thread Mario Splivalo
Marcin Krawczyk wrote: > Hi, I believe you're looking for invalid_text_representation. > > EXCEPTION WHEN invalid_text_representation THEN > Thnx, that is it. Mike -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql

[SQL] Trapping 'invalid input syntax for integer'

2009-09-10 Thread Mario Splivalo
Is there a way to trap this error in plpgsql code? I have a function that accepts integer and character varying. Inside that function I need to cast that varchar to integer. Of course, sometimes that is not possible. When I run function like that, I get this errror: fidel=# select * from get_acco

Re: [SQL] date_trunc should be called date_round?

2009-06-29 Thread Mario Splivalo
Tom Lane wrote: > Mario Splivalo writes: >> But, date_trunc behaves like round function: round(1.9) = 2. > > Hmm ... only for float timestamps, and only for the millisec/microsec > cases. > > case DTK_MILLISEC: > #ifdef HAVE_INT64_TIMESTAMP >

[SQL] date_trunc should be called date_round?

2009-06-29 Thread Mario Splivalo
It's stated in the docs that date_trunc is "conceptually similar to the trunc function for numbers.". So, trunc(1.1) = 1, trunc(1.9) = 1, and so on. But, date_trunc behaves like round function: round(1.9) = 2. Example: idel=# select date_trunc('milliseconds', '2009-01-01 12:15:00.000999+02'::ti

[SQL] Find periods for a given... action set?

2009-06-12 Thread Mario Splivalo
I have a table where there are actinos for some user logged. It's part of the MPI system of some sort. For every user, action type and time of the action is logged. There are many action types but the ones which are of interest to me are BEGIN and END. I need to find the durations for all the p

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread Mario Splivalo
landsharkdaddy wrote: I have not tried that but I will in the morning. The @ in SQL is used to indicate a parameter passed to the query. In PostgreSQL it seems that the : is the same as the @ in SQL Server. I tried something like: SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%';

Re: [SQL] Ordering a name list and ignoring whitespace

2009-04-16 Thread Mario Splivalo
Mikel Lindsaar wrote: Hi all, Doing some googling and looking through the docs, I can't find an obvious way to do this beside post processing after the query (which I am trying to avoid). I'm trying to select a list of names in alphabetical order but ignoring the whitespace. So for example, th

Re: [SQL] ENUM vs DOMAIN vs FKyed loookup table

2009-04-14 Thread Mario Splivalo
Dirk Jagdmann wrote: When you need to choose between enum types, domain types or lookup tables with foreign keys, what do you usualy choose? When I have a column with valid values that I know when writing my tables and that will *never* change I use an enum. For example a human gender type (and

[SQL] ENUM vs DOMAIN vs FKyed loookup table

2009-04-08 Thread Mario Splivalo
When you need to choose between enum types, domain types or lookup tables with foreign keys, what do you usualy choose? Only recently I started using domains, but that seems to be painful, as Joshua Drake explains here: http://www.commandprompt.com/blogs/joshua_drake/2009/01/fk_check_enum_or_

[SQL] xpath_table, or something similair?

2009-03-30 Thread Mario Splivalo
Is there a way to get recordset out of XML document - something similair to contrib/xml2's xpath_table function, but I'd like to be able to get data out of XML document that is not stored in the database. I wrote my own plpgsql function for converting XML document data to recordset (table), bu

Re: [SQL] Postgres version of all_ind_cols

2008-11-11 Thread Mario Splivalo
Bart van Houdt wrote: Hi all, This might be a stupid question, but I wasn't able to find any information on it, so here it goes: Oracle knows a view which contains information about indexed columns (all_ind_cols), is there something similar available in Postgres? I want to be able to create a

Re: [SQL] Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

2008-11-11 Thread Mario Splivalo
Mario Splivalo wrote: But, if I want it other way around, I get the error: test1=# select envode(E'\305', 'hex'); ERROR: invalid byte sequence for encoding "UTF8": 0xc5 HINT: This error can also happen if the byte sequence does not match the encoding ex

Re: [SQL] Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

2008-11-11 Thread Mario Splivalo
Tom Lane wrote: Mario Splivalo <[EMAIL PROTECTED]> writes: Tom Lane wrote: Exactly what version of pg_dump are you using? What I get from pg_dump doesn't look like that. Bytea fields with -D look more like this: INSERT INTO foo (f1) VALUES ('\\305S\\224\\226\\203)')

Re: [SQL] Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

2008-11-11 Thread Mario Splivalo
Richard Huxton wrote: Mario Splivalo wrote: Richard Huxton wrote: Mario Splivalo wrote: I have this issue: postgres=# select E'\xc5\x53\x94\x96\x83\x29'; ERROR: invalid byte sequence for encoding "UTF8": 0xc553 I think you want to be using octal escapes. That's tex

Re: [SQL] Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

2008-11-10 Thread Mario Splivalo
Tom Lane wrote: I'm using the above mentioned string to store data into bytea column. I did pg_dump of the database on postgres 8.2, and then tried to restore it on postgres 8.3, and I got this error. The actuall line that produces error is like this: INSERT INTO vpn_payins_bitfield (vpn_id,

[SQL] Converting between UUID and VARCHAR

2008-11-10 Thread Mario Splivalo
I have a table, like this: CREATE TABLE t1 ( u1 character varying ) And some data inside: INSERT INTO t1 (u1) VALUES ('62d6b434-7dfd-4b3b-b1bf-87f6c20c10dd'); INSERT INTO t1 (u1) VALUES ('e3fee596-164b-4995-9e0d-7b2a79e83752'); INSERT INTO t1 (u1) VALUES ('37a42ec8-9000-44bc-bb06-13b5d4373a45

[SQL] Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

2008-11-10 Thread Mario Splivalo
I have this issue: postgres=# select E'\xc5\x53\x94\x96\x83\x29'; ERROR: invalid byte sequence for encoding "UTF8": 0xc553 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". postgres=# show clien

Re: [SQL] Subselect strange behaviour - bug?

2008-03-17 Thread Mario Splivalo
Tom Lane wrote: Mario Splivalo <[EMAIL PROTECTED]> writes: And here is the 'problematic' query: melem=# select * from t2 where id1 in (select id1 from t1); I guess postgres should tell me that column name id1 is nonexistant in table t1. No, it shouldn

[SQL] Subselect strange behaviour - bug?

2008-03-16 Thread Mario Splivalo
I have two tables, 'configured' like this: melem=# \d t1 Table "public.t1" Column | Type| Modifiers +---+--- id | integer | value | character varying | melem=# \d t2 Table "public.t2" Column | Type

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 11:09 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Am I doing something wrong here, or there is no way of using temporary > > tables within 'sql' written functions? > > I believe the problem is that for a SQL f

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 11:00 -0500, Andrew Sullivan wrote: > On Thu, Jan 25, 2007 at 03:39:14PM +0100, Mario Splivalo wrote: > > When I try to use TEMPORARY TABLE within postgres functions (using 'sql' > > as a function language), I can't because postgres can&#

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 08:03 -0800, Stephan Szabo wrote: > On Thu, 25 Jan 2007, Mario Splivalo wrote: > > > When I try to use TEMPORARY TABLE within postgres functions (using 'sql' > > as a function language), I can't because postgres can't find that >

[SQL] Using Temporary Tables in postgres functions

2007-01-25 Thread Mario Splivalo
When I try to use TEMPORARY TABLE within postgres functions (using 'sql' as a function language), I can't because postgres can't find that temporary table. Consider this example: CREATE FUNCTION func1() RETURNS SETOF v_messages_full AS $BODY$ CREATE TEMPORARY TABLE tmpTbl AS SELECT messag

Re: [SQL] Postgres regexp matching failure?

2006-09-07 Thread Mario Splivalo
On Tue, 2006-09-05 at 11:22 -0400, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > So, I guess it's obvious that postgres doesn't treat regular expressions > > the same way as java/perl/pyton/php/awk/sed do... > > When you get into stuff a

Re: [SQL] Postgres regexp matching failure?

2006-09-05 Thread Mario Splivalo
On Tue, 2006-09-05 at 10:21 -0400, Alvaro Herrera wrote: > Mario Splivalo wrote: > > On Tue, 2006-09-05 at 08:42 -0500, Aaron Bono wrote: > > > On 9/5/06, Mario Splivalo <[EMAIL PROTECTED]> wrote: > > > > > > pulitzer2=# select 'sto

Re: [SQL] Postgres regexp matching failure?

2006-09-05 Thread Mario Splivalo
On Tue, 2006-09-05 at 08:42 -0500, Aaron Bono wrote: > On 9/5/06, Mario Splivalo <[EMAIL PROTECTED]> wrote: > > pulitzer2=# select 'stop works' ~ '^\s*(?:[\ > +|-]|(?:[sS][tT][oO][pP]\b)).*$'; > ?column? >

Re: [SQL] Postgres regexp matching failure?

2006-09-05 Thread Mario Splivalo
On Tue, 2006-09-05 at 10:11 -0400, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Now, here is what happens if I try this in postgres: > > > pulitzer2=# select '+mario' ~ '^\s*(?:[\+|-]|(?:[sS][tT][oO][pP]\b)).*$'; > > I'

[SQL] Postgres regexp matching failure?

2006-09-05 Thread Mario Splivalo
[sS][tT][oO][pP]\b)).*$'; ?column? -- t (1 row) This one is also ok. pulitzer2=# select 'mario works' ~ '^\s*(?:[\ +|-]|(?:[sS][tT][oO][pP]\b)).*$'; ?column? -- f (1 row) Same as this one, also ok. pulitzer2=# select 'stop works' ~ '^\s*(?:[\ +|-]|(

[SQL] Primary key constraint violation without error?

2006-07-24 Thread Mario Splivalo
; l_netsms=# This is expected, I'm just unsure why ain't I receiving that error when running punimessages() function? Postgres is 8.1.2 running on linux 2.6.17. Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick

Re: [SQL] Views and query planner

2006-06-30 Thread Mario Splivalo
On Fri, 2006-06-30 at 21:47 +0900, Michael Glaesemann wrote: > On Jun 30, 2006, at 21:35 , Mario Splivalo wrote: > > > Is postgres going to make one query plan, or each view has it own > > query > > plan? > > Have you taken a look at the EXPLAIN ANALYZE output o

[SQL] Views and query planner

2006-06-30 Thread Mario Splivalo
ry plan, or each view has it own query plan? Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] hi i need to encrypt one field in a table

2006-05-30 Thread Mario Splivalo
encrypted passwords. Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an

Re: [SQL] Counting the rows INSERTed/UPDATEd?

2006-05-02 Thread Mario Splivalo
On Tue, 2006-05-02 at 09:13 +0100, Richard Huxton wrote: > Mario Splivalo wrote: > > I have found, I thinl, in the pg manual, the way to get the number of > > rows inserted/updated, from within the plpgsql. I can't find it anymore, > > is that still there, or I misread so

[SQL] Counting the rows INSERTed/UPDATEd?

2006-05-01 Thread Mario Splivalo
I have found, I thinl, in the pg manual, the way to get the number of rows inserted/updated, from within the plpgsql. I can't find it anymore, is that still there, or I misread something earlier? Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do i

[SQL] INSERTing values from usertypes how-to?

2006-04-27 Thread Mario Splivalo
Comming back after SELECTing into usertypes, is there a nice way to insert data into table from usertype, in a nice way? For instance, I have table like this: CREATE TABLE tblA ( id int4, key varchar, value varchar ) Then, in my function, I do this: CREATE FUNCTION testI

Re: [SQL] SELECTing into usertype, how to do it?

2006-04-25 Thread Mario Splivalo
On Tue, 2006-04-25 at 14:21 +0200, A. Kretschmer wrote: > am 25.04.2006, um 14:03:07 +0200 mailte Mario Splivalo folgendes: > > > > And then, when I want to fill in the type_var, i do this: > > > > type_var.member_a := col_a FROM table_a WHERE col_c = 5; > &g

[SQL] SELECTing into usertype, how to do it?

2006-04-25 Thread Mario Splivalo
27;d like to do? Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] 'locking' the SELECTs based on indices...

2006-02-23 Thread Mario Splivalo
On Thu, 2006-02-23 at 17:35 +0100, PFC wrote: > > > Now, If some other user want's his prize, when checking his code, if he > > sends code for some other service then service 1, that's ok. If he's > > sends code for the service 1 the PERFORM will wait untill I'm finished > > with previous user. >

Re: [SQL] 'locking' the SELECTs based on indices...

2006-02-23 Thread Mario Splivalo
On Thu, 2006-02-23 at 13:56 +0200, Achilleus Mantzios wrote: > The intersection of rows that satisfy BOTH > "code_id = 1 AND code_value = 'abla'" > and > "code_id = 1 AND code_value = 'eble'" > is ZERO!!! > > Why would you want irrelevant rows to wait for one another?? It was a bit silly repre

Re: [SQL] 'locking' the SELECTs based on indices...

2006-02-23 Thread Mario Splivalo
On Wed, 2006-02-22 at 13:58 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Now, when I do this from one connection (psql shell, for instance): > > > [A]BEGIN TRANSACTION; > > [A]SELECT * FROM bla WHERE code_id = 1 FOR UPDATE; > >

[SQL] 'locking' the SELECTs based on indices...

2006-02-22 Thread Mario Splivalo
UPDATE I will get the rows. If I erase the index bla_idx1, then [C] select will wait, same as [B] select will wait. Is there a way to have this behaviour with the index on column code_id? Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I c

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
On Mon, 2006-02-13 at 17:10 +0100, Mathieu Arnold wrote: > | It works like this: > | > | ORDER BY (CASE WHEN 5=5 THEN "from"::varchar ELSE > | receiving_time::varchar) DESC. > | > | Is there a way to have DESC/ASC inside of a CASE? > | > | Mario > > No, you don't understand, you should do s

Re: [SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
EN 5=5 THEN "from"::varchar ELSE receiving_time::varchar) DESC. Is there a way to have DESC/ASC inside of a CASE? Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two."

[SQL] ORDER BY CASE ...

2006-02-13 Thread Mario Splivalo
END, or do I need to have two querries, and then first check for the value of the parametar, and then, according to that value, call the SELECTs wich sort randomly, or by receiving_time. Mario P.S. The postgres is 8.1.2. -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick,

Re: [SQL] CREATE VIEW form stored in database?

2006-01-31 Thread Mario Splivalo
On Tue, 2006-01-31 at 12:30 +, Richard Huxton wrote: > Mario Splivalo wrote: > > When I create a view, I like to define it like this (just representing > > the form here): > [snip] > > But, when I extracit it from postgres, it's somehow stored like this: > [

[SQL] CREATE VIEW form stored in database?

2006-01-31 Thread Mario Splivalo
ostgres NOT to format the 'source code' of my views? Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 1: if posting/readi

Re: [SQL] How to find a temporary table

2006-01-27 Thread Mario Splivalo
On Fri, 2006-01-27 at 04:48 -0800, Emil Rachovsky wrote: > Hi, > I am using PostgreSQL 8.1.0 . How can I find a temp > table from my session, having the name of the table? > Can anyone show me what query should I execute? I've > tried some things but I receive mixed results of > tables from differe

Re: [SQL] Changing the transaction isolation level within

2006-01-27 Thread Mario Splivalo
"NOTIFY interacts with SQL transactions" in the NOTIFY documentation. I've been playing with that, but performance drops significantly with those notifications. And, it would be a hack. We redesigned the process so it makes sense :) > > I don

Re: [SQL] Changing the transaction isolation level within the

2006-01-25 Thread Mario Splivalo
On Wed, 2006-01-25 at 15:54 +0100, Markus Schaber wrote: > Hi, Mario, > > Mario Splivalo wrote: > > Is it possible to change the transaction level within the procedure? > > No, currently not, the PostgreSQL "stored procedures" really are "stored > functio

Re: [SQL] Changing the transaction isolation level within the

2006-01-25 Thread Mario Splivalo
On Wed, 2006-01-25 at 11:46 -0500, Jaime Casanova wrote: > you need to set the transaction level after the begin and before every > other statement... after the begin you have a select that invoke your > function so that set is not the first statement... But I can't do that inside of a function,

[SQL] Changing the transaction isolation level within the stored procedure?

2006-01-25 Thread Mario Splivalo
or I need to do 'SET TRANSACTION ISOLATION LEVEL TO SERIALIZABLE' before step 2 in both thread A and thread B? Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of

[SQL] Regexp group matching - extracting second group element?

2006-01-10 Thread Mario Splivalo
oup. Is there a way to extract 'auction 24' as a second group? Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 9: In versi

Re: [SQL] Regular Expression Matching problem...

2006-01-08 Thread Mario Splivalo
On Wed, 2006-01-04 at 10:00 -0700, Michael Fuhr wrote: > What Andreas is saying is that the patterns in the table have too > many backslashes. The original query was > > test=> select '+385911234567' ~ '^\\+38591\\d{7}$'; > ?column? > -- > t > (1 row) > > but if you select just the p

[SQL] Regular Expression Matching problem...

2006-01-04 Thread Mario Splivalo
turn "t", esp. when I wrote the first query it seems that the regex match was ok. Or I can't do regexp matching from the table columns? Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two."

[SQL] PostgreSQL and uuid/guid

2006-01-02 Thread Mario Splivalo
s the general feeling concerning the uuid issue I explained above? I've never written a C postgreSQL function, and any help (or documentation pointout) would be greatly appreciated. If I posted this to the wrong mailing list, please point me out to the correct one. Mario -- Mario Spl

Re: [SQL] JOIN query not working as expected

2005-12-06 Thread Mario Splivalo
On Tue, 2005-12-06 at 09:58 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Now I want all services which didn't have any messages within certain > > period: > > pulitzer2=# select * from services where id not in (select distinct &g

[SQL] JOIN query not working as expected

2005-12-06 Thread Mario Splivalo
EEN '2005-10-01' AND '2005-10-30' GROUP BY services.id, services.keyword ORDER BY services.keyword This query runs MUCH faster, but it omits the 'cocker' column, as if I used INNER JOIN. Any clues? I'm stuck here... Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Create Public Schema

2005-11-20 Thread Mario Splivalo
On Sat, 2005-11-19 at 20:03 -0700, [EMAIL PROTECTED] wrote: > Hello all, > > I'm trying to create a schema that contains the default tables, > functions, etc. of the public schema. Using pgAdmin, when I create a > schema, it is blank - has no associated aggregates, tables, etc. How > would I cre

Re: [SQL] RETURNS SETOF table; language 'sql'

2005-11-09 Thread Mario Splivalo
On Wed, 2005-11-09 at 17:05 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Works fine. I remind you again, this is on a newly created database. > > Yup, works fine for me too. > > > When I run it, again the same:pulitzer2=# select * from &g

Re: [SQL] RETURNS SETOF table; language 'sql'

2005-11-09 Thread Mario Splivalo
On Wed, 2005-11-09 at 13:49 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > When I do: > > SELECT * FROM get_ads(1004); > > i get: > > ERROR: query-specified return row and actual function return row do not > > match > > Th

[SQL] RETURNS SETOF table; language 'sql'

2005-11-09 Thread Mario Splivalo
I do: SELECT * FROM get_ads(1004); i get: ERROR: query-specified return row and actual function return row do not match Why is that? Mike P.S. That's run on Postgres 7.4. -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap,

[SQL] Slow query - SELECTing one row from 'big' table.

2005-11-03 Thread Mario Splivalo
seems that SELECT itself is slow, not the currval. Am I doing something wrong? Or that's just the way it is? I have a workaround now, I declared local variable of type messages%ROW, and I fill that variable with the parametars received from the caller of the function, and then i do RETURN

Re: [SQL] PGSQL encryption functions

2005-11-02 Thread Mario Splivalo
described it. I'd also lilke to see he's example of brute-force 'cracking' the MD5 digest. Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] why vacuum

2005-10-28 Thread Mario Splivalo
ppose), or put it on a web page or > whatever. General Bits is a fairly regular column that Elein Mustain > puts out. I bet she'd include a submission on this topic, although > you'd have to ask her. You can find GB at > <http://varlena.com/varlena/GeneralBits/>. I'll

Re: [SQL] why vacuum

2005-10-27 Thread Mario Splivalo
On Thu, 2005-10-27 at 06:21 -0400, Andrew Sullivan wrote: > On Thu, Oct 27, 2005 at 10:22:41AM +0200, Mario Splivalo wrote: > > offers no replication at all, you need to use slony (wich is also a poor > > replacement for a wannabe replication), or some other commercial > > pro

Re: [SQL] why vacuum

2005-10-27 Thread Mario Splivalo
slow down postgres quite a bit. So, to end this 'my father has bigger car than yours' debate, when will postgres have two phase commit protocol implemented? I presume that should come after you allow something like SELECT someCol FROM myServer.myDatabase[Schema].myTable... Mike --

Re: [SQL] why vacuum

2005-10-27 Thread Mario Splivalo
ation wos working as expected, and the load that replication posed was insignificant. The only TRUE problem was that replication was unidirectional. That SAME problem has Slony, and other 'replication systems' available for postgres. Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED

Re: [SQL] RETURNS SETOF primitive returns results in parentheses

2005-10-26 Thread Mario Splivalo
On Wed, 2005-10-26 at 15:45 -0400, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Wo-ha, makes perfect sense. So, I'd go by with declaring the rec as > > varchar, instead as of a record. Wich is what I should do in the first > > place. > > O

Re: [SQL] RETURNS SETOF primitive returns results in parentheses

2005-10-26 Thread Mario Splivalo
On Wed, 2005-10-26 at 10:40 -0400, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > biblio3=# select * from php_get_subfield_data_repeating(1,'606a'); > > php_get_subfield_data_repeating1 > > -- > > (Anđel

Re: [SQL] RETURNS SETOF primitive returns results in parentheses

2005-10-26 Thread Mario Splivalo
ering is this like that 'by design', or is it a bug. I've been reproducing this on postgres versions 7.4.8, 7.4.9, 8.0.3, 8.0.4 and 8.1beta3. Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick any two." ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

[SQL] RETURNS SETOF primitive returns results in parentheses

2005-10-26 Thread Mario Splivalo
1,'606a'); subfield_data --- Anđeli ofsajd (2 rows) Am I doing something wrong here? Why do I need to create type with only one member of type varchar to have results without the parentheses? Mike P.S. The subFieldValue field in the records_sub table is of type

Re: [SQL] Postgres 7.4.9 slow!

2005-10-21 Thread Mario Splivalo
On Fri, 2005-10-21 at 10:20 -0400, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > I have a query that does COUNT, LEFT JOIN and GROUP BY from two tables. > > One has 85000 records, and other has 100 records. I've been running > > the tests o

Re: [SQL] Postgres 7.4.9 slow!

2005-10-21 Thread Mario Splivalo
just that when I run the query with pg7.4.8 it takes 100% of the processor time while running. pg7.4.9 takes 2-10% while running. Disk activity is much more intense with pg7.4.9 Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well

[SQL] Postgres 7.4.9 slow!

2005-10-21 Thread Mario Splivalo
4.9, and i'm running the very same query on the very same database with all the indices and constraints beeing the same (also SET ENABLE_SEQSCAN TO OFF), and I get around 90-110 seconds. Has anyone noticed extreeme slowdown of postgres 7.4.9? Mike -- Mario Splivalo Mob-Art [EMAIL PROTE

Re: [SQL] Field Separator not working?

2005-10-19 Thread Mario Splivalo
On Wed, 2005-10-19 at 11:43 +0100, Richard Huxton wrote: > Mario Splivalo wrote: > > pulitzer2=# \t > > Showing only tuples. > > pulitzer2=# \f# > > Field separator is "#". > > pulitzer2=# select * from pg_user; > >

[SQL] Field Separator not working?

2005-10-19 Thread Mario Splivalo
es I have problems because data in my tables often contain "|" charachter. I've been looking trough the psql source code, but just like that, it's too big hassle for me now :) Am I doing something wrong? Mike -- Mario Splivalo Mob-Art [EMAIL PROTECTED]

Re: [SQL] Consulta!

2005-10-18 Thread Mario Splivalo
he desired query, in your case: FOR res IN EXECUTE SELECT x FROM test LOOP ... It is more convinient to add the SQL query to a variable, and then exec that variable, like so: _SQL := 'SELECT a, b FROM tmpTable WHERE colText=' || quote_literal(someParametar); FOR res IN EXECUTE _SQL LOOP

Re: [SQL] Returning NULL results?

2005-10-12 Thread Mario Splivalo
On Tue, 2005-10-11 at 15:39 +0100, Richard Huxton wrote: > Mario Splivalo wrote: > > > > Of course, if it returns no rows, I'm presented with an error, saying: > > > > ERROR: record "rec" has no field "_qv" > > > > This is logic

[SQL] Returning NULL results?

2005-10-11 Thread Mario Splivalo
no field "_qv" This is logical. My question would be is there a way around this withouth first doing SELECT COUNT(*) FROM tmbBids WHERE ..., and then if COUNT(*) is zero THEN bidCount := NULL ELSE if COUNT(*) is not zero then do SELECT from the begining? Mike -- Mario Splivalo Mob

Re: [SQL] EXECUTE SELECT INTO... last one!

2005-09-30 Thread Mario Splivalo
On Fri, 2005-09-30 at 02:34 -0600, Michael Fuhr wrote: > On Fri, Sep 30, 2005 at 10:00:35AM +0200, Mario Splivalo wrote: > > PgSql8.1beta2 gives me this: > > > > ERROR: EXECUTE of SELECT ... INTO is not implemented yet > > CONTEXT: PL/pgSQL function "_rndb

[SQL] EXECUTE SELECT INTO... last one!

2005-09-30 Thread Mario Splivalo
PgSql8.1beta2 gives me this: ERROR: EXECUTE of SELECT ... INTO is not implemented yet CONTEXT: PL/pgSQL function "_rndbroj" line 5 at execute statement Shall I forget about this once and for all (and use FOR construct), or there is a chance that will be 'fixed'?

[SQL] EXECUTE with SELECT INTO variable, or alternatives

2005-09-29 Thread Mario Splivalo
I can assign a value to a variable in several ways: myVar := (SELECT col FROM table WHERE somecondition...) myVar := col FROM table WHERE somecondtition... SELECT col INTO myVar FROM table WHERE somecondition How do I do any of the above using EXECUTE? I need to be able to assign the value to a v

Re: [SQL] Sending function parametars within EXECUTE ''SELECT...

2005-09-29 Thread Mario Splivalo
x27;t have postsgres handy now, I'll check that ASAP, but somehow I feel that I'd run into same problems as before. I'll try and I'll post a reply here. Mario -- Mario Splivalo Mob-Art [EMAIL PROTECTED] "I can do it quick, I can do it cheap, I can do it well. Pick

Re: [SQL] Sending function parametars within EXECUTE ''SELECT...

2005-09-28 Thread Mario Splivalo
On Wed, 2005-09-28 at 10:01 -0700, codeWarrior wrote: > > > > ---(end of broadcast)--- > > TIP 5: don't forget to increase your free space map settings > > > > FOR rec IN EXECUTE ''SELECT COUNT(col1) AS num FROM tmpTbl WHERE col2 = " || > aBid || ''

[SQL] Sending function parametars within EXECUTE ''SELECT...

2005-09-28 Thread Mario Splivalo
I've learned that one can't use temporary tables within the function unless EXECUTE'd the SELECTS from that temp table. So, I have a function like this: CREATE FUNCTION Foo1(int4, int4) RETURNS SETOF myType AS ' DECLARE aDataId ALIAS FOR $1; aBid ALIAS FOR $2; return myTyp