Re: [SQL] COPY tablename FROM and null values

2006-03-22 Thread Luckys

On 3/22/06, Achilleus Mantzios <[EMAIL PROTECTED]> wrote:
O ivan marchesini έγραψε στις Mar 22, 2006 :> Dear users,> I'm working on a Postgres 7.4
 server>> I have a .txt file, containing some tabular data, where data are> delimited by TABs.> there are 3 columns:>> column1 int4, column2 float8, column3 float8>> the problem is that column3 contains also null values (
i.e. sometimes is> empty)>> so when I try to use COPY tablename FROM 'filename.txt' I obtain an> error>> I have tried also using " WITH NULL AS ' ' " but without good results...
>> can someone explain me how to solve this problem???batch edit your file (with sed,awk,perl,C,java,...) and build yourexplicit INSERT statements in some version of your file.
 
or Replace the empty spaces in the file with some other value (0.0)
>> thank you very much>> Ivan>--
-Achilleus---(end of broadcast)---TIP 5: don't forget to increase your free space map settings


Re: [SQL] how to solve this problem

2006-04-15 Thread Luckys
the same can be even achieved, instead of having 20 different columns,
in a single column varchar(20) vincs('11010111011101110010').
 
Luckys.
 
On 4/14/06, ivan marchesini <[EMAIL PROTECTED]> wrote:
Thank you very much!!!your suggestion seems really usefull!! I will try it very soon!!!ivan
Il giorno gio, 13/04/2006 alle 11.34 -0700, Steve Crawford ha scritto:> > I have a table where there are 20 columns named> > vinc1, vinc2, vinc3, vinc4, etc> >> > the values contained into each column are simply 1 or 0  (each column is
> > dichotomic)> > 1 means presence> > 0 means absence> >> > I would obtain a column (new_column) containg the name of the columns,> > comma separated, where the value is = 1
> >> > for example:> >> > vinc1   vinc2   vinc3   vinc4   new_column> > 1   0   1   0   vinc1,vinc3> > 0   0   0   1   vinc4> > 0   1   1   1   vinc2,vinc3,vinc4
> >> > can someone help me to find the best way to obtain this result???> > thank you very much>> Here's a brute-force method. Maybe someone else has a more elegant way.> More info on the nature of your data and what you are trying to obtain
> from it would help in finding such elegance.>> select>substr(>case when vinc1 = 1 then ',vinc1' else '' ||>case when vinc2 = 1 then ',vinc2' else '' ||>...
>case when vinc20 = 1 then ',vinc20' else ''>,2) as new_column ...>> As to the binary representation mentioned elsewhere, the idea is that> you can view vinc1-vinc20 as bits in a binary number equal to vinc1 +
> 2*vinc2 + 4*vinc3 + 8*vinc4...2^19*vinc20. Whether or not this is useful> depends on what you are trying to do.>> Cheers,> Steve>--Ivan MarchesiniDepartment of Civil and Environmental Engineering
University of PerugiaVia G. Duranti 93/a06125Perugia (Italy)e-mail: [EMAIL PROTECTED]   [EMAIL PROTECTED]
tel: +39(0)755853760fax: +39(0)755853756jabber: [EMAIL PROTECTED]---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] Thoughts on a Isolation/Security problem.

2006-04-18 Thread Luckys
how about having a company table, and company_code column across all relevant table, although you'll have to modify your application also, which would be an additional clause in the WHERE condition e.g where company_code = 'which company user has logged in'.

The user has to specify while logging under which company he's going to work on.
This way would be ideal even for your Global financial consolidations if the mgmt requires in the due course.
other option would be of two tables, Company , Organization, where you can have company1, org1, org2 etc., this can also be applied in the same pattern as stated above.
 
 
 
On 4/18/06, Achilleus Mantzios <[EMAIL PROTECTED]> wrote:
Hi, i have run into the following problem.Let me describe the context first.When i joined the company(ies) i work for (a group of Shipping Mgmt/
Owenship/Agent companies), the only thing i was told when i starteddesigning the DB/Apps was just one company.So i built everything into one single DB, and i wrote the appshaving one company in mind.
Our architecture is based on jboss3/postgresql (curenctly 7.4.12).There is one .ear file, which authenticates users against a lotusnotes ldap server.At the time, the corporate organisational model was a little bit wierd:
- Many Indepentent ownership companies- Many Independent Mgmg companies(but all busines was with one company in mind).Each App user is a member of one or more ldap groups, each groupmapping to a mgmt company.
So i ended up with- one DB with 173 tables- one DB user (postgres)- one .EAR application with 148,827 lines of code.Now the requirements start to change.The boss now bought some other types of vessels too.
So virtually there must be N separate distinct apps, where N is the numberof Mgmt companies (roughly one for every type of vessel), where each appsees and manages only its data.Moreover there are some apps that should see global data for some specific
tables. (like the crew data, people in the crew move from one type ofvessel to the other so they are not tied to a Mgmt company).These new requirements are of legal nature, as well as ofoperational. (People managing a type of vessels dont want to mess with
another type,and auditors must see each company completely separated from the rest).Doing it with extra code would be a real pain, since i would have torefineall security/authentication based on the groups (
[EMAIL PROTECTED])that a person belongs to. Also this way no inherent isolation/securitywould hold.Now i am thinking of restructuring the whole architecture as:- Create one EAR app for every mgmt company
- Create one DB USER for every mgmg company- Create one SCHEMA (same as the USER) for every mgmt company(mgmtcompany1,mgmtcompany2,etc...)- Find a way (links/xdoclet/eclipse?) to have *one* common code base for
the N EAR apps.- Tweak with jboss*.xml to map java:comp/env/jdbc/DB tojava:/pgsql, where pgsql authenticateswith the corresponding DB USER.- Classify the tables into
- The ones that apply to ALL mgmt companies (and leave them in thepublic schema)- The ones that apply *only* to a mgmt company and so create one undereach SCHEMA- Load the data in *each* SCHEMA, except the tables that apply to all.
- Define a process of "mgmt company"fying the tables in each schema (e.g.delete from mgmtcompany1.vessels the vessels that dont belong tomgmtcompany1, and so forth)- Resolve FK constraint issues
- The default search_path in psql (whats the the equivalent in jdbc?) is$user,public, so effectively *each* EAR will hit automagically the correctmgmtcompanyN.* tables, or the public.* tables if these tables apply to all
mgmt companies.With this way, the hard work is DB oriented, and not APP oriented.However i wonder whether someone else has gone thru a similar process,or if someone finds some assumption conceptually flawed.
Thanx for reading, and for any possible thoughts.---Achilleus---(end of broadcast)---TIP 4: Have you searched our list archives?
  http://archives.postgresql.org-- regards, Luckys...