Re: [SQL] UNNEST result order vs Array data

2013-06-20 Thread Richard Huxton
nteed. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Restrict FOREIGN KEY to a part of the referenced table

2013-04-12 Thread Richard Broersma
uot; CHECK( parent_discriminator = 42) or: COMMENT ON TABLE child "Your explanation goes here."; If you need to hide this column from you uses, you can use a view. -- Regards, Richard Broersma Jr.

Re: [SQL] Concatenating bytea types...

2013-03-01 Thread Richard Huxton
2, 'hex'); END; $$ LANGUAGE plpgsql; SELECT '\x000b'::bytea AS want_this, decode('000b','hex')AS or_this1, decode('\000\013','escape') AS or_this2; SELECT f_concat_bytea1('\x00', '\x0b&#x

Re: [SQL] Can't get upsert working.

2012-12-04 Thread Richard Huxton
ve, which means it's trying to treat them as a single record-column with three fields. Hence the error message. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Disabling constraint check

2012-09-17 Thread Richard Broersma
LE-EXCLUDE You cannot disable a check constraint. Perhaps a staging table is advisable here? -- Regards, Richard Broersma Jr.

Re: [SQL] Insane behaviour in 8.3.3

2012-06-15 Thread Richard Huxton
k the same options as ssh I daresay you could get it working. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Insane behaviour in 8.3.3

2012-06-14 Thread Richard Huxton
-- (0 rows) dynacom=# -- THIS IS INSANE Perhaps just do an EXPLAIN ANALYSE on both of those. If for some reason one is using the index and the other isn't then it could be down to a corrupted index. Seems unlikely though. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing

Re: [SQL] Postgresql function which compares values from both tables

2012-03-19 Thread Richard Huxton
AS id_a, tb.id AS id_b, ta.d, ta.t FROM ta JOIN tb USING (d,t); ROLLBACK; If the fields were named differently you'd need something like: FROM ta JOIN tb ON (ta.d1, ta.t1) = (tb.d2, tb.t2) -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql

Re: [SQL] Natural sort order

2012-02-29 Thread Richard Klingler
Actually got it figured...for some reason it had the function twice (o; But with or without function index the time to query stays the same...around 110msec for 24 results... cheers richard On Wed, 29 Feb 2012 11:08:46 -0500, Tom Lane wrote: > Richard Klingler writes: >> Took some t

Re: [SQL] Natural sort order

2012-02-28 Thread Richard Klingler
rt(name)); Which should speed up my query: select * from port where name not like '%Z' order by btrsort(name) asc cheers richard On Sat, 17 Dec 2011 16:16:07 +0100, Filip Rembiałkowski wrote: > If you use btrsort(column) from the example, you can just create

[SQL] Natural sort order

2011-12-17 Thread Richard Klingler
for building up a hierarchical tree menu in a web application where every msecs counts (o; cheers richard -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] conditional FROM

2011-12-10 Thread Richard Klingler
%' ; Though I just can't order the rows anymore by inet(arp.ip) anymore... Any hints on my ordering isn't anylonger possible? But at least the query is way faster than before (o; 2msec instead of 650msecs (o; thanx ina dvance richard On Sat, 10 Dec 2011 11:28:29 -0500, David Jo

[SQL] conditional FROM

2011-12-10 Thread Richard Klingler
Null or 0... thanx in advance richard -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] updating a sequence

2011-11-15 Thread Richard Broersma
Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] the use of $$string$$

2011-11-07 Thread Richard Huxton
quote any of your values in your Python code - it's doing it for you. I'm guessing there are other options beside %s for other data-types (integers,floats,boolean etc). -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] the use of $$string$$

2011-11-04 Thread Richard Huxton
caping apart from single quotes. It's especially useful for function bodies which tend to contain their own string literals. SELECT length($$ab\nde$$); length 6 None of this should matter from an application however, since its database access library should do all the

Re: [SQL] need help with some aggregation magic

2011-06-09 Thread Richard Broersma
FROM Loggingtable GROUP BY user_id, project_id, date_trunc( 'day', ts ) ORDER BY date_trunc( 'day', ts ), user_id, project_id; -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] selecting records X minutes apart

2011-06-04 Thread Richard Broersma
WHERE B.id = Accum_ts.id AND B.ts >= Accum_ts.ts - INTERVAL '5 MINUTES' GROUP BY B.id HAVING MIN( B.ts ) <= MAX( B.ts )) SELECT id, ts FROM Accum_ts ORDER BY id, ts; -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql

Re: [SQL] selecting records X minutes apart

2011-06-04 Thread Richard Broersma
XISTS ( SELECT * FROM Yourtable AS B WHERE B.id = A.id AND B.ts > A.ts - INTERVAL '5 MINUTES' AND B.tx < A.ts ) ORDER BY id, ts; -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@p

Re: [SQL] CROSS JOIN ordering

2011-05-12 Thread Richard Huxton
ies do not have any guaranteed order unless you add an ORDER BY clause. None of them, no matter how simple. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Dates and NULL's`

2011-05-10 Thread Richard Broersma
will be returned too The WHERE clause will only return rows is the arguments all evaluate to TRUE. No rows will be returned for rows that cause the WHERE clause to evaluate to a NULL value. -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To m

Re: [SQL] Dates and NULL's`

2011-05-10 Thread Richard Broersma
4-01'::DATE AND NULL::DATE <= '2011-04-30'::DATE) IS FALSE; ?column? -- f (1 row) spi=> SELECT (NULL::DATE >= '2011-04-01'::DATE AND NULL::DATE <= '2011-04-30'::DATE) IS UNKNOWN; ?column? -- t (1 row) -- Regards, Richard Br

[SQL] None numeric exclusion constraints using GIST

2011-05-06 Thread Richard Broersma
ostgresql.org/docs/9.1/static/datatype-geometric.html http://www.postgresql.org/docs/9.1/static/sql-createindex.html http://www.depesz.com/index.php/2010/01/03/waiting-for-8-5-exclusion-constraints/ Is this correct? -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@p

Re: [SQL]How to transform table rows into Colum?

2011-03-17 Thread Richard Albright
you can also generate a crosstab table using the sign function you can check out the link below ( its a sqlite tutorial, but the same idea will work for pg too ) http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html On 03/09/2011 12:16 PM, Eric Ndengang wrote: Hi Guys, I have the fo

Re: [SQL] Problem with serial counters

2011-03-01 Thread Richard Huxton
. Apart from Vibhor's suggestion (which is the typical way PG does it) you can also set the auto field to DEFAULT: INSERT INTO mytable (rowid, other) VALUES (DEFAULT,'a'), (DEFAULT,'b'); This should work on either system. -- Richard Huxton Archonet Ltd -- Sent via pgsq

Re: [SQL] pattern matching with dates?

2011-01-07 Thread Richard Huxton
7;day' FROM d) = 3; That ends up doing a bitmap index scan for me. Of course, it's entirely possible an index on year+month returns too many rows to be useful. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subs

Re: [SQL] concatenate question

2010-12-07 Thread Richard Broersma
On Tue, Dec 7, 2010 at 1:47 PM, Tony Capobianco wrote: > Why did I need to cast both as text though? http://www.postgresql.org/docs/8.3/interactive/release-8-3.html#AEN87134 -- Regards, Richard Broersma Jr. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to y

Re: [SQL] force view column varchar(32) to varchar(128)

2010-11-19 Thread Richard Broersma
o push your data to the new schema. -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Using PL/pgSQL text argument in 'IN (INT,INT,...)' clause [re-post]

2010-10-25 Thread Richard Broersma
should work: UPDATE foo Set x = y WHERE id = ANY( CAST( string_to_array( '1,2,3,4', ',' ) AS INTEGER[] )); -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@po

Re: [SQL] Need help on update.

2010-10-21 Thread Richard Huxton
ble1 SET nm = table2.nm FROM table2 WHERE table1.sn = table2.sn; SELECT * FROM table1; ROLLBACK; Be careful with aliasing the target of the update (table1 in this case). As another poster has discovered, that counts as another table in your join. -- Richard Huxton Archonet Ltd -- Sent v

Re: [SQL] pl/python out params

2010-08-07 Thread Richard Albright
first define a custom type, then drop the out parameters. create type mytype as ( i integer, j text ); create or replace function outtest() returns mytype as $BODY$ i = 1 j = 'something' return ( i, j ) $BODY$ language plpythonu; select * from outtest(); i | j ---+--- 1 | someth

Re: [SQL] Domains, casts, and MS Access

2010-08-04 Thread Richard Broersma
> native postgres driver, does any better? >From my limited experience, I believe is does do better. The following blogs as a few entries about using Base: http://www.postgresonline.com/journal/archives/167-Importing-data-into-PostgreSQL-using-Open-Office-Base-3.2.html -- Rega

Re: [SQL] Delete rules

2010-08-04 Thread Richard Broersma
rd to get correct. They sometimes do unexpected things. It looks like the CREATE Trigger FOR EACH STATEMENT is better suited to do what you want: "In addition, triggers may be defined to fire for a TRUNCATE, though only FOR EACH STATEMENT." -- Regards, Richard Broersma Jr. Visit the L

Re: [SQL] Domains, casts, and MS Access

2010-08-04 Thread Richard Broersma
6-08 14:39:43 PDTSTATEMENT: BEGIN; UPDATE "public"."structures" SET "scoped"=E'-1' WHERE "buildingfunction" = E'CRANE OPERATOR STATION' AND "xmin" = 20497 -06-08 14:39:43 PDTLOG: duration: 0.000 ms statement: ROLLBA

Re: [SQL] Domains, casts, and MS Access

2010-08-04 Thread Richard Broersma
I could find. I know that there are a couple of options that affect the representation of Booleans in the odbc driver. I'm not sure it will do what you need though. However, here is the official documentation: (hopefully it helpful) http://psqlodbc.projects.postgresql.org/ -- Regard

Re: [SQL] Domains, casts, and MS Access

2010-08-04 Thread Richard Broersma
; bareword 1 and 0 instead of 't' and 'f'. For the sake of compatibility > (especially bareword integers in queries), I've defined a 'sybit' type > in postgres to be a domain. One thought would be see if ODBC configuration options will achieve this for you. H

Re: [SQL] Aggregates (last/first) not behaving

2010-07-22 Thread Richard Huxton
Using the real, windowing versions of first/last in 8.4+ will still require sorting the whole table (AFAICT) so isn't likely to be much improvement over a self-join here. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

Re: [SQL] grouping subsets

2010-07-22 Thread Richard Huxton
with an outer query that compares mycode=prev_code to get a run length. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Aggregates (last/first) not behaving

2010-07-22 Thread Richard Huxton
uot; and "last value I happened to find". If you want the earliest/latest timestamp from each day, use min() and max(). -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] what does this do

2010-06-10 Thread Richard Broersma
ta-types in the alias declaration for all set returning relations with the exception of a set returning function (i.e. store procedure). The from clause has a give-away that this is a set returning function: "jfcs_balancedue('%s')" since it has a parameter. Notice the function

Re: [SQL]

2010-05-21 Thread Richard Broersma
te" = '2010-05-21'::date AND "completio ndate" = '-12-31'::date /* The table was automatically re-queried to find out what the new itemnbr actually is according to its default value. And lastly the former query tha

Re: [SQL]

2010-05-20 Thread Richard Broersma
erial datatype. At-least in recent versions auto increment is recognized by MS-Access just fine (I'm guessing this is due to the Return clause which the ODBC driver automatically calls). -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postg

Re: [SQL] How to get CURRENT_DATE in a pl/pgSQL function

2010-05-18 Thread Richard Broersma
IN >    curtime := 'CURRENT_DATE'; >    LOOP I'm not "up" on my pl/pgSQL, but isn't CURRENT_DATE a literal value so it shouldn't to be enclosed in single quotes? Another idea would be to: CAST( now() AS DATE ) -- Regards, Richard Broersma Jr. V

Re: [SQL] Greetings folks, dumb question maybe?

2010-05-12 Thread Richard Broersma
FROM T p2082849b(> WHERE n <= 10000) p2082849b-> SELECT n,c,d FROM T; INSERT 0 10001 -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list

[SQL] Celko take on EAV

2010-05-07 Thread Richard Broersma
I'm rereading my Joe Celko's SQL Programming Style and I noticed an interesting comment regarding the EAV model (of course he discourages its use): "There are better tools for collecting free-from data." What tools was he referring to? -- Regards, Richard Broersma Jr. V

Re: [SQL] graphing time series data

2010-04-14 Thread Richard Broersma
discrepencylist ds, opendays WHERE opendays.day >= ds.discstartdt AND opendays.day <= LEAST('now'::text::date, ds.resolutiondate) GROUP BY opendays.day, ds.resolvingparty ORDER BY opendays.day, ds.resolvingparty; -- Regards, Richard Broersma Jr. Visit the Los Angele

Re: [SQL] Table Design for Hierarchical Data

2010-04-06 Thread Richard Broersma
raints. While 8.4 has CTE's which are good for querying adjacency list tree, we need to wait for write-able CTE's (maybe 9.1?) to preform all of the possible tree modifications. -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.post

Re: [SQL] Avoiding cycles in a directed graph

2010-03-16 Thread Richard Huxton
trigger? If you don't expect this to be common, maybe you could fix the concurrency issue by taking a table-wide lock that locks out other writers. Surely SELECT FOR UPDATE on the parents would be sufficient? If there's no overlap between (currently non-cyclic) graphs being altered

Re: [SQL] Avoiding cycles in a directed graph

2010-03-16 Thread Richard Huxton
child" isn't in that set. 4. If there is a cycle, raise an error (which will abort the insert or update) If you have a "before" trigger, then step 4 could return NULL rather than raise an error. That would just skip the insert. Also, step #1 could be done with a CHECK const

Re: [SQL] installing uuid generators

2010-03-16 Thread Richard Huxton
es to go through the issues I had building the lib etc.) I'd be surprised if there wasn't a -contrib or -extras rpm with the relevant files. The community rpms should have them if the "official" Suse ones don't -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql ma

Re: [SQL] installing uuid generators

2010-03-16 Thread Richard Huxton
is being executed? It's also worth checking that the pg_config you are executing is the one associated with postgresql-8.4.2 - make sure your PATH is set appropriately. I'm not sure that it would give this error, but I keep making the mistake of setting my PATH with the three version

Re: [SQL] check constraint on multiple tables?

2010-03-03 Thread Richard Broersma
this hierarchy will have overlap, this is an indication of a violation of the second normal form (I believe). -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.or

Re: [SQL] check constraint on multiple tables?

2010-03-03 Thread Richard Broersma
. Each cabin is defined by a category according the set in the cabin_category table. -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make chang

Re: [SQL] check constraint on multiple tables?

2010-03-03 Thread Richard Broersma
On Wed, Mar 3, 2010 at 7:02 AM, Louis-David Mitterrand wrote: > What is the best solution? Adding an id_ship to 'cabin'? Or check'ing > with a join down to 'ship'? (if possible). Can you post simplified table definitions for the relations involved? -- Regar

Re: [SQL] kind of RULE on SELECT depending on existence of a WHERE condition

2010-03-01 Thread Richard Huxton
You will need to create the function with SECURITY DEFINER permissions, as a user who can read from the table. Make sure the application cannot read from the table and has to use the function. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To

Re: [SQL] kind of RULE on SELECT depending on existence of a WHERE condition

2010-03-01 Thread Richard Huxton
return NOTHING. Is there a way to achieve this? Not quite the way you suggest. You could build a series of views with the WHERE conditions built in to them, and grant permissions on those though. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org

Re: [SQL] Unable to get UPDATE ... FROM syntax correct

2010-02-19 Thread Richard Huxton
On 19/02/10 10:58, Gordon Ross wrote: On 19/02/2010 10:36, "Richard Huxton" wrote: Works here - are you sure you don't have any triggers interfering? Doh ! *blush* Yes, I did, to stop anyone tampering with the audit table ;-) There you go - it worked :-) -- Richard Hu

Re: [SQL] sintax error

2010-02-19 Thread Richard Huxton
of PostgreSQL from the last few years supports "dollar quoting". http://www.postgresql.org/docs/8.4/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS That lets you do: create or replace function ... as $$ ... IF myvar = 'normal-quoting works here' THEN ... $$ language plpgsql; -- Ric

Re: [SQL] Unable to get UPDATE ... FROM syntax correct

2010-02-19 Thread Richard Huxton
(-1,1), (-2,2), (-3,3); UPDATE audit SET key = extension.number FROM extension WHERE audit.record_id = extension.number; SELECT * FROM audit ORDER BY id; ROLLBACK; CREATE TABLE INSERT 0 3 INSERT 0 3 UPDATE 3 id | record_id | key +---+- 1 | 1 | 1 2 | 2 | 2 3 |

Re: [SQL] Referencing external table in update/insert triggers

2010-02-18 Thread Richard Huxton
r, for this case you can just do an update with an extended where clause: UPDATE t2 ... WHERE t2f1=NEW.d1 AND NEW.t1f4 > t2.t2f4 No need for the IF. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscript

Re: [SQL] 'image' table with relationships to different objects

2010-02-09 Thread Richard Huxton
l.loc_name AS linked_name FROM images i2 JOIN location_images li ON i2.img_id = li.img_id JOIN locations l ON li.loc_id = l.loc_id ... You could do something clever with inheritance on the joining tables, but it's better to keep things simple imho. -- Richard Huxton Archonet Ltd -- Sent via pg

Re: [SQL] Fwd: conditional rule not applied

2010-01-06 Thread Richard Broersma
mpt to perform an update. The official use for update-able views is for limiting the results from a *single* base table. Having said all of this, it is possible to do what your describing. I've seen Keith Larson make update-able views from a composite of selected UNION and FULL OUT JOIN quer

[SQL] CREATE SERVER - what is this?

2009-11-24 Thread Richard Broersma
I noticed a few new SQL references in the manual: CREATE SERVER CREATE FOREIGN DATA WRAPPER, CREATE USER MAPPING Is this similar to DBI-Link? -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing

Re: [SQL] ORDB and dot-notation query

2009-11-10 Thread Richard Broersma
> ERROR: schema "adress" does not exist > > Do somebody have some problem and how to fix this? Are you sure that you didn't just misspell address? -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent

Re: [SQL] Learning about WITH RECURSIVE

2009-11-04 Thread Richard Broersma
On Wed, Nov 4, 2009 at 2:11 PM, Tom Lane wrote: > Richard Broersma writes: >> Can anyone one explain why a "WITH RECURSIVE" query has the same >> results regardless whether UNION or UNION ALL is specified? > > Well, if the rows are all different anyway, UNION

Re: [SQL] Learning about WITH RECURSIVE

2009-11-04 Thread Richard Broersma
On Wed, Nov 4, 2009 at 2:11 PM, Tom Lane wrote: > Richard Broersma writes: >> Can anyone one explain why a "WITH RECURSIVE" query has the same >> results regardless whether UNION or UNION ALL is specified? > > Well, if the rows are all different anyway, UNION

[SQL] Learning about WITH RECURSIVE

2009-11-04 Thread Richard Broersma
> SELECT sum(n) FROM t; sum -- 5050 (1 row) broersr=> WITH RECURSIVE t(n) AS ( broersr(> VALUES (1) broersr(> UNION ALL broersr(> SELECT n+1 FROM t WHERE n < 100 broersr(> ) broersr-> SELECT sum(n) FROM t; sum -- 5050 (1 row) -- Regards, Richard

Re: [SQL] slow count(CASE) query

2009-10-30 Thread Richard Huxton
to replace our UNIONs. You'll want a unique constraint on length_codes.code and you should really write a custom trigger to make sure none of the min_length..max_length ranges overlap. In practice, you're probably only setting this table up once so might not bother. -- Ri

Re: [SQL] Table Valued Parameters

2009-10-24 Thread Richard Huxton
E plpgsql; SELECT print_array(ARRAY[ '(1,"abc")'::typ1, '(2,"def")'::typ1 ]); SELECT print_array(ARRAY[ '(1,"abc")', '(2,"def")' ]::typ1[]); ROLLBACK; -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Problem with return type of function ??? (corrected)

2009-10-22 Thread Richard Huxton
number'::regclass; > > plpgsql isn't tremendously good with rowtypes that contain dropped > columns. I thought that only applied to columns dropped after the function was defined. Live and learn. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list

Re: [SQL] Problem with return type of function ???

2009-10-22 Thread Richard Huxton
ial_number > > That seems to be some bug in Postgres ? If you look earlier you should see a line that says something like: "set search_path = rma, ..." Makes it irritating to cut+paste sections of the dump, but it works just fine. -- Richard Huxton Archonet Ltd --

Re: [SQL] Problem with return type of function ???

2009-10-22 Thread Richard Huxton
Denis BUCHER wrote: > Richard Huxton a écrit : >> The other thing you could try is printing out row before returning it: >> RAISE NOTICE 'row = %', row; >> RETURN NEXT ROW; >> It might be you've not got what you were expecting. > > Thanks a

Re: [SQL] Problem with return type of function ???

2009-10-22 Thread Richard Huxton
. ROLLBACK we can change things until we see the problem. The other thing you could try is printing out row before returning it: RAISE NOTICE 'row = %', row; RETURN NEXT ROW; It might be you've not got what you were expecting. -- Richard Huxton Archonet Ltd -- Sent via p

Re: [SQL] Problem with return type of function ???

2009-10-22 Thread Richard Huxton
Denis BUCHER wrote: > Richard Huxton a écrit : >>> ERREUR: wrong record type supplied in RETURN NEXT >>> CONTEXTE : PL/pgSQL function "hds_bw_find_sn_live" line 26 at return next >>> >>> Does someone maybe knows what it could be ? >>>

Re: [SQL] Problem with return type of function ???

2009-10-22 Thread Richard Huxton
PLACE FUNCTION rma.find_sn_live (varchar(30)) RETURNS SETOF >> rma.serial_number This is a different function. Function "hds_bw_find_sn_live" has the wrong type for its "return next". -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pg

Re: [SQL] Existential quantifier

2009-10-09 Thread Richard Albright
you could use distinct on select distinct on (fs.film.title, fs.film.year ) title, year from fs.film left join fs.star on fs.film.id = fs.star.film where fs.star.last = 'Sheen'; On Sat, 2009-10-10 at 00:53 +0200, Dag-Erling Smørgrav wrote: > Consider the attached schema (filmstars.sql), which i

Re: [SQL] Function Anomaly?

2009-10-08 Thread Richard Huxton
---+---+-- > (0 rows) You've defined getnote() as returning a single getnote_t value I think you probably want "RETURNS SETOF getnote_t". -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Encryption in the tables of a Postgres 7.3.2 database

2009-09-11 Thread Richard Huxton
t splitting where the files are stored. That might involve setting up symlinks, I can't remember if 7.3 supported tablespaces. If you do put some files on the encrypted filesystem and some on the unencrypted one make sure you don't start PG until both are available. I don't kno

Re: [SQL] trigger failed to identify the partions

2009-09-09 Thread Richard Huxton
two rows. > But to work with hibernate I need the return NEW statement. Hmm - not sure I can see a way around this. Maybe someone else who knows Hibernate can help. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make change

Re: [SQL] trigger failed to identify the partions

2009-09-09 Thread Richard Huxton
p_subdtls_01" does not exist I think you missed the word "column" in the error message (easy to do, you know you are naming tables). You've missed the quotes around the partition-names so it's trying to find a column on a table that matches. dateTable := 'coll_fp_su

Re: [SQL] Problems when copy data from dump file

2009-08-06 Thread Richard Huxton
ext \. Why not just load the dump file into PostgreSQL? Why are you trying to copy+paste if you want the entire dump? -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Problems when copy data from dump file

2009-08-06 Thread Richard Huxton
ould be if I just can type the table name. There is a variable called "search_path" which controls what schemas are checked for tables, functions etc. If you have two tables with the same name but different schemas you'll need to use the . format though. SET search_path = public

Re: [SQL] Problems when copy data from dump file

2009-08-04 Thread Richard Huxton
27;t know how you do that, but it should be in the manual. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Problems when copy data from dump file

2009-08-04 Thread Richard Huxton
he end of lines when it's expecting "\n". The postgresql version is 7.4.17. Might want to set aside some time to upgrade in the near future - you're missing four full versions since 2003. At the very least, upgrade to 7.4.25 at your earliest convenience. -- Richard

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Richard Huxton
Glenn Maynard wrote: On Thu, Jul 23, 2009 at 2:41 AM, Richard Huxton wrote: Ah [cue light-bulb effect], I think I understand. Your function isn't in the database is it? Surely your application knows if it's issuing BEGIN..COMMIT? I'm writing a Python library call. It has no i

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-22 Thread Richard Huxton
Glenn Maynard wrote: On Thu, Jul 23, 2009 at 1:31 AM, Richard Huxton wrote: - Let me use SAVEPOINT outside of a transaction, You are never outside a transaction. All queries are executed within a transaction. "Transaction block", then, if you insist. I think this is the ro

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-22 Thread Richard Huxton
ter, I'll probably end up dropping out of the ORM and using some uglier SQL to work around this, but this is so trivial that it's silly to have to do that. I can't do it within the ORM; it doesn't have the vocabulary. The ORM can't control transactions, can't call fu

Re: [SQL] De-duplicating rows

2009-07-17 Thread Richard Huxton
earliest duplicates WHERE email=tgt_email AND create_date > tgt_date; -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Moving text columns, when it actually is large

2009-07-09 Thread Richard Huxton
, transplant the pointer rather than actually copy the data? If they are large-objects (stored via the lo_xxx interface) yes. If not, no. I take it the large blob of xml is one of the fields that you are classifying as common? -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql

Re: [SQL] left outer join on more than 2 tables? (UNCLASSIFIED)

2009-06-16 Thread Richard Broersma
flavors are available also). -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] left outer join on more than 2 tables?

2009-06-16 Thread Richard Broersma
*) more since it helps to correctly express the idea that we are counting rows per group and not cm.id(s) per group. -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgre

Re: [SQL] left outer join on more than 2 tables?

2009-06-16 Thread Richard Broersma
have proposed; > > SELECT >    R.region_name, >    Count(*) AS RegionComplaints > FROM >    Region AS R >        LEFT JOIN City AS Ci >            LEFT JOIN Complaint AS Cm ON Ci.id = Cm.city_id >      ON R.id = C.region_id > GROUP BY >    R.region_name; Yup, it produces the s

Re: [SQL] left outer join on more than 2 tables?

2009-06-16 Thread Richard Broersma
on_name, Count(*) AS RegionComplaints FROM Region AS R LEFT JOIN City AS Ci ON R.id = C.region_id LEFT JOIN Complaint AS Cm ON Ci.id = Cm.city_id GROUP BY R.region_name; -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgr

Re: [SQL] polymorphic function in 7.4 vs. 8.3

2009-06-11 Thread Richard Rosenberg
LANGUAGE 'plpgsql' VOLATILE; Oh well, I'm glad I tested the approach out before going too far down this road. Thanks again for your timely help. Richard -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] polymorphic function in 7.4 vs. 8.3

2009-06-11 Thread Richard Rosenberg
: . . . select into some_rec * from dd_test(some_rec) as (id int4, descr text); . . . Throws this:  ERROR: column "some_rec" does not exist SQL state: 42703 Context: PL/pgSQL function "test1_trg" line 7 at select into variables Sorry for the earlier typo(s), and t

[SQL] polymorphic function in 7.4 vs. 8.3

2009-06-11 Thread Richard Rosenberg
), but throws the error on the machine I am forced to work with, which is running version 7.4. I realize that polymorphic functions were pretty new in v7.4, is there a workaround or am I making a silly mistake? Or both? Incidentally, I get the same error when I change the polymorphic function&#

Re: [SQL] 'cost' and 'rows' for volitile function

2009-06-08 Thread Richard Huxton
Rob Sargent wrote: Richard Huxton wrote: If your functions are all called at the top-level then indeed it doesn't matter. At a low level though, telling the planner function F1 costs 1000 times more than F2 is useful. What scares me about this is that for function such as the one

Re: [SQL] 'cost' and 'rows' for volitile function

2009-06-08 Thread Richard Huxton
Rob Sargent wrote: Richard Huxton wrote: Rob Sargent wrote: pg-admin is showing 'COST 100' and 'ROWS 1000' for my explicitly VOLATILE functions. Thanks for the pointer back to CREATE FUNCTION docs. That would have told me that those value are indeed the defaults.

Re: [SQL] Type inheritance

2009-06-06 Thread Richard Broersma
store. Its kind-of like EAV for a column instead of a table. -- Regards, Richard Broersma Jr. Visit the Los Angeles PostgreSQL Users Group (LAPUG) http://pugs.postgresql.org/lapug -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] Need help combining 2 tables together

2009-05-22 Thread Richard Ekblom
Hello I have frequently encountered the need of combining two tables into one. First, please take a look at the following table setups... CREATE TABLE topics ( id SERIAL PRIMARY KEY, topic TEXT NOT NULL ); CREATE TABLE messages ( id SERIAL PRIMARY KEY, topic INTEGER REFERENCES topics(

  1   2   3   4   5   6   7   8   9   10   >