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

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.

Erwin PombettAsked:
Who is Participating?
earth man2Commented:
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!
Erwin PombettAuthor Commented:
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)



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.

Erwin PombettAuthor Commented:
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?


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.