[SQL] Speeding up schema changes

2007-09-03 Thread Stefan Arentz
Is there a way to speed up simple schema changes like ... ALTER TABLE foo ADD COLUMN bar CHAR(64); ... where foo already contains millions of records? On a live database changes like this can take hours. Even when the database is idle. Is there a better way to do this? S. --

Re: [SQL] Speeding up schema changes

2007-09-03 Thread Gregory Stark
"Stefan Arentz" <[EMAIL PROTECTED]> writes: > Is there a way to speed up simple schema changes like ... > > ALTER TABLE foo ADD COLUMN bar CHAR(64); > > ... where foo already contains millions of records? > > On a live database changes like this can take hours. Even when the > database is idle.

[SQL] Constraints for grouping

2007-09-03 Thread PostgreSQL Admin
I have a question that I've thought in my head about using triggers, but I figure to ask people that do SQL more than I. So, I have a table that I want two columns. (1) A featured column which is for only 1 row, once it switched to another row than all other rows must be false title

[SQL] Execute SQL statements with 'context'/predefined variables

2007-09-03 Thread blay bloo
I was wondering if it is possible to set the 'context' for running an sql command: For example, say you have a rule which upon update to table TEST of type [a int, b varchar(10), c varchar(50)]: INSERT INTO Log(a * 5, substring(b,0,2), randomize(c)) So an update of (5, 'hello', 'world') will add

Re: [SQL] Constraints for grouping

2007-09-03 Thread Richard Broersma Jr
--- PostgreSQL Admin <[EMAIL PROTECTED]> wrote: > I have a question that I've thought in my head about using triggers, but > I figure to ask people that do SQL more than I. So, I have a table that > I want two columns. > > (1) A featured column which is for only 1 row, once it switched to > anoth

Re: [SQL] Constraints for grouping

2007-09-03 Thread Richard Broersma Jr
OOPS! --- Richard Broersma Jr <[EMAIL PROTECTED]> wrote: > CREATE UNIQUE INDEX Only_one_row_true > ON Your_table ( featured ) >WHERE featured = true; > > Or if you want to only allow 1 featured article per catagory then: > > CREATE UNIQUE INDEX Only_one_row_true_per_catagory >

Re: [SQL] Execute SQL statements with 'context'/predefined variables

2007-09-03 Thread chester c young
> I was wondering if it is possible to set the 'context' for running an > sql command Oracle has a Context('varname') that returns the value of varname for the session. to best of my knowledge pg has nothing like this. > I guess bottom line, is it possible to execute a bunch of SQL > statements

Re: [SQL] Constraints for grouping

2007-09-03 Thread PostgreSQL Admin
> --- Richard Broersma Jr <[EMAIL PROTECTED]> wrote: > >> CREATE UNIQUE INDEX Only_one_row_true >> ON Your_table ( featured ) >>WHERE featured = true; >> >> Or if you want to only allow 1 featured article per catagory then: >> >> CREATE UNIQUE INDEX Only_one_row_true_per_catag

[SQL] Cast on character columns in views

2007-09-03 Thread Luiz K. Matsumura
Hello, I have a scenario like this: CREATE TABLE table1 ( id serial NOT NULL, col1 character varying(30), CONSTRAINT pk_table1 PRIMARY KEY (id) ); CREATE TABLE table2 ( fk_table1 integer, type1 character(3), id serial NOT NULL, CONSTRAINT pk_table2 PRIMARY KEY (id) ); CREATE TABLE table

Re: [SQL] Execute SQL statements with 'context'/predefined variables

2007-09-03 Thread chester c young
... > When you say use rules to inject constants, how would I go about > doing this? Could you maybe give a brief example? create view tab1_dml as select * from tab1; -- note: -- CONSTANT1 = 8 -- CONSTANT2 = 15 create or replace rule tab1_insert as on insert to tab1_dml do instead( ins

Re: [SQL] Cast on character columns in views

2007-09-03 Thread Richard Broersma Jr
--- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: > CREATE VIEW view1( id, col1, type1, type2) AS > SELECT table1.id, >table1.col1, >CAST( table2.type1 AS CHARACTER( 3 )), >NULL > FROM table1 > JOIN table2 ON table2.fk_table1 = table1.id > UNION ALL > SELECT table1.id,

Re: [SQL] Request into several DBMS simultaneously on DDL and DML

2007-09-03 Thread Dmitry Turin
DT> As result, __new type of system information__ appears: DT> field, refering to other field by foreign key, DT> has additional bit except own value - DT> bit specifies, whether record, to which it refers, DT> is in the same or in other database. DT> It's necessary to not signalize about break of

[SQL] Difference between "foo is false" and "foo=false"? Partial index on boolean.

2007-09-03 Thread Bryce Nesbitt
Expecting to save 4 seconds per query, I built a partial index on a table, and was surprised that it did not work.  Could someone explain the difference between "foo=false" and "foo is false", for a boolean type column? stage=# create index eg_ve_reconciled_partial on eg_vehicle_event (reconci

Re: [SQL] Difference between "foo is false" and "foo=false"? Partial index on boolean.

2007-09-03 Thread Tom Lane
Bryce Nesbitt <[EMAIL PROTECTED]> writes: > Could someone explain > the difference between "foo=false" and "foo is false", for a boolean > type column? They give different results for NULL --- specifically, NULL for the former and FALSE for the latter. Don't blame me, it's in the spec...

Re: [SQL] Difference between "foo is false" and "foo=false"? Partial index on boolean.

2007-09-03 Thread Bryce Nesbitt
Tom Lane wrote: Bryce Nesbitt <[EMAIL PROTECTED]> writes: Could someone explain the difference between "foo=false" and "foo is false", for a boolean type column? They give different results for NULL --- specifically, NULL for the former and FALSE for the latter. Don't b

Re: [SQL] Cast on character columns in views

2007-09-03 Thread Luiz K. Matsumura
Richard Broersma Jr wrote: --- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: CREATE VIEW view1( id, col1, type1, type2) AS SELECT table1.id, table1.col1, CAST( table2.type1 AS CHARACTER( 3 )), NULL FROM table1 JOIN table2 ON table2.fk_table1 = table1.id UNION ALL SE