looking for an example of how to create users out of a table in the database.

Posted on 2007-10-01
Last Modified: 2013-11-26
i need to create users in postgres databases.
i integrate datas from excel files with c# in a new created database,
i need now to get users out of a table and give them rights depending what was entry in the table.
three kind of users....
what 's the best way to do this? do I need to generate a file and then pass to postgres?
with procedures?

i need an advice on how to do it and a description on steps to do.
some code is wellcome or link on code solution.

Question by:toshi_
    LVL 22

    Accepted Solution

    It's usually better to create ROLES that are given the associated privileges rather than assign a multitude of access rights.

    To add data from a CSV file you can use the COPY command

    COPY tablename [ ( column [, ...] ) ]
        FROM { 'filename' | STDIN }
        [ [ WITH ]
              [ BINARY ]
              [ OIDS ]
              [ DELIMITER [ AS ] 'delimiter' ]
              [ NULL [ AS ] 'null string' ]
              [ CSV [ HEADER ]
                    [ QUOTE [ AS ] 'quote' ]
                    [ ESCAPE [ AS ] 'escape' ]
                    [ FORCE NOT NULL column [, ...] ]

    You just need to wrap some plpgsql stored function around that and the CREATE USER, ALTER USER, CREATE ROLE, ALTER ROLE commands.

    More work than I'm prepared to do for free!

    Author Comment

    ok, lets say that i'll export the data table users to a cvs file
    in order to parse it with postgres functions.

    what i dont understand is where to start with my prob.
    where do i write your commands - COPY tablename[] ....- to start with?  i'll arrange them once i know where to introduce them.
    and how do i launch it then ?

    i dont need you to do my job earhman, as you're the biggest expert here i don't want to loose your time
    ,you can give so many answers to people.

    if you know a good tutorial on how to do it,  or an article i'll suit me.
    i'll be able to ask more precisely then.

    thanks in advance, you over guru ;o)

    LVL 10

    Assisted Solution



    As far as I can understand your question you need to create users
    in PostgreSQL from excel files using C#. Please correct me if I'm wrong.
    First, you need to have the PostgreSQL server running and you need
    to connect to it from C# in order to send it commands.

    I would start here with PosgreSQL if you don't have it installed already:
    I. Tutorial 1. Getting Started

    Another way would be to generate text files with SQL commands from C# and then call (execute)
    psql file.sql
    to push them into the PostgreSQL database.


    Author Comment

    hi adrpo,
    the first part is done,
    i have install xp with pgadminIII which install also the 8.2 postgres server.
    i could create user, databases, i create a c# class to connect to postgres,
    everything is working.

    i' have an xls file with a list of people that will connect read only to database. some of them will have permissions to make changes, a columns in excel file has the type of the user.

    as far as i understand now, i have to generate a csv file while parsing my excel file with c#. the csv file will have loginuser and right type.
    then i parse that file from postgresql with the call(execute) in order to
    create the users and roles for the database.

    what would be good practice for doing this,  how to use roles and grouproles?
    i need :  "communityUser"  "logisticUser" and "communityAdmin".
    should i create three grouproles with the rights, and then create roles and add them to grouproles?



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    prevent lose focus 6 48
    Session variables expiration ASP.NET C# 3 37
    C# - SOLID Question 6 35
    vb linq Count Distinct? 1 29
    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now