SQLite issue with Table Names using numbers? - sql

I'm developing an app which requires that the user selects a year formatted like this 1992-1993 from a spinner. The tablename is also named 1992-1993 and the idea is that using SQL the values from this table are pulled through with a statement like this select * from 1992-1993. When I run the emulator however, it throws an error.
If I then relabel the Spinner item to NinetyTwo and rename the table to NinetyTwo and run the emulator it runs as expected and the data is pulled through from the table.
Does SQLite have an issue with numbers in table names?

Yes and No. It has an issue with numbers at the beginning of a table name. 1992-1993 is an expression returning -1. Try to rename the table to Year1992.
Here a similar issue on SO.

sorry for late post
There may be a deeper issue here - is the structure you are using (table name per item in spinner) the best one for the job?
You may find that you want a number of tables e.g.
spinner_value (id, value)
form_data(id, spinner_value_id, etc ....)

Related

Why would Access spontaneously start displaying a non-existant table in a query?

I updated a simple Access select query, adding four fields from the single table the query uses. When I then attempted to edit data in the form that references that query, Access did not allow any edits. After poking around at other possible edit rights problems I went back to the query design, and saw this:
The table CC_Tracker_1 does not exist in the database, nor is there a query by that name, as you can see in the object list:
In the design view, CC_Tracker_1 displays as an exact copy of CC_Tracker. Additionally, the four fields I added had CC_Tracker_1 listed as their table of origin.
Deleting CC_Tracker_1 from the query and re-adding the fields from CC_Tracker fixed the problem, but I'm very curious as to how this could happen.
Edit to add: This is the SQL Access generated. As you can see the alias it created isn't used anywhere in the code except in the variable list. Why it would do this is still the question:
SELECT CC_Tracker.LAST_NAME, CC_Tracker.FIRST_NAME, CC_Tracker.MRN, CC_Tracker.RIN,
CC_Tracker.SUBSCRIBER_ID, CC_Tracker.ASSIGNED, CC_Tracker.Letter, CC_Tracker.[1stCall],
CC_Tracker.CHRA, CC_Tracker.[ICP/Review], CC_Tracker.F2F, CC_Tracker.ICTCont,
CC_Tracker.ICTSheet, CC_Tracker.ICP2MD, CC_Tracker.SigPg, CC_Tracker.HTR_1st_cont,
CC_Tracker.HTR_2nd_cont, CC_Tracker.HTR_3rd_cont, CC_Tracker.HTR_Letter,
CC_Tracker.CLOSE, CC_Tracker.Comments, CC_Tracker.CHRA_Next, CC_Tracker.ICP_Next,
CC_Tracker.F2F_Next, CC_Tracker.ICT_Next, CC_Tracker_1.Final_Follow, CC_Tracker_1.BH_SA,
CC_Tracker_1.Readmitter, CC_Tracker_1.CCM, CC_Tracker.ASSIGNED_CARE_COORDINATOR, CC_Tracker.Final_Follow
FROM CC_Tracker, CC_Tracker AS CC_Tracker_1
WHERE (((CC_Tracker.ASSIGNED_CARE_COORDINATOR)=[Forms]![frmCoord_Selector]![cmbCoords]))
OR (((([CC_Tracker].[ASSIGNED_CARE_COORDINATOR])
Like [Forms]![frmCoord_Selector]![cmbCoords]) Is Null));
If you look at the SQL that is generated for the query, you will see that it has created an alias called CC_Tracker_1 for the CC_Tracker table.
Your query may need to be rewritten to exclude this alias, and any incorrect joins.
If you post the actual query generated, we will be able to help fix it.

Run command SQL query on joomla database to jos_content table to change catid number for specific dates

my question is quite simple and easy,, and it has to do with the syntax on a SQL query,
I want to run a SQL query BUT I dont know what command to use on the PHPMyAdmin cause i m not very familiar with the sql syntax.
Problem:
Imagine a table named jos_content that among others columns has a column named catid and a column named created.
So on these two columns i want to play.
So i want to change all rows with catid 162 change to 255 AND that are created from 01/09/2014 till today...
Bear in mind the created column has data for example like 2015-04-20 09:09:28 ,, I dont know if you can understand the question
Target
I need the full sql command and syndax to achieve automatically and change all rows catid number from this date till today, instead of changing one by one each row.
please some help guys,
Thank you in advance
Disclaimer: be very careful on your data. Perform a backup first. You're the only one responsible on what you're doing. Here's the query:
UPDATE #__content
SET catid = 255
WHERE catid = 162
AND created > '2014-09-01'
Did I tell you to be very careful?

Repeating Data In Access Combo Box

I am having an issue regarding repeating data in my access form, I want to be able to select a tutors name and for it to display all of the students linked to that tutor this does work however in the list view because one tutor sees many students the data is repeated (see images) Is there a SQL statement I should be using to stop this? (I am new to Access and SQLServer so I apologies if this is an obvious) Please see the images below which will make my issue clear.
I solved my problem by adding SELECT 'DISTINCT' to my SQL Statement so from
SELECT "Tutors"."PAT" FROM "Tutors";
To:
SELECT DISTINCT "Tutors"."PAT" FROM "Tutors";

Copy one database table's contents into another on same database

I'm a bit of a newbie with the workings of phpmyadmin. I have a database and now there are 2 parts within it - the original tables jos_ and the same again but with a different prefix, say let's ****_ that will be the finished database.
This has come about because I am upgrading my Joomla 1.5 site to 2.5. I used a migration tool for the bulk of the new database but one particular piece of information did not transfer because the new database has a different structure.
I want to copy the entire contents of jos_content, attribs, keyref= across to ****_content, metadata, "xreference"."VALUE" if that makes sense. This will save manually typing in the information contained within 1000s of articles.
jos_content, attribs currently contains
show_title=
link_titles=
show_intro=
show_section=
link_section=
show_category=
link_category=
show_vote=
show_author=
show_create_date=
show_modify_date=
show_pdf_icon=
show_print_icon=
show_email_icon=
language=
keyref=41.126815,0.732623
readmore=
****_content, metadata currently contains
{"robots":"all","author":""}
but I want it to end up like this
{"robots":"","author":"","rights":"","xreference":"41.126815,0.732623","marker":""}
Could anyone tell me the SQL string that I would need to run to achieve this please?
If it makes any difference I have manually changed about 300 of these articles already and thought there must be a better way.
Edit: Being nervous of trying this I would like to try and find the exact syntax (if that's the right word) for the SQL Query to run.
The value I want to extract from the source table is just, and only, the numbers next to keyref= and I want them to turn up in the destination table prefixed by "xreference". - so it shows "xreference"."VALUE" with VALUE being the required numbers. There is also an entry - ,"marker":"" that is in the destination table so I guess the Query needs to produce that as well?
Sorry for labouring this but if I get it wrong, maybe by guessing what to put, I don't really have the knowledge to put it all right again....
Thanks.
Please Try it
insert into tableone(column1,column2) select column1,column2 from Tablesecond
if You have not Table another Daabase Then This query
select * into anyname_Table from tablesource

Can I insert in a programmatically defined PostgreSQL table using SQL language?

Context: I'm trying to INSERT data in a partitioned table. My table is partitioned by months, because I have lots of data (and a volume expected to increase) and the most recent data is more often queried. Any comment on the partition choice is welcome (but an answer to my question would be more than welcome).
The documentation has a partition example in which, when inserting a line, a trigger is called that checks the new data date and insert it accordingly in the right "child" table. It uses a sequence of IF and ELSIF statements, one for each month. The guy (or gal) maintaining this has to create a new table and update the trigger function every month.
I don't really like this solution. I want to code something that will work perfectly and that I won't need to update every now and then and that will outlive me and my grand-grand-children.
So I was wondering if I could make a trigger that would look like this:
INSERT INTO get_the_appropriate_table_name(NEW.date) VALUES (NEW.*);
Unfortunately all my attempts have failed. I tried using "regclass" stuffs but with no success.
In short, I want to make up a string and use it as a table name. Is that possible?
I was just about to write a trigger function using EXECUTE to insert into a table according to the date_parts of now(), or create it first if it should not exist .. when I found that somebody had already done that for us - right under the chapter of the docs you are referring to yourself:
http://www.postgresql.org/docs/9.0/interactive/ddl-partitioning.html
Scroll all the way down to user "User Comments". Laban Mwangi posted an example.
Update:
The /interactive branch of the Postgres manual has since been removed, links are redirected. So the comment I was referring to is gone. Look to these later, closely related answers for detailed instructions:
INSERT with dynamic table name in trigger function
Table name as a PostgreSQL function parameter
For partitioning, there are better solutions by now, like range partitioning in Postgres 10 or later. Example:
Better database for “keep always the 5 latest entries per ID and delete older”?