niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » PostgreSQL
problem creating users via pythons script
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Timothy Smith
*nix forums addict


Joined: 16 Apr 2005
Posts: 61

PostPosted: Wed Jul 19, 2006 1:16 pm    Post subject: Re: problem creating users via pythons script Reply with quote

Volkan YAZICI wrote:
Quote:
On Jul 19 10:40, Timothy Smith wrote:

Volkan YAZICI wrote:

On Jul 19 10:02, Timothy Smith wrote:


cur.execute("""CREATE USER %s WITH PASSWORD %s IN GROUP %s
""",(StaffUserName,NewPassword,StaffGroup))

produces this error

ERROR: syntax error at or near "'bob.smith'" at character 13


IIRC, per Python DB-API PEP, the DB adapter you use try to escape and
quote any parameter you specified. Please try to use python parameters,
that are "% (param1, param2, ...)", only for values; not for any other


Edit: «% (param1, param2, ...)» part must be replaced with
«"query_str", param1, param2, ...»


place in the query string.

To summarize, you can only use parameters for values, not keys.

...
ah ok so how do i do it :/


Just don't pass username as parameter to Cursor.execute(), for instance:

cur.execute("CREATE USER %s WITH PASSWORD %s IN GROUP %s"
% (StaffUserName, NewPassword, StaffGroup))


Regards.

P.S. Please don't forget to CC mailing list next time. Also, -interface
ml is more appropriate for these kind of questions.



of course, i should have seen that to begin with, cheers.


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Back to top
Volkan YAZICI
*nix forums beginner


Joined: 13 Jun 2005
Posts: 31

PostPosted: Wed Jul 19, 2006 12:50 pm    Post subject: Re: problem creating users via pythons script Reply with quote

On Jul 19 10:40, Timothy Smith wrote:
Quote:
Volkan YAZICI wrote:
On Jul 19 10:02, Timothy Smith wrote:

cur.execute("""CREATE USER %s WITH PASSWORD %s IN GROUP %s
""",(StaffUserName,NewPassword,StaffGroup))

produces this error

ERROR: syntax error at or near "'bob.smith'" at character 13


IIRC, per Python DB-API PEP, the DB adapter you use try to escape and
quote any parameter you specified. Please try to use python parameters,
that are "% (param1, param2, ...)", only for values; not for any other

Edit: «% (param1, param2, ...)» part must be replaced with
«"query_str", param1, param2, ...»

Quote:
place in the query string.

To summarize, you can only use parameters for values, not keys.

...
ah ok so how do i do it :/

Just don't pass username as parameter to Cursor.execute(), for instance:

cur.execute("CREATE USER %s WITH PASSWORD %s IN GROUP %s"
% (StaffUserName, NewPassword, StaffGroup))


Regards.

P.S. Please don't forget to CC mailing list next time. Also, -interface
ml is more appropriate for these kind of questions.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Back to top
Volkan YAZICI
*nix forums beginner


Joined: 13 Jun 2005
Posts: 31

PostPosted: Wed Jul 19, 2006 12:13 pm    Post subject: Re: problem creating users via pythons script Reply with quote

On Jul 19 10:02, Timothy Smith wrote:
Quote:
cur.execute("""CREATE USER %s WITH PASSWORD %s IN GROUP %s
""",(StaffUserName,NewPassword,StaffGroup))

produces this error

ERROR: syntax error at or near "'bob.smith'" at character 13

IIRC, per Python DB-API PEP, the DB adapter you use try to escape and
quote any parameter you specified. Please try to use python parameters,
that are "% (param1, param2, ...)", only for values; not for any other
place in the query string.

To summarize, you can only use parameters for values, not keys.


Regards.

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

http://www.postgresql.org/docs/faq
Back to top
Timothy Smith
*nix forums addict


Joined: 16 Apr 2005
Posts: 61

PostPosted: Wed Jul 19, 2006 12:02 pm    Post subject: problem creating users via pythons script Reply with quote

this is really newb of me but i can't manage to make a script to create
users.

cur.execute("""CREATE USER %s WITH PASSWORD %s IN GROUP %s
""",(StaffUserName,NewPassword,StaffGroup))

produces this error

ERROR: syntax error at or near "'bob.smith'" at character 13

is it because i need to double quote or something? i'm sure the answer
is stupid and i'm just too tired.


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

http://archives.postgresql.org
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 2:01 am | All times are GMT
navigation Forum index » Databases » PostgreSQL
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts bounce problem murkis Postfix 0 Sun Oct 08, 2006 3:45 pm

Credit Cards | Online Advertising | Web Advertising | Credit Report | Loan
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2643s ][ Queries: 20 (0.1774s) ][ GZIP on - Debug on ]