Re: [SQL] Question about index/constraint definition in a table

2013-10-09 Thread David Johnston
David Johnston wrote > > JORGE MALDONADO wrote >> I have a table as follows: >> >> Table Artist Colaborations >> >> * car_id (integer field, primary key) >&

Re: [SQL] Question about index/constraint definition in a table

2013-10-09 Thread David Johnston
you? Also, the car_id field becomes pointless since your new constraint is the true and natural PK. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Question-about-index-constraint-definition-in-a-table-tp5773924p5773925.html Sent from the PostgreSQL - sql

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
not pass a cost-benefit analysis. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Unique-index-VS-unique-constraint-tp5773386p5773434.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postg

Re: [SQL] Advice on defining indexes

2013-10-04 Thread David Johnston
ionship. CREATE TABLE list ( lst_source, lst_date, FOREIGN KEY (lst_source, lst_date) REFERENCES source (src_id, src_date) ...; If a unique constraint (in this case I'd suggest primary key) does not exist for source(src_id, src_date) the create table with the foreign key will fail. David

Re: [SQL] Unique index VS unique constraint

2013-10-04 Thread David Johnston
should be associated only with constraints. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Unique-index-VS-unique-constraint-tp5773386p5773427.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-s

Re: [SQL] Advice on defining indexes

2013-10-04 Thread David Johnston
the different text fields. I would then add an index on art_bday and call it done. You can then write a view/function that performs a full-text search against the functional index (or just create an actual column) for most text searches and have separate criteria filters for country/type/birthda

Re: [SQL] Help needed with Window function

2013-10-02 Thread David Johnston
Create an array of all dates (tags in the example) that match with positive amounts. Negative amounts get their matching tag added to the array as NULL. The provided function looks into the generated array and returns the last (closest to the current row in the frame) non-null date/tag in the

Re: [SQL] postgres subfunction return error

2013-09-27 Thread David Johnston
and toss the temporary variables but that should not impact the semantics. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/postgres-subfunction-return-error-tp5772407p5772627.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via

Re: [SQL] postgres subfunction return error

2013-09-25 Thread David Johnston
on variables. You must manually map the output of the sub-function call query onto the parent variables. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/postgres-subfunction-return-error-tp5772407p5772408.html Sent from the PostgreSQL - sql mailing list ar

Re: [SQL] removing duplicates and using sort

2013-09-16 Thread David Johnston
otherwise your use of "DISTINCT ON" begins to mal-function. I dislike DISTINCT ON generally but do not wish to ponder how you can avoid it, so I'd suggest just turning your query into a sub-query like I show above. David J. -- View this message in context: http://postgresql.104569

Re: [SQL] Using regexp_matches in the WHERE clause

2013-08-29 Thread David Johnston
ot;text[]" instead of a "setof text[]". It makes coding these kinds of queries easier if you know/understand the fact that your matching will never cause more than 1 row to be returned. If zero rows are returned I return an empty array and the normal 1-row case returns the match

Re: [SQL] Criteria to define indexes

2013-07-26 Thread David Johnston
e, composite primary key definitions but in this kind of star-schema setup simply have each foreign key and whatever other searching fields you require maintain their own individual index. David J. P.S. Arguably, having a separate column for each kind of person is a poor design at face value

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
Luca Vernini wrote > 2013/7/8 David Johnston < > polobo@ > > > >> >> This may be a pl/pgsql limitation but you should probably provide a >> complete >> self-contained example with your attempt so that user-error can be >> eliminated. >>

Re: [SQL] Update a composite nested type variable

2013-07-08 Thread David Johnston
read and in assign. > How can I workaround this and update my values? > > Luca. This may be a pl/pgsql limitation but you should probably provide a complete self-contained example with your attempt so that user-error can be eliminated. David J. -- View this message in context: ht

Re: [SQL] UNNEST result order vs Array data

2013-06-20 Thread David Johnston
the usual output. This is, I am pretty such, a usability enhancement that makes easier something that can be done today using CTE/WITH and/or sub-queries. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/UNNEST-result-order-vs-Array-data-tp5760087p5760126.ht

Re: [SQL] Select statement with except clause

2013-05-24 Thread David Johnston
SELECT fldA, fldB, fldC, sum(fldD) AS sum_positive) q1 NATURAL FULL OUTER JOIN (SELECT fldA, fldB, fldC, sum(fldD)*-1 AS sum_negative) q2 WHERE <...> Food for thought. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Select-statement-with-except-clau

Re: [SQL] Select statement with except clause

2013-05-23 Thread David Johnston
"tbl" within the query inside the where clause GROUP BY col1, col2, col3 I do not follow your example enough to provide a more explicit example/solution but this should at least help point you in the right direction. David J. -- View this message in context: http://postgresql.10

Re: [SQL] pivot query with count

2013-04-12 Thread David Johnston
My prior comment simply answers your question. You likely can rewrite your query so that a separate grouping layer is not needed (or rather the group by would exist in the main query and you minimize the case/sub-select column queries and use aggregates and case instead). David J. -- View

Re: [SQL] pivot query with count

2013-04-12 Thread David Johnston
SELECT num_ads, sum(...), sum(...), FROM ( your query here ) GROUP BY num_ads; BTW, While "SELECT '1' "num_ads" is valid syntax I recommend you use the "AS" keyword. '1' AS "num_ads" David J. -- View this message in context: h

Re: [SQL] Query execution based on a condition

2012-12-29 Thread David Johnston
UNION SELECT fields FROM tblTable WHERE condition Respectfully, Jorge Maldonado Not using pure SQL. pl/pgsql provides you access to conditionals and flow control so you should be able to create a function to do precisely what you need. David J.

Re: [SQL] deciding on one of multiple results returned

2012-12-21 Thread David Johnston
a 0 b 0 c 1 a 1 b How do I just choose a preferred element say value 'a' over any other elements returned, that is the value returned is from a subquery to a larger query? Thanks. ORDER BY (with a LIMIT depending on circumstances) David J.

Re: [SQL] Joining several rows into only one

2012-11-28 Thread David Johnston
Joining several rows into only one > > You need to use the array_agg() and array_to_string() functions. > Or you can skip directly to the "string_agg(expression, delimiter)" function. See http://www.postgresql.org/docs/9.2/interactive/functions-aggregate.html for more informa

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread David Johnston
turns its own record. Even though only one record is ever returned without the "g" option the function itself is the same and still is defined to return a set. David J. -- 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] organizing cron jobs in one function

2012-11-19 Thread Louis-David Mitterrand
On Mon, Nov 19, 2012 at 08:31:10AM +0800, Craig Ringer wrote: > On 11/19/2012 01:11 AM, Louis-David Mitterrand wrote: > > On Sun, Nov 18, 2012 at 07:27:54PM +0800, Craig Ringer wrote: > >> On 11/18/2012 12:19 AM, Louis-David Mitterrand wrote: > >>> Hi, > >>&g

Re: [SQL] organizing cron jobs in one function

2012-11-18 Thread Louis-David Mitterrand
On Sun, Nov 18, 2012 at 07:27:54PM +0800, Craig Ringer wrote: > On 11/18/2012 12:19 AM, Louis-David Mitterrand wrote: > > Hi, > > > > I'm planning to centralize all db maintenance jobs from a single > > pl/pgsql function called by cron every 15 minutes (highest fre

[SQL] organizing cron jobs in one function

2012-11-17 Thread Louis-David Mitterrand
Hi, I'm planning to centralize all db maintenance jobs from a single pl/pgsql function called by cron every 15 minutes (highest frequency required by a list of jobs). In pseudo code: CREATE or replace FUNCTION cron_jobs() RETURNS void LANGUAGE plpgsql AS $$ DECLARE rec record; BEGIN /*

Re: [SQL] replace text occurrences loaded from table

2012-10-30 Thread David Johnston
. Since you have not shared the true context of your request no alternatives can be suggested. Also, your ability to implement certain algorithms is influenced by the version of PostgreSQL that you are running and which you have also not provided. David J. -- 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] pull in most recent record in a view

2012-10-28 Thread David Johnston
rt/update/delete triggers. A boolean flag along with a partial index can work instead of an actual table in some cases. If using a table only the pkid needs to be stored, along with any desired metadata. It probably isn't worth the effort until you actually do encounter performance proble

Re: [SQL] Insert strings that contain colons into a table

2012-10-19 Thread David Johnston
;colon" has nothing to do with it. It appears that "wwn_end" is defined as an array and not a simple text value. You need to provide the table definition for "wwn". This is a section in the documentation regarding arrays but I am guessing the use of an array in this situatio

Re: [SQL] Trigger triggered from a foreign key

2012-10-19 Thread David Johnston
o determine how a DELETE was issued. The trigger itself would seem to be possibly exhibit concurrency issues, meaning that in certain circumstances the last record could be deleted. You may want to add explicit locking to avoid that possibility. That or figure out a better way to accompl

Re: [SQL] How to make this CTE also print rows with 0 as count?

2012-10-06 Thread David Johnston
zcount, 0) AS zcount FROM (cal CROSS JOIN id_master) master LEFT JOIN datavalues USING (id, stamp) Also, the mixing of multiple FROM relations and JOINs is confusing. In particular is the fact the JOIN takes precedence over the "," in FROM "A JOIN clause combines two FROM items.

Re: [SQL] String Search

2012-10-04 Thread David Johnston
ions") as well as PostgreSQL's full text search capability since both are "string" related. http://www.postgresql.org/docs/9.2/interactive/functions.html http://www.postgresql.org/docs/9.2/interactive/textsearch.html My best guess is you want to learn about substring functions and/

Re: [SQL] Calling the CTE for multiple inputs

2012-10-04 Thread David Johnston
L JOIN (SELECT ROW_NUMBER() OVER () AS index, generate_series(...) AS long_high) long_high_rel You may (probably will) need to move the generate_series into a FROM clause in the sub-query but the concept holds. Then in the main query you'd simply... AND lat BETWEEN lat_low AND lat_hi

Re: [SQL] Help in accessing array

2012-10-02 Thread David Johnston
there. Each, "unnest(array)" call explodes one dimension. Consider wraping things in a function to make the code cleaner. David J. -- 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] [noob] How to optimize this double pivot query?

2012-10-01 Thread David Johnston
one time per id and create a materialized view - basically insert the results of the query into a physical table and for live usage query that table. This is a cache and comes with all the benefits and downsides thereof. David J. On Oct 1, 2012, at 21:13, Robert Buck wrote: > So as you

Re: [SQL] [noob] How to optimize this double pivot query?

2012-10-01 Thread David Johnston
. As a second (not necessarily mutually exclusive) alternative: install and use the hstore extension. David J. Thanks in advance, Bob select t.id_name, max(t.begin_time) as begin_time, max(t.end_time) as end_time, max(case when (m.id_name = 'package-version&#

Re: [SQL] Reuse temporary calculation results in an SQL update query [SOLVDED]

2012-09-30 Thread David Johnston
.. FROM ( WITH final_result AS ( SELECT pkid, FROM tbl WHERE ... ) -- /WITH SELECT pkid, FROM final_result ) src -- /FROM WHERE src.pkid = tbl.pkid ; If you provide an actual query better help may be provided. David J. -- Sent via pgsql-sql mailing list (pg

Re: [SQL] Need help with a special JOIN

2012-09-29 Thread David Johnston
, syntax not tested) Select objectid, name, coalesce(actuals.value, defaults.value) From objects cross join (select ... From attributes ...) as defaults Left join attributes as actuals on ... Build up a master relation with all defaults then left join that against the attributes taking the matche

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread David Johnston
are allowed to use a FROM clause with UPDATE so if you can figure out how to write a SELECT query, including a CTE if needed, you can use that as your cache. An immutable function should also be optimized in theory though I've never tried it. David J. -- 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]

2012-09-22 Thread David Johnston
solve > this issue without affecting the ORDER BY it already has ? > > Regards, > Jorge Maldonado Since you are forced to include the ON field(s) first in the ORDER BY if you want a different final sort order you will have to use either a sub-select or a CTE/WITH to execute the above query then in the outer/main query you can perform a second sort. David J.

Re: [SQL] ERROR: missing FROM-clause entry for table "new"

2012-09-13 Thread David Johnston
d have the behavior, if different section numbers. In short the whole "NEW.name" is a variable and you need to build the statement the same way you would with any user-defined variable. David J.

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
well though if you are going to filter/sort on initial date frequently (by itself) then it likely wants its own index anyway and having two separate indexes would be better. David J. On Sep 9, 2012, at 20:56, JORGE MALDONADO wrote: > Firstly, who should I reply to, you or the list? > Yo

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Sunday, September 09, 2012 1:26 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query with LIMIT clause I have the following records that I get from a query, the fields are date type in d

Re: [SQL] returning values to variables from dynamic SQL

2012-09-08 Thread David Johnston
ments.html#PLPGS QL-STATEMENTS-EXECUTING-DYN Basically when you use "EXECUTE" you do not embed the "INTO" as part of the SQL query but rather INTO becomes a modifier of the EXECUTE itself: EXECUTE 'some query' INTO {variables} David J. -- 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] Need to Iterate the record in plpgsql

2012-09-06 Thread David Johnston
he column name and lookup the corresponding column on "test3_table" to determine the data type associated with the value. I do not know the specific syntax to do this but the information is available in the database. It helps to provide the why behind what you are trying to accomplish and just ask whether some behavior can be accomplished or emulated. David J. -- 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] prepared statement in crosstab query

2012-08-31 Thread David Johnston
NY ( split_to_array($$'1,3,5,7,11'$$, ',')::int[] ) In this case you pass a single delimited string (replacing the $-quoted literal shown) with whatever values you want as a single parameter/input. Convert that string to an array and then use the =ANY array operator to match th

Re: [SQL] Error: Template Id should be teh identifier of a template - help

2012-08-17 Thread David Johnston
tions that the triggers sets forth so the trigger performs a "RAISE ERROR 'Template Id should be the identifier of a template'". You will need to speak with someone responsible for maintaining the database. David J. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org

Re: [SQL] [GENERAL] Indexing question

2012-08-15 Thread David Johnston
t;1}. Zero you ignore, 1 you generally put on the same table - though not always, and more-than-one you create a separate table and store multiple values as separate rows instead of as columns. David J. -- 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] join against a function-result fails

2012-07-27 Thread David Johnston
er. With a recursive CTE you can start at the bottom of the trees and only evaluate the needed branches. David J. -- 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] query two tables using same lookup table

2012-07-22 Thread David Johnston
.id_project, n1.name_auth, n2.name_auth From pj Left join t3 as n1 on (id_auth1 = id_auth) Left join t3 as n2 on (id_auth2 = id_auth) ; Full join the two project tables and give aliases to the duplicate id_auth field. Then left join against t3 twice (once for eachid_auth) using yet a another set of

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-12 Thread David Johnston
te the partial index on that. You could also consider creating an updatable view and avoid directly interacting with the three individual tables. You could also just turn event states into a history table and leave the current state on the event table. David J. -- 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] How to solve the old bool attributes vs pivoting issue?

2012-06-27 Thread David Johnston
How would I build a view for this that shows all flags for any company? > When I create this view I'would not know how many flags exist at > execution time. > > > This must be a common issue. > > Is there a common solution, too? > > You should look

Re: [SQL] Need help building this query

2012-06-21 Thread David Johnston
ess) row while unmatched records will have one of the two resultant columns NULLed SELECT tableA.subid_a, tableB.subid_b FROM tableA FULL OUTER JOIN tableB ON (tableA.subid_a = tableB.subid_b) Requires at least version 8.4 David J. -- 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 ordinal_position

2012-06-07 Thread David Johnston
should not meaningfully impact query plan generation and thus it should be no slower than a more direct query. David J. -- 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] defaults in a function

2012-06-06 Thread David Johnston
one is > used as the default. > > Is this possible with plpgsql??? > > Johnf > http://www.postgresql.org/docs/9.0/interactive/sql-createfunction.html ... param_n type DEFAULT value OR ... param_n type = value It is SQL DDL syntax and not specific to the language the function is

Re: [SQL] Lowest 2 items per

2012-06-01 Thread David Johnston
Mike > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql I would recommend using the "RANK" window function with an appropriate partition clause in a sub-query then i

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread David Johnston
0/interactive/functions-aggregate.html Assuming that the users_id field is an integer: SELECT MAX(users_id) FROM users; --NO GROUP BY needed since no other fields are being output... That said, you really should create and attach a sequence so that you can avoid race/concurrency issues. Dav

Re: [SQL] generic crosstab ?

2012-04-24 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Sent: Tuesday, April 24, 2012 5:35 PM To: Samuel Gendler Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] generic crosstab ? Am 24.04.2012 22:08, schrieb Samuel Gendler: On Tue, Apr 24, 2012 at

Re: [SQL] Wrong output from union

2012-03-30 Thread David Johnston
Documented behavior. Please read the section on UNION for the why and the proper alternative syntax: http://www.postgresql.org/docs/9.0/interactive/sql-select.html On Mar 28, 2012, at 7:01, Gary Stainburn wrote: > Hi folks. > > I have two selects which in themselves report what they should.

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

2012-03-19 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Richard Huxton > Sent: Monday, March 19, 2012 4:59 PM > To: David Johnston > Cc: 'Rehan Saleem'; pgsql-sql@postgresql.org > Subject: Re:

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

2012-03-19 Thread David Johnston
You would need to install the "HSTORE" extension to convert the record into a key->value pair then perform the comparison on that. Dave From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Rehan Saleem Sent: Monday, March 19, 2012 3:40 PM To: pgsql-sq

Re: [SQL] help on a function with exception

2012-03-14 Thread David Johnston
> LANGUAGE plpgsql VOLATILE > > CREATE TRIGGER trg_check_PO_extra_date > BEFORE INSERT OR UPDATE > ON extra_values > FOR EACH ROW > EXECUTE PROCEDURE fnc_check_PO_extra_date(); > > You are suppressing the original exception so figuring out what is wrong is very d

Re: [SQL] Invalid syntax for integer

2012-03-13 Thread David Johnston
uot;" SQL state: 22P02 Context: PL/pgSQL function "getsitesbytfid" line 6 at IF The empty-string is not a valid syntax for an integer. You probably want: “IF (distance IS NULL) …”. David J. -- 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] Window function frame clause

2012-02-16 Thread David Johnston
er doesn't make sense with a frame clause...frame is more useful for stuff like calculating rolling sums/averages and the like - where you evaluate fields in the surrounding frame as part of the aggregate. Window functions do not affect the number of rows returned. David J. -- Sent via pgs

Re: [SQL] need help with import

2012-02-15 Thread David Johnston
On Feb 15, 2012, at 21:05, Andreas wrote: > Am 16.02.2012 02:13, schrieb David Johnston: >> -Original Message- >> From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] >> On Behalf Of Andreas >> Sent: Wednesday, February 15, 20

Re: [SQL] need help with import

2012-02-15 Thread David Johnston
-Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Sent: Wednesday, February 15, 2012 8:03 PM To: pgsql-sql@postgresql.org Subject: [SQL] need help with import Hi I get CSV files to import. Th structure is like this. main p

Re: [SQL] update column with multiple values

2012-02-10 Thread David Johnston
ere is not inherent linkage between the "UPDATE" table and the "FROM" table. You can make a correlated sub-query but in this case the is necessary. David J. -- 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] Multiple tables query on Mapserver

2012-02-01 Thread David Johnston
On Feb 2, 2012, at 0:32, tiplip wrote: > I just need gid or id in increasing order start from 0 (or 1), fetching their > original gid (or id) value is not necessary:) > can I do that? > > > David Johnston wrote >> >> >> The general method is to use "

Re: [SQL] Multiple tables query on Mapserver

2012-02-01 Thread David Johnston
;name22' 'address22' 102356 2 > > geom22 >5 5 'name31' 'address31' 102356 3 > > geom31 >6 6 'name32' 'address32' 102356 3 > > geom32 >- - - - --- - > > - > > > can I achieve that results with a single query sentence? and how? > any good ideas will be appricated? > > thanks > > The general method is to use "UNION" but not sure about the changing of the gid and id values... David J. -- 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] must appear in the GROUP BY clause or be used in an aggregate function problem

2012-01-31 Thread David Johnston
nnot readily specify how. Generally you'd simply operate off of "id" and then join in the corresponding first/last names at the outer-most layer of the query. Since you are grouping on "a.id" anyway I would suggest you try it. David J. -- Sent via pgsql-sql mai

Re: [SQL] Update Mass Data in Field?

2012-01-26 Thread David Johnston
he literal value "%ghostsoftware.com" - which obviously is not an e-mail address - and the original "holyghost.org" email address would have been gone beyond easy recovery. Takeaway: test update queries on sample data (or at least within a transaction block) and confirm your res

Re: [SQL] sql query problem

2012-01-17 Thread David Johnston
very simple queries that beginner reference materials cover adequately. Plus, you didn't display any effort in attempting to solve the question yourself; you can do this by showing and and asking what you did wrong as opposed to simply asking for an answer. David J. -- 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] Query Problem... Left OuterJoin / Tagging Issue

2012-01-13 Thread David Johnston
easier. Write out your desired output columns, with table prefixes, and mark whether each on is optional or mandatory. Tables with optional fields are outer joined to other tables, ideally those with only mandatory fields. The corresponding ON clauses should use simple equalities, though you may modify the the comparison values using functions. It sounds like you need to take a step back and do some serious reading on SQL basics, though I'll give you credit for at least trying and being somewhat descriptive of your goal. David J.

Re: [SQL] Unable To Modify Table

2012-01-12 Thread David Johnston
ore complicated to setup and execute compared to the more direct ON UPDATE CASCADE modifier to the FOREIGN KEY. But learning both methods is good. David J. -- 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] Unable To Modify Table

2012-01-12 Thread David Johnston
f the same length. There are many points-of-view regarding whether to use "serial" PRIMARY KEYs but regardless of whether you add one or not you should try and define a UNIQUE constraint on the table by using meaningful values. However, for things like Orders this is generally not possible

Re: [SQL] Unable To Alter Data Type

2012-01-11 Thread David Johnston
On Jan 11, 2012, at 19:30, Carlos Mennens wrote: > On Wed, Jan 11, 2012 at 7:13 PM, David Johnston wrote: >> However, I will say again, you DO NOT WANT TO ACTUALLY DO THIS! >> >> The specific issue is that some US Postal Code begin with a zero ( 0 ) and >> so whenev

Re: [SQL] Unable To Alter Data Type

2012-01-11 Thread David Johnston
as numeric. If you deal with Canada (and maybe Mexico) at all then spaces and letters become acceptable characters within the zip_code. David J. -- 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] Nested custom types: array - unable to insert

2011-12-30 Thread David Johnston
and add additional phone numbers > -- This is where things go awry. > -- > update people > set phone = CAST(ROW(CAST(ROW(111,'home') as > phonenumber_type),ARRAY[(222,'office'), > (333,'cell'),(444,'eve')]::phonenumber_type) >

Re: [SQL] Current transaction is aborted, commands ignored until end of transaction block

2011-12-29 Thread David Johnston
that transaction until that > point. > > Any suggestions? > > Jan > > Start a "savepoint" before each sub-update and rollback to the savepoint if the update fails, and then try again with different data. If it succeeds you then release the savepoint anad mov

Re: [SQL] JDBC Statement.setQueryTimeout : is there plan to implement this?

2011-12-18 Thread David Fetter
be done in a container-independent way (*shudder*). I'm quite sure > that using EJB timers is NOT the right way to do it - they're not > supported by web profile containers and are really intended for > "business level" timers that should be persistent across > rede

Re: [SQL] using a generated series in function

2011-12-17 Thread David Johnston
ction and so must be sourced from somewhere. 2011-11-20 is a literal being fed into a function and so does not require a From clause in order to be evaluated. David J. On Dec 17, 2011, at 11:50, John Fabiani wrote: > As always I respect your insights - Adrian. I do understand what I did wr

Re: [SQL] using a generated series in function

2011-12-15 Thread David Johnston
; > "select ... as week_date where week_date in ..." You are missing a FROM clause for the main select; the only FROM you have is part of the IN target subquery. David J. -- 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 David Johnston
FROM clause as the > query will return unneccessary duplicate > row...the same goes for port2node being Null or 0... > > > thanx in advance > richard > > Two options (one of which may not work for you). 1. Write two queries, one for each table, and union the results. 2

Re: [SQL] prepared statements

2011-12-08 Thread David Johnston
parameter, please regards Pavel Stehule -- Or, in lieu of readily passing arrays from your client API you can always pass a string and modify the query to parse the string into an array. ... users = ANY ( regexp_split_to_array( $1, ',' )::integer[

Re: [SQL] Change in 9.1?

2011-11-22 Thread David Johnston
ng all of: a test case, AND EXPLAIN ANALYZE results, AND a description of what is taken as being a problem, is necessary to provide suggestions. David J. -- 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] clarification about ARRAY constructor implementation

2011-11-11 Thread David Johnston
ession. Going by observation/inference here... An array can never take on the "unknown" type whereas a scalar can. The unknown type can be passed to the Insert where the target's column type can then be used for casting. The array, needing immediate casting, chooses the most

Re: [SQL] Updatable view should truncate table fields

2011-11-08 Thread David Johnston
r data was provided. David J. -- 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] Issue with a variable in a function

2011-11-08 Thread David Johnston
ON ppr_data(aarstall int, frauke int, tiluke int, prosjektkode int[] ) -- Note the change to int[] from int for prosjektkode David J. -- 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 David Johnston
x your process. Done correctly there should be no difference in the end result regardless of how you choose to identify your strings. Don't use pgadmin3 myself so I don't know if what you are looking at would include the E. If it is outputting DDL (I.e., INSERT statements) it might but simple SELECT results should not. David J. -- 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] Create Type with typmod_in

2011-11-04 Thread David Johnston
n explicit cast of a value to varchar(n) causes the value to be truncated to n characters. E.g., '1234567'::varchar(5) -> '12345' How to integrate that knowledge into a type I do not know. David J. >

Re: [SQL] advice on how to store variable attributes

2011-10-25 Thread David Johnston
On Oct 22, 2011, at 10:07, Pavel Stehule wrote: > 2011/10/22 David Johnston : >> On Oct 22, 2011, at 6:41, Linos wrote: >> >>> Hi all, >>>i need a little of advice on what could be the best way to store this >>> information. >>> >&

Re: [SQL] Handling mutliple clients access with views

2011-10-24 Thread David Johnston
l security, for that you need functions. While a view itself will not provide the protected data a function can be used to process data (via RAISE NOTICE) that would otherwise be filtered out in the end result. This is because views are simply re-write rules. David J. -- 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] advice on how to store variable attributes

2011-10-22 Thread David Johnston
On Oct 22, 2011, at 11:39, Linos wrote: > El 22/10/11 14:53, David Johnston escribió: >> On Oct 22, 2011, at 6:41, Linos wrote: >> >>> Hi all, >>> i need a little of advice on what could be the best way to store this >>> information. >>> &

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread David Johnston
lumn and multiple category columns. ( amount_value, amount_unit, amount_category, vendor_id ) If necessary each "amount_value" data type should have it's own table since the processing logic will vary (I.e., you cannot subtract text or Boolean values). You are , in effect,

Re: [SQL] plpgsql function executed multiple times for each return value

2011-10-08 Thread David Johnston
result FROM ... ) SELECT (func.func_result).* FROM func David J.

Re: [SQL] Sorting of data from two tables

2011-09-25 Thread David Johnston
On Sep 25, 2011, at 12:37, "R. Smith" wrote: > On Sat, Sep 17, 2011 at 2:56 PM, David Johnston wrote: >> On Sep 17, 2011, at 9:32, "R. Smith" wrote: >> >> >> What I want to do is do a query joining table A with B and sorting >> firstly on

Re: [SQL] using the aggregate function max()

2011-09-22 Thread David Johnston
omefield = max_date.specialdate; You can use a online query instead of the WITH if desired, same effect. You could also drop the join and use the max_date CTE in a WHERE clause: ... FROM table WHERE table.somefield = (SELECT specialdate FROM max_date) David J -- Sent via pgsql-sql mailing

Re: [SQL] ambiguous local variable name in 9.0 proc

2011-09-21 Thread David Johnston
able value into a different variable. DECLARE tbl_schema_copy VARCHAR; tbl_schema_copy := tbl_schema; . WHERE tbl_schema_copy = e.tbl_schema . David J.

Re: [SQL] Combining several CTEs with a recursive CTE

2011-09-20 Thread David Johnston
> Thomas > > Try sticking the recursive keyword after the "with" if any of the following CTEs are recursive. WITH RECURSIVE normal1 AS () ,recursine1 AS () ,normal2 AS () ,recursine2 AS () SELECT ... David J.

Re: [SQL] Sorting of data from two tables

2011-09-17 Thread David Johnston
also help if you actually provided a detailed description of you goal instead of the generic one quoted above. Given your stated need the query does exactly what you requested. David J.

  1   2   3   4   5   >