Re: [sqlite] Newbie problem using special column name
* Martin Engelschalk : > try enclosing your column name with double quotes " > > create table test("column-1" varchar(255)) > > > However, i strongly advise not to use this character, because it is the > minus-operator in sql. You will have to make sure that you enclose the > column name every time you (or somone other) uses ist. Thanks. Unfortunately I don't have a choice. An application I don't have control over expects such strange table names. p...@rick > > Martin > > Patrick Ben Koetter wrote: > > Can I add a column name containing a dash "-" and if yes, how would I do > > that? > > > > I am asking because I fail to add a column name that contains a dash "-" > > and I > > don't know if I cause the problem (easy solution) or if its something else > > causing this to fail. > > > > Here's what I try: > > > > sqlite> create table test(column-1 varchar(255)); > > SQL error: near "-": syntax error > > > > So far I have had a look at the SQLite documentation, but couldn't find > > anything that would tell me about 'reserved' characters or how I would > > escape > > a dash. > > > > Thanks, > > > > p...@rick > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Newbie problem using special column name
2010/1/25 Adam DeVita : > Create the table using single quotes around the strange name. Double-quotes for identifiers: http://www.sqlite.org/lang_keywords.html > > > sqlite> create table x (boomer int, 'squid-nick' text); > sqlite> insert into x values (1,'asdlh'); > sqlite> select * from x; > 1|asdlh > sqlite> select squid-nick from x; > SQL error: no such column: nick > sqlite> select 'squid-nick' from x; > squid-nick > /*oops, I selected the string not a column name. */ > sqlite> select x.'squid-nick' from x; /*reference the table name before the > column*/ > asdlh > > > As an aside: If you realize that the database name for a column doesn't have > to be the same as the user friendly name in your user interface, you don't > have to use keywords or special characters as column names. Good advice > > Regards, Simon ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Newbie problem using special column name
Hi, try enclosing your column name with double quotes " create table test("column-1" varchar(255)) However, i strongly advise not to use this character, because it is the minus-operator in sql. You will have to make sure that you enclose the column name every time you (or somone other) uses ist. Martin Patrick Ben Koetter wrote: > Can I add a column name containing a dash "-" and if yes, how would I do that? > > I am asking because I fail to add a column name that contains a dash "-" and I > don't know if I cause the problem (easy solution) or if its something else > causing this to fail. > > Here's what I try: > > sqlite> create table test(column-1 varchar(255)); > SQL error: near "-": syntax error > > So far I have had a look at the SQLite documentation, but couldn't find > anything that would tell me about 'reserved' characters or how I would escape > a dash. > > Thanks, > > p...@rick > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Newbie problem using special column name
Create the table using single quotes around the strange name. sqlite> create table x (boomer int, 'squid-nick' text); sqlite> insert into x values (1,'asdlh'); sqlite> select * from x; 1|asdlh sqlite> select squid-nick from x; SQL error: no such column: nick sqlite> select 'squid-nick' from x; squid-nick /*oops, I selected the string not a column name. */ sqlite> select x.'squid-nick' from x; /*reference the table name before the column*/ asdlh As an aside: If you realize that the database name for a column doesn't have to be the same as the user friendly name in your user interface, you don't have to use keywords or special characters as column names. On Mon, Jan 25, 2010 at 9:18 AM, Patrick Ben Koetter wrote: > Can I add a column name containing a dash "-" and if yes, how would I do > that? > > I am asking because I fail to add a column name that contains a dash "-" > and I > don't know if I cause the problem (easy solution) or if its something else > causing this to fail. > > Here's what I try: > > sqlite> create table test(column-1 varchar(255)); > SQL error: near "-": syntax error > > So far I have had a look at the SQLite documentation, but couldn't find > anything that would tell me about 'reserved' characters or how I would > escape > a dash. > > Thanks, > > p...@rick > > -- > state of mind > Digitale Kommunikation > > http://www.state-of-mind.de > > Franziskanerstraße 15 Telefon +49 89 3090 4664 > 81669 München Telefax +49 89 3090 4666 > > Amtsgericht MünchenPartnerschaftsregister PR 563 > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- VerifEye Technologies Inc. 905-948-0015x245 7100 Warden Ave, Unit 3 Markham ON, L3R 8B5 Canada ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Newbie problem using special column name
Welcome to the SQLite list. >Can I add a column name containing a dash "-" and if yes, how would I >do that? Make this create table test([column-1] varchar(255)); or create table test("column-1" varchar(255)); Both work ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Newbie problem using special column name
2010/1/25 Patrick Ben Koetter : > Can I add a column name containing a dash "-" and if yes, how would I do that? > > I am asking because I fail to add a column name that contains a dash "-" and I > don't know if I cause the problem (easy solution) or if its something else > causing this to fail. > > Here's what I try: > > sqlite> create table test(column-1 varchar(255)); > SQL error: near "-": syntax error C:\>sqlite3_6_20 SQLite version 3.6.20 Enter ".help" for instructions sqlite> sqlite> create table tst( "column-1" text ); sqlite> > > So far I have had a look at the SQLite documentation, but couldn't find > anything that would tell me about 'reserved' characters or how I would escape > a dash. > > Thanks, > > p...@rick > > -- > state of mind > Digitale Kommunikation > Regards, Simon ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Newbie problem using special column name
Can I add a column name containing a dash "-" and if yes, how would I do that? I am asking because I fail to add a column name that contains a dash "-" and I don't know if I cause the problem (easy solution) or if its something else causing this to fail. Here's what I try: sqlite> create table test(column-1 varchar(255)); SQL error: near "-": syntax error So far I have had a look at the SQLite documentation, but couldn't find anything that would tell me about 'reserved' characters or how I would escape a dash. Thanks, p...@rick -- state of mind Digitale Kommunikation http://www.state-of-mind.de Franziskanerstraße 15 Telefon +49 89 3090 4664 81669 München Telefax +49 89 3090 4666 Amtsgericht MünchenPartnerschaftsregister PR 563 ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users