Re: [SQL] customising serial type

2005-06-27 Thread Stefan Becker
Am Dienstag, 21. Juni 2005 12:01 schrieben Sie:
> hi,in a table with a serial datatype, how do i get the sequence to start at
> a specific number like 10?


Use START in the create sequence statement.
#

create sequence seq_xeingang increment 1 start 1000;
;

CREATE TABLE xeingang  
( 
  idinteger default nextval('seq_xeingang'),
  buchchar not null, 
  eingdt  date not null,
  jnr   integer not null,
  grp   integer,
  code  integer not null
);



my best regards..

Stefan



---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [SQL] group by function, make SQL cleaner?

2006-03-18 Thread Stefan Becker
this should work, 
#
SELECT date_trunc('day',endtime),count(*)
 FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01'
 GROUP BY  1
  ORDER BY 1;


best regards,


Stefan









Am Donnerstag, 16. März 2006 06:18 schrieb Bryce Nesbitt:
> I've got a working query:
>
> stage=# SELECT date_trunc('day',endtime),count(*)
> FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01'
> GROUP BY  date_trunc('day',endtime)
> ORDER BY date_trunc('day',endtime);
>
>  date_trunc  | count
> -+---
>  2006-02-01 00:00:00 |   253
>  2006-02-02 00:00:00 |   245
>  2006-02-03 00:00:00 |   231
>  2006-02-04 00:00:00 |   313
>  2006-02-05 00:00:00 |   285
>  2006-02-06 00:00:00 |   194
>  2006-02-07 00:00:00 |   229
>  2006-02-08 00:00:00 |   239
>  2006-02-09 00:00:00 |   250
>  2006-02-10 00:00:00 |   245
>  2006-02-11 00:00:00 |   275
>
> Is there a way to eliminate the ugly repeated use of
> date_trunc('day',endtime)?
>
>
> ---(end of broadcast)---
> TIP 1: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to [EMAIL PROTECTED] so that your
>message can get through to the mailing list cleanly

-- 
email: [EMAIL PROTECTED]
tel  : +49 (0)6232-497631
http://www.yukonho.de

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] regarding join

2006-03-25 Thread Stefan Becker
given this.
 create table AA (id serial,name varchar(15));
 create table BB (id serial,name varchar(15));
insert into AA (name) values ('1243f');
insert into AA (name) values ('asdfef');
insert into AA (name) values ('fdbsfd');
insert into AA (name) values ('btgrt');
insert into AA (name) values ('crregsewf');
insert into AA (name) values ('xedrgeef');
insert into BB (name) values ('243f');
insert into BB (name) values ('sdfef');
insert into BB (name) values ('dbsfd');
insert into BB (name) values ('tgrt');
insert into BB (name) values ('rregsewf');
insert into BB (name) values ('edrgeef');

you could try: (if you just need the one column "name")
 select name from AA union select name from BB order by name;



a real nice way to go about this is:
 create table CC (id serial,name varchar(15));
 create table AA() inherits(CC);
 create table BB() inherits(CC);
insert into AA (name) values ('1243f');
insert into AA (name) values ('asdfef');
insert into AA (name) values ('fdbsfd');
insert into AA (name) values ('btgrt');
insert into AA (name) values ('crregsewf');
insert into AA (name) values ('xedrgeef');
insert into BB (name) values ('243f');
insert into BB (name) values ('sdfef');
insert into BB (name) values ('dbsfd');
insert into BB (name) values ('tgrt');
insert into BB (name) values ('rregsewf');
insert into BB (name) values ('edrgeef');


=> select * from AA;
 id |   name
+---
  1 | 1243f
  2 | asdfef
  3 | fdbsfd
  4 | btgrt
  5 | crregsewf
  6 | xedrgeef
(6 rows)

=> select * from BB;
 id |   name
+--
  7 | 243f
  8 | sdfef
  9 | dbsfd
 10 | tgrt
 11 | rregsewf
 12 | edrgeef
(6 rows)

=> select * from CC order by name;
 id |   name
+---
  1 | 1243f
  7 | 243f
  2 | asdfef
  4 | btgrt
  5 | crregsewf
  9 | dbsfd
 12 | edrgeef
  3 | fdbsfd
 11 | rregsewf
  8 | sdfef
 10 | tgrt
  6 | xedrgeef
(12 rows)


by best regards,

Stefan


-- 
email: [EMAIL PROTECTED]
tel  : +49 (0)6232-629542 
   länger klingeln lassen (Weiterleitung aktiv)
fax  : +49 (0)6232-629544
http://www.net-away.de







Am Samstag, 25. März 2006 07:36 schrieb AKHILESH GUPTA:
> hi all,
> below I have created two tables in pgsql with field name as 'name' and 'id'
> as their datatype 'varchar(15)' and 'integer'.
>
> One of the table is:->
> chemical=> select * from test1;
>  name  | id
> ---+
>  akhil |  1
>  b |  2
>  c |  3
>  d |  4
>  e |  5
>  f |  6
> (6 rows)
>
> Another table is:->
> chemical=> select * from test3;
>  name | id
> --+
>  ab   |  1
>  cd   |  2
>  ef   |  3
>  gh   |  4
> (4 rows)
>
> i want the output as:->
> name  | id
> ---+
>  akhil |  1 -from test1 table
>  ab   |  1--from test2 table
>  b |  2-from test1 table
>  cd   |  2--from test2 table
>  c |  3-from test1 table
>  ef   |  3--from test2 table
>  d |  4-from test1 table
>  gh   |  4--from test2 table
>  e |  5-from test1 table
>  f |  6-from test1 table
>
> i have tried all the joins but it makes different fields for different
> tables.
> is there any way out for this kind of output??
> (plz reply asap)urgent.
>
> THANKS IN ADVANCE
>
> --
> Thanks & Regards,
> Akhilesh
> S/W Trainee (EDP),
> NUCHEM Pvt. Ltd.,
> Faridabad(Haryana)
> GSM:-(+919891606064)
>
> "FAILURES CAN BE FORGIVEN BUT AIMING LOW IS A CRIME"


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


[SQL] Is there a solution for "SELECT OR INSERT"

2010-11-28 Thread Stefan Becker
given a simply table table like this:

create table MyTabl 
(id serial,
 lname varchar,
 primary key (id)
)

I am trying to return the Primary-Key for a given
row regardless of the wanted row already being 
in the table.

using something like:

select coalesce 
(
  (select id from MyTabl where lname='wanted'),
  (insert into MyTabl (lname) values ('wanted') returning id)
) as id;

the above doesn't allow the insert..returning even thow
a similar select statement would be okay.
Is there a way to get the ID row OR create a new one in
ONE single statement?

my best regards and thank-you 
for your time

Stefan




-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] how do I to generate a sequence Range or Set of integer constants

2007-02-23 Thread Stefan Becker
dear SQL friends,

What I want to do might be done differantly.  Right now I can't
think of another solution other than a select statement

I would like to create a sequence range of integer constants.  Join
this sequence against a ID Range in a database and look for missing
Id's.   

Another application for this would be to simply populate a database with
say 1000.. Records

Now:  Is there a syntax that allows for the following.

create table XX (id int);
insert into XX (select  xx from "1 to 1000" of integers)

or...

select IntSeq.MissingValues, x.UniqIntId,x.A,x.B,x.C, 
from MyDataTable x
left outer join 
(
 select  MissingValues from "1 to 1000" of integers
) IntSeq on MissingValues=x.UniqIntId


I'm hoping that someone has done this and might be able to
point to some function or methode to do this

Thanks,

Stefan Becker
-- 
email: [EMAIL PROTECTED]
tel  : +49 (0)6232-497631
http://www.yukonho.de

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [SQL] Selecting exactly one row for each column value

2007-03-06 Thread Stefan Becker
Am Dienstag, 6. März 2007 16:03 schrieb Florian Weimer:

>  a | b | c
> ---+---+---
>  5 | 6 | 7
>  2 | 3 | 4
>  1 | 2 | 3

Hi,
couldn't you accomplish this by:

select distinct on (a) * from tablename order by a;


here:

create table tab (a int,b int,c int);
insert into tab values (1,2,3);
insert into tab values (5,6,7);
insert into tab values (1,2,3);
insert into tab values (2,3,4);
insert into tab values (1,2,2);
insert into tab values (2,3,4);

select * from tab;
 a | b | c
---+---+---
 1 | 2 | 3
 5 | 6 | 7
 1 | 2 | 3
 2 | 3 | 4
 1 | 2 | 2
 2 | 3 | 4
(6 rows)

select distinct on (a) * from tab order by a;
 a | b | c
---+---+---
 1 | 2 | 3
 2 | 3 | 4
 5 | 6 | 7
(3 rows)



my regards,


Stefan






-- 
email: [EMAIL PROTECTED]
tel  : +49 (0)6232-497631
http://www.yukonho.de

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [SQL] ROW_NUMBER alias

2007-05-06 Thread Stefan Becker
I might be told off by some better SQL-User here on the list -
still here is my 2 Cents worth

> I needed ROW_NUMBER() in PostGresql and I did find the 'temporary sequence'
> method as a workaround and i think it at least gets the job done relatively

you use:

> CREATE TEMP SEQUENCE rownum;
> SELECT nextval('rownum') AS row_number , t.a, t.b, t.c
> FROM (
> SELECT a, b, c
> FROM table
> WHERE table_id  = 973
> ORDER BY record_date
> ) t;

Doesn't this just return the 973th single record for the current 
sequence order in your table?

I believe:
 SELECT a, b, c FROM table
 offset 973 limit 1 

will accomplish the same result.


Stefan


-- 
email: [EMAIL PROTECTED]
tel  : +49 (0)6232-497631
http://www.yukonho.de

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] pg_clog (?) problem with VACUMM

2007-11-27 Thread Stefan Becker
Dear Gerardo and Pgsql-List,

>When executing a VACUUM, i have this msg:
>gse_new_version=# VACUUM ;
>ERROR:  could not access status of transaction 118
>DETAIL:  could not open file "pg_clog/": No existe el fichero o el

I had a similar problem.  I decided one day to "clean" out
The pg_clog/ directory of the database cluster.  These files'
"last modified time Stamps" on many files were quite 
old, so I deleted them.  This didn't have any consequences for
the data (dumps or indexes etc.) or the operation of 
the installation except, as I found out MUCH later found out
- I could no longer vacuum the Database.

I restored the missing files from a backup and everything
was okay again, after a vacuum of the database the
system cleaned out the older pg_log/ files on its own.

I hope you get things fixed!

My best regards,

Stefan Becker
Email: [EMAIL PROTECTED]



---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match